blob: 2f19a985f7449bdfc0d1bf31ce20ee2b5c1571b1 (
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
|
module Issue.Group
( groupArg,
groupIssuesByTag,
)
where
import Data.Map (Map)
import Data.Map qualified as M
import Data.Text qualified as T
import Issue (Issue (..))
import Issue.Tag qualified as I
import Options.Applicative qualified as O
groupArg :: O.Parser (Maybe T.Text)
groupArg =
O.optional
( O.option
(O.maybeReader (parse . T.pack))
( O.long "group"
<> O.metavar "TAG"
<> O.help "Group selected issues."
)
)
where
parse s
| "@" `T.isPrefixOf` s = Just (T.drop 1 s)
| otherwise = Nothing
groupIssuesByTag :: T.Text -> [Issue] -> Map T.Text [Issue]
groupIssuesByTag tagKey issues =
foldl
( \collected issue ->
foldl
(flip $ M.alter (Just . maybe [issue] (issue :)))
collected
(I.tagValuesOf tagKey (issue.tags ++ issue.internalTags))
)
M.empty
issues
|