aboutsummaryrefslogtreecommitdiffstats
path: root/app/History.hs
blob: c80840085300c2f608c11f0417e37244525501d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module History
  ( Issues (..),
    IssueEvents (..),
    getIssues,
    getIssueEvents,
    getIssuesOfFile,
  )
where

import Backend qualified
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 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
    =<< Backend.getCommitHashes Nothing (Just Backend.WorkingTree)

getIssueEvents :: IO IssueEvents
getIssueEvents =
  realise . (formulate Proxy) . NE.fromList
    =<< Backend.getCommitHashes Nothing (Just Backend.WorkingTree)

-- | Get all issues in the given directory and file.
getIssuesOfFile :: Backend.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 []
              ]