aboutsummaryrefslogtreecommitdiffstats
path: root/app/Issue/Group.hs
diff options
context:
space:
mode:
Diffstat (limited to 'app/Issue/Group.hs')
-rw-r--r--app/Issue/Group.hs47
1 files changed, 47 insertions, 0 deletions
diff --git a/app/Issue/Group.hs b/app/Issue/Group.hs
new file mode 100644
index 0000000..69caf20
--- /dev/null
+++ b/app/Issue/Group.hs
@@ -0,0 +1,47 @@
+module Issue.Group
+ ( groupArg,
+ groupIssuesBy,
+ )
+where
+
+import Data.Map (Map)
+import Data.Map qualified as M
+import Data.Maybe (mapMaybe)
+import Data.Text qualified as T
+import Issue (Issue (..))
+import Issue.Tag (Tag (..))
+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
+
+groupIssuesBy :: T.Text -> [Issue] -> Map T.Text [Issue]
+groupIssuesBy group issues =
+ foldl
+ ( \collected issue ->
+ foldl
+ (flip $ M.alter (Just . maybe [issue] (issue :)))
+ collected
+ (groupsOfIssue group issue)
+ )
+ M.empty
+ issues
+
+groupsOfIssue :: T.Text -> Issue -> [T.Text]
+groupsOfIssue group issue =
+ mapMaybe I.tagValue
+ . filter (\(Tag key _) -> key == group)
+ $ issue.tags ++ issue.internalTags