aboutsummaryrefslogtreecommitdiffstats
path: root/app/Issue/Meta.hs
blob: 6e3bbf0f79eb38fe957cb722ab7b011b38712fdd (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
43
44
45
46
47
48
module Issue.Meta
  ( Meta (..),
    getMeta,
  )
where

import Data.List (intersperse)
import Data.Text qualified as T
import Issue (Issue (..))
import Issue.Render ()
import Issue.Tag (Tag, TagKey (..), tagValue)
import Render ((<<<))
import Render qualified as P

data Meta = Meta
  { referencedBy :: [(Issue, Tag)]
  }
  deriving (Show)

getMeta :: [Issue] -> Issue -> Meta
getMeta issues issue =
  Meta
    { referencedBy =
        concatMap
          ( \issueOther ->
              let tagsRelevant =
                    filter (\tag -> tagValue tag == Just issue.id) issueOther.tags
               in map (\tag -> (issueOther, tag)) tagsRelevant
          )
          issues
    }

instance P.Render Meta where
  render meta =
    if (not $ null meta.referencedBy)
      then
        P.styled [P.italicized]
          . (P.vsep . intersperse P.hardline)
          $ map
            ( \(otherIssue, tag) ->
                ("This commit was referenced by issue " :: T.Text)
                  <<< P.Linked otherIssue
                  <<< (" (" :: T.Text)
                  <<< TagKey tag
                  <<< (")." :: T.Text)
            )
            meta.referencedBy
      else P.emptyDoc