aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2023-10-04 11:16:34 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2023-10-04 11:16:34 +0200
commit9b5bd101f7c511a9a0dd4a12a5480ff2628f0b50 (patch)
tree3e71a222dad2959e9da9f09354bd926dfe1f7fc0
parent13b2faa45ca5df4933619a06d28c42686aea8725 (diff)
add tags to issues
-rw-r--r--anissue.cabal1
-rw-r--r--app/Issue.hs8
-rw-r--r--app/Issue/Tag.hs23
-rw-r--r--app/Main.hs19
4 files changed, 41 insertions, 10 deletions
diff --git a/anissue.cabal b/anissue.cabal
index e15a069..84c3eb3 100644
--- a/anissue.cabal
+++ b/anissue.cabal
@@ -67,6 +67,7 @@ executable anissue
-- Modules included in this executable, other than Main.
other-modules:
Issue
+ Issue.Tag
TreeGrepper.FileType
TreeGrepper.Match
TreeGrepper.Result
diff --git a/app/Issue.hs b/app/Issue.hs
index 02de257..66047b6 100644
--- a/app/Issue.hs
+++ b/app/Issue.hs
@@ -9,6 +9,8 @@ import Data.List (find)
import Data.Maybe (fromMaybe)
import Data.Text (Text)
import Data.Text qualified as T
+import Issue.Tag (Tag)
+import Issue.Tag qualified as I
import TreeGrepper.FileType qualified as G
import TreeGrepper.Match (Match (..))
import TreeGrepper.Match qualified as G
@@ -19,7 +21,8 @@ data Issue = Issue
{ title :: Text,
description :: Text,
start :: G.Position,
- end :: G.Position
+ end :: G.Position,
+ tags :: [Tag]
}
fromMatch :: G.Result -> G.Match -> Maybe Issue
@@ -31,7 +34,8 @@ fromMatch result match =
{ title = stripMarker (T.strip (T.unlines title)),
description = T.strip (T.unlines description),
start = match.start,
- end = match.end
+ end = match.end,
+ tags = I.extract text
}
else Nothing
where
diff --git a/app/Issue/Tag.hs b/app/Issue/Tag.hs
new file mode 100644
index 0000000..2699342
--- /dev/null
+++ b/app/Issue/Tag.hs
@@ -0,0 +1,23 @@
+{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE ViewPatterns #-}
+
+module Issue.Tag (Tag (..), extract) where
+
+import Data.Maybe (catMaybes)
+import Data.Text (Text)
+import Data.Text qualified as T
+
+data Tag = Tag Text Text deriving (Show)
+
+extract :: Text -> [Tag]
+extract =
+ catMaybes
+ . map
+ ( ( \case
+ ((T.uncons -> Just ('@', k)) : v) ->
+ Just (Tag k (T.unwords v))
+ _ -> Nothing
+ )
+ . T.words
+ )
+ . T.lines
diff --git a/app/Main.hs b/app/Main.hs
index 630ba89..723a0a1 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -32,13 +32,6 @@
-- Additionally to TODO, also FIXME should start an issue. There might
-- be more interesting keywords.
--- TODO Add tags
---
--- Users can add tags inside issue title and description. Tags are slugs
--- and start with @
---
--- @assigned aforemny
-
-- TODO Add filter by tags
--
-- Users can filter issues for tags with the option -t/--tag @tag.
@@ -57,9 +50,11 @@ import Data.List (intercalate)
import Data.Maybe (catMaybes)
import Data.Maybe qualified as Maybe
import Data.String qualified as String
+import Data.Text qualified as T
import Data.Text.IO qualified as T
import Issue (Issue (..))
import Issue qualified as I
+import Issue.Tag qualified as I
import Options.Applicative ((<**>))
import Options.Applicative qualified as O
import System.Exit (ExitCode (ExitFailure), exitWith)
@@ -134,7 +129,15 @@ showMatches issue = do
listMatches :: Issue -> IO ()
listMatches issue =
- T.putStrLn issue.title
+ printf
+ "%s%s\n"
+ issue.title
+ ( if null issue.tags
+ then ""
+ else
+ T.append " " . T.intercalate " " $
+ map (\(I.Tag k v) -> T.intercalate ":" [k, v]) issue.tags
+ )
data UnknownFileExtension = UnknownFileExtension
{ extension :: String