|
| 1 | +#!/usr/bin/env cabal |
| 2 | +{- cabal: |
| 3 | +build-depends: base, process, html-conduit, http-conduit, xml-conduit, text |
| 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 | + , "--revers", |
| 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 | + prUrls = map ("https://github.com/haskell/haskell-ide-engine/pull/" <>) prNums |
| 37 | + |
| 38 | + (flip mapM_) prUrls $ \url -> do |
| 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 !! 2 -- second author is the pr author |
| 49 | + |
| 50 | + -- generate markdown |
| 51 | + putStrLn $ "- [" <> title <> "](" <> url <> ") (@" <> author <> ")" |
0 commit comments