|
| 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 | + let lastTag = last tags |
| 25 | + messages <- lines <$> |
| 26 | + readProcess "git" ["log", last tags <> "..HEAD", "--merges", "--reverse", "--pretty=format:\"%s\""] "" |
| 27 | + |
| 28 | + let prNums = map (filter isDigit) $ map head $ filter (not . null) $ map (filter (isPrefixOf "#") . words) messages |
| 29 | + prUrls = map ("https://github.com/haskell/haskell-ide-engine/pull/" <>) prNums |
| 30 | + |
| 31 | + (flip mapM_) prUrls $ \url -> do |
| 32 | + body <- getResponseBody <$> httpLBS (parseRequest_ url) |
| 33 | + let cursor = fromDocument (parseLBS body) |
| 34 | + titles = (descendant >=> attributeIs "class" "js-issue-title" >=> child >=> content) cursor |
| 35 | + title = T.unpack $ T.strip $ head titles |
| 36 | + checkAuthor :: Element -> Bool |
| 37 | + checkAuthor e = maybe False (T.isInfixOf "author") (M.lookup "class" (elementAttributes e)) |
| 38 | + authors = (descendant >=> checkElement checkAuthor >=> child >=> content) cursor |
| 39 | + author = T.unpack $ T.strip $ authors !! 2 -- second author is the pr author |
| 40 | + putStrLn $ "- [" <> title <> "](" <> url <> ") (@" <> author <> ")" |
0 commit comments