Skip to content

Commit cd1b544

Browse files
committed
Add script to generate changelog
1 parent 5777e8d commit cd1b544

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

GenChangelogs.hs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env cabal
2+
{- cabal:
3+
build-depends: base, process, html-conduit, http-conduit, xml-conduit, text, containers
4+
-}
5+
6+
{-# LANGUAGE OverloadedStrings #-}
7+
8+
import Control.Monad
9+
import Data.Char
10+
import Data.List
11+
import qualified Data.Map.Lazy as M
12+
import Network.HTTP.Simple
13+
import System.Process
14+
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(..))
19+
20+
main = do
21+
callCommand "git fetch --tags"
22+
tags <- filter (isPrefixOf "0.") . lines <$>
23+
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+
50+
-- generate markdown
51+
putStrLn $ "- " <> title <> "\n([#" <> prNum <> "](" <> url <> ") by @" <> author <> ")"

0 commit comments

Comments
 (0)