aboutsummaryrefslogtreecommitdiffstats
path: root/app/Issue
diff options
context:
space:
mode:
authorLibravatar Fabian Kirchner <kirchner@posteo.de>2023-11-07 14:21:33 +0100
committerLibravatar Fabian Kirchner <kirchner@posteo.de>2023-11-07 14:25:47 +0100
commit59ddbdb3d54de4009c2b3238661272f7e9fb80bc (patch)
tree9b62c8b9f81cb6f5a9f27b7a5dfe5746cbce05e1 /app/Issue
parent3bdaff7c176bdf00da9177a87819dad2c50c25b8 (diff)
add --group-by option
Diffstat (limited to 'app/Issue')
-rw-r--r--app/Issue/GroupBy.hs65
1 files changed, 65 insertions, 0 deletions
diff --git a/app/Issue/GroupBy.hs b/app/Issue/GroupBy.hs
new file mode 100644
index 0000000..0e8941f
--- /dev/null
+++ b/app/Issue/GroupBy.hs
@@ -0,0 +1,65 @@
+module Issue.GroupBy
+ ( groupByArg,
+ 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
+
+
+-- FIXME Parse group by using @topic syntax
+
+-- TODO Display number of issues within one group
+--
+-- ```
+-- Issue D
+-- Issue E
+--
+-- @topic tags (2 issues)
+-- Issue A
+-- Issue B @topic ids
+--
+-- @topic ids (2 issues)
+-- Issue B @topic tags
+-- Issue C
+-- ```
+
+-- TODO Add issues marker as internal tags
+--
+-- The internal makers `TODO`, `FIXME`, etc. should be available via the
+-- internal tag @type
+
+-- TODO Add author and editor as internal tags
+
+groupByArg :: O.Parser (Maybe T.Text)
+groupByArg =
+ O.optional
+ ( O.strOption
+ ( O.long "group-by"
+ <> O.metavar "TAG"
+ <> O.help "Group selected issues."
+ )
+ )
+
+groupIssuesBy :: T.Text -> [Issue] -> Map T.Text [Issue]
+groupIssuesBy groupBy issues =
+ foldl
+ ( \collected issue ->
+ foldl
+ (flip $ M.alter (Just . maybe [issue] (issue :)))
+ collected
+ (groupsOfIssue groupBy issue)
+ )
+ M.empty
+ issues
+ where
+ groupsOfIssue group issue =
+ mapMaybe I.tagValue $
+ filter (\(Tag key _) -> key == group) (issue.tags ++ issue.internalTags)