Skip to content

Commit 2b72891

Browse files
committed
Rework GenChangelogs to use GitHub API
Fixes squashed/rebased PRs not showing up
1 parent 6322eb1 commit 2b72891

File tree

1 file changed

+22
-37
lines changed

1 file changed

+22
-37
lines changed

GenChangelogs.hs

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,36 @@
11
#!/usr/bin/env cabal
22
{- cabal:
3-
build-depends: base, process, html-conduit, http-conduit, xml-conduit, text, containers
3+
build-depends: base, process, text, github, time
44
-}
55

6-
{-# LANGUAGE OverloadedStrings #-}
6+
{-# LANGUAGE OverloadedStrings, RecordWildCards #-}
77

88
import Control.Monad
9-
import Data.Char
109
import Data.List
11-
import qualified Data.Map.Lazy as M
12-
import Network.HTTP.Simple
13-
import System.Process
10+
import Data.Maybe
1411
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
1916

2017
main = do
2118
callCommand "git fetch --tags"
2219
tags <- filter (isPrefixOf "0.") . lines <$>
2320
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
4921

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

Comments
 (0)