|
1 | 1 | #!/usr/bin/env cabal
|
2 | 2 | {- cabal:
|
3 |
| -build-depends: base, process, html-conduit, http-conduit, xml-conduit, text, containers |
| 3 | +build-depends: base, process, text, github, time |
4 | 4 | -}
|
5 | 5 |
|
6 |
| -{-# LANGUAGE OverloadedStrings #-} |
| 6 | +{-# LANGUAGE OverloadedStrings, RecordWildCards #-} |
7 | 7 |
|
8 | 8 | import Control.Monad
|
9 |
| -import Data.Char |
10 | 9 | import Data.List
|
11 |
| -import qualified Data.Map.Lazy as M |
12 |
| -import Network.HTTP.Simple |
13 |
| -import System.Process |
| 10 | +import Data.Maybe |
14 | 11 | import qualified Data.Text as T
|
15 |
| -import qualified Data.Text.IO as T |
16 |
| -import Text.HTML.DOM |
17 |
| -import Text.XML.Cursor |
18 |
| -import Text.XML (Element(..)) |
| 12 | +import Data.Time.Format.ISO8601 |
| 13 | +import Data.Time.LocalTime |
| 14 | +import System.Process |
| 15 | +import GitHub |
19 | 16 |
|
20 | 17 | main = do
|
21 | 18 | callCommand "git fetch --tags"
|
22 | 19 | tags <- filter (isPrefixOf "0.") . lines <$>
|
23 | 20 | readProcess "git" ["tag", "--list", "--sort=v:refname"] ""
|
24 |
| - messages <- lines <$> readProcess "git" [ "log" |
25 |
| - , last tags <> "..HEAD" |
26 |
| - , "--merges" |
27 |
| - , "--reverse" |
28 |
| - , "--pretty=format:\"%s\"" |
29 |
| - ] "" |
30 |
| - |
31 |
| - let -- try to get "1334" out of "merge PR #1334" |
32 |
| - prNums = map (filter isDigit) $ |
33 |
| - map head $ |
34 |
| - filter (not . null) $ |
35 |
| - map (filter (isPrefixOf "#") . words) messages |
36 |
| - |
37 |
| - (flip mapM_) prNums $ \prNum -> do |
38 |
| - let url = "https://github.com/haskell/haskell-language-server/pull/" <> prNum |
39 |
| - body <- getResponseBody <$> httpLBS (parseRequest_ url) |
40 |
| - let cursor = fromDocument (parseLBS body) |
41 |
| - |
42 |
| - titles = (descendant >=> attributeIs "class" "js-issue-title" >=> child >=> content) cursor |
43 |
| - title = T.unpack $ T.strip $ head titles |
44 |
| - |
45 |
| - checkAuthor :: Element -> Bool |
46 |
| - checkAuthor e = maybe False (T.isInfixOf "author") (M.lookup "class" (elementAttributes e)) |
47 |
| - authors = (descendant >=> checkElement checkAuthor >=> child >=> content) cursor |
48 |
| - author = T.unpack $ T.strip $ authors !! 4 -- second author is the pr author |
49 | 21 |
|
50 |
| - -- generate markdown |
51 |
| - putStrLn $ "- " <> title <> "\n([#" <> prNum <> "](" <> url <> ") by @" <> author <> ")" |
| 22 | + lastDateStr <- last . lines <$> readProcess "git" ["show", "-s", "--format=%cI", "-1", last tags] "" |
| 23 | + lastDate <- zonedTimeToUTC <$> iso8601ParseM lastDateStr |
| 24 | + |
| 25 | + prs <- github () $ pullRequestsForR "haskell" "haskell-language-server" stateClosed FetchAll |
| 26 | + let prsAfterLastTag = either (error "asdf") |
| 27 | + (foldMap (\pr -> if inRange pr then [pr] else [])) |
| 28 | + prs |
| 29 | + inRange pr |
| 30 | + | Just mergedDate <- simplePullRequestMergedAt pr = mergedDate > lastDate |
| 31 | + | otherwise = False |
| 32 | + |
| 33 | + forM_ prsAfterLastTag $ \SimplePullRequest{..} -> |
| 34 | + putStrLn $ T.unpack $ "- " <> simplePullRequestTitle <> |
| 35 | + "\n([#" <> T.pack (show $ unIssueNumber simplePullRequestNumber) <> "](" <> getUrl simplePullRequestUrl <> ")" <> |
| 36 | + " by @" <> (untagName (simpleUserLogin simplePullRequestUser)) |
0 commit comments