2019-10-25 05:32:30 +03:00
|
|
|
#!/usr/bin/env cabal
|
|
|
|
{- cabal:
|
2019-12-03 01:08:20 +03:00
|
|
|
build-depends: base, process, html-conduit, http-conduit, xml-conduit, text, containers
|
2019-10-25 05:32:30 +03:00
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
|
|
|
import Control.Monad
|
|
|
|
import Data.Char
|
|
|
|
import Data.List
|
|
|
|
import qualified Data.Map.Lazy as M
|
|
|
|
import Network.HTTP.Simple
|
|
|
|
import System.Process
|
|
|
|
import qualified Data.Text as T
|
|
|
|
import qualified Data.Text.IO as T
|
|
|
|
import Text.HTML.DOM
|
|
|
|
import Text.XML.Cursor
|
|
|
|
import Text.XML (Element(..))
|
|
|
|
|
|
|
|
main = do
|
|
|
|
callCommand "git fetch --tags"
|
|
|
|
tags <- filter (isPrefixOf "0.") . lines <$>
|
|
|
|
readProcess "git" ["tag", "--list", "--sort=v:refname"] ""
|
2019-12-03 01:08:20 +03:00
|
|
|
messages <- lines <$> readProcess "git" [ "log"
|
2019-10-25 18:05:31 +03:00
|
|
|
, last tags <> "..HEAD"
|
|
|
|
, "--merges"
|
2019-12-03 01:08:20 +03:00
|
|
|
, "--reverse"
|
2019-10-25 18:05:31 +03:00
|
|
|
, "--pretty=format:\"%s\""
|
|
|
|
] ""
|
2019-10-25 05:32:30 +03:00
|
|
|
|
2019-10-25 18:05:31 +03:00
|
|
|
let -- try to get "1334" out of "merge PR #1334"
|
|
|
|
prNums = map (filter isDigit) $
|
|
|
|
map head $
|
|
|
|
filter (not . null) $
|
|
|
|
map (filter (isPrefixOf "#") . words) messages
|
2019-10-25 05:32:30 +03:00
|
|
|
prUrls = map ("https://github.com/haskell/haskell-ide-engine/pull/" <>) prNums
|
|
|
|
|
|
|
|
(flip mapM_) prUrls $ \url -> do
|
|
|
|
body <- getResponseBody <$> httpLBS (parseRequest_ url)
|
|
|
|
let cursor = fromDocument (parseLBS body)
|
2019-10-25 18:05:31 +03:00
|
|
|
|
2019-10-25 05:32:30 +03:00
|
|
|
titles = (descendant >=> attributeIs "class" "js-issue-title" >=> child >=> content) cursor
|
|
|
|
title = T.unpack $ T.strip $ head titles
|
2019-10-25 18:05:31 +03:00
|
|
|
|
2019-10-25 05:32:30 +03:00
|
|
|
checkAuthor :: Element -> Bool
|
|
|
|
checkAuthor e = maybe False (T.isInfixOf "author") (M.lookup "class" (elementAttributes e))
|
|
|
|
authors = (descendant >=> checkElement checkAuthor >=> child >=> content) cursor
|
|
|
|
author = T.unpack $ T.strip $ authors !! 2 -- second author is the pr author
|
2019-10-25 18:05:31 +03:00
|
|
|
|
|
|
|
-- generate markdown
|
2019-10-25 05:32:30 +03:00
|
|
|
putStrLn $ "- [" <> title <> "](" <> url <> ") (@" <> author <> ")"
|