haskell-language-server/GenChangelogs.hs

44 lines
1.6 KiB
Haskell
Raw Normal View History

2020-09-02 22:50:14 +03:00
#!/usr/bin/env cabal
{- cabal:
build-depends: base, bytestring, process, text, github, time >= 1.9
2020-09-02 22:50:14 +03:00
-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
2020-09-02 22:50:14 +03:00
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe
import qualified Data.Text as T
import Data.Time.Format.ISO8601
import Data.Time.LocalTime
import GitHub
import System.Environment
import System.Process
2020-09-02 22:50:14 +03:00
main = do
callCommand "git fetch --tags"
tags <- filter (isPrefixOf "1.") . lines <$>
2020-09-02 22:50:14 +03:00
readProcess "git" ["tag", "--list", "--sort=v:refname"] ""
lastDateStr <- last . lines <$> readProcess "git" ["show", "-s", "--format=%cI", "-1", last tags] ""
lastDate <- zonedTimeToUTC <$> iso8601ParseM lastDateStr
args <- getArgs
let githubReq = case args of
[] -> github'
token:_ -> github (OAuth $ BS.pack token)
prs <- githubReq $ pullRequestsForR "haskell" "haskell-language-server" stateClosed FetchAll
2020-10-03 18:21:14 +03:00
let prsAfterLastTag = either (error . show)
(foldMap (\pr -> [pr | inRange pr]))
prs
inRange pr
| Just mergedDate <- simplePullRequestMergedAt pr = mergedDate > lastDate
| otherwise = False
forM_ prsAfterLastTag $ \SimplePullRequest{..} ->
putStrLn $ T.unpack $ "- " <> simplePullRequestTitle <>
"\n([#" <> T.pack (show $ unIssueNumber simplePullRequestNumber) <> "](" <> getUrl simplePullRequestHtmlUrl <> "))" <>
2021-01-18 17:51:44 +03:00
" by @" <> untagName (simpleUserLogin simplePullRequestUser)