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