module History ( Issues (..), IssueEvents (..), getIssues, getIssueEvents, getIssuesOfFile, ) where import Comment qualified as G import Control.Exception (Handler (..), catches) import Data.List.NonEmpty qualified as NE import Data.Maybe (catMaybes) import Data.Proxy (Proxy (Proxy)) import Exception qualified as E import Git qualified import History.IssueEvents (IssueEvents (..)) import History.Issues (Issues (..)) import History.Plan (formulate, realise) import History.Scramble (fromComment) import Issue qualified as I import Parallel (parMapM) getIssues :: IO Issues getIssues = realise . (formulate Proxy) . NE.fromList =<< Git.getCommitHashes Nothing (Just Git.WorkingTree) getIssueEvents :: IO IssueEvents getIssueEvents = realise . (formulate Proxy) . NE.fromList =<< Git.getCommitHashes Nothing (Just Git.WorkingTree) -- | Get all issues in the given directory and file. getIssuesOfFile :: Git.CommitHash -> FilePath -> IO [I.Issue] getIssuesOfFile commitHash filename = ( fmap catMaybes . parMapM (fromComment commitHash) =<< G.getComments commitHash filename ) `catches` [ Handler \(_ :: E.UnknownFile) -> pure [], Handler \(_ :: E.UnsupportedLanguage) -> pure [] ]