aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/Issue.hs13
-rw-r--r--app/Issue/Tag.hs17
-rw-r--r--app/Issue/Text.hs4
-rw-r--r--app/Main.hs4
4 files changed, 23 insertions, 15 deletions
diff --git a/app/Issue.hs b/app/Issue.hs
index 249ce92..07bddee 100644
--- a/app/Issue.hs
+++ b/app/Issue.hs
@@ -20,24 +20,27 @@ data Issue = Issue
description :: Maybe Text,
start :: G.Position,
end :: G.Position,
- tags :: [Tag]
+ tags :: [Tag],
+ internalTags :: [Tag]
}
fromMatch :: G.Result -> G.Match -> Maybe Issue
fromMatch result match =
- if T.isPrefixOf marker title
+ if T.isPrefixOf marker title'
then
Just
Issue
- { title = stripMarker title,
+ { title = title,
description = stripTags <$> description,
start = match.start,
end = match.end,
- tags = maybe [] I.extract description
+ tags = maybe [] I.extractTags description,
+ internalTags = I.internalTags title
}
else Nothing
where
- (title, description) = I.extractText result.file_type match.text
+ (title', description) = I.extractText result.file_type match.text
+ title = stripMarker title'
marker :: Text
marker = "TODO"
diff --git a/app/Issue/Tag.hs b/app/Issue/Tag.hs
index 2699342..af12331 100644
--- a/app/Issue/Tag.hs
+++ b/app/Issue/Tag.hs
@@ -1,7 +1,8 @@
{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}
-module Issue.Tag (Tag (..), extract) where
+module Issue.Tag (Tag (..), extractTags, internalTags) where
import Data.Maybe (catMaybes)
import Data.Text (Text)
@@ -9,8 +10,8 @@ import Data.Text qualified as T
data Tag = Tag Text Text deriving (Show)
-extract :: Text -> [Tag]
-extract =
+extractTags :: Text -> [Tag]
+extractTags =
catMaybes
. map
( ( \case
@@ -21,3 +22,13 @@ extract =
. T.words
)
. T.lines
+
+internalTags :: Text -> [Tag]
+internalTags title =
+ [ Tag "id" (toSpinalCase title)
+ ]
+
+toSpinalCase :: Text -> Text
+toSpinalCase = T.replace " " "-" . T.filter keep . T.toLower
+ where
+ keep = (`elem` (concat [[' ', '-'], ['a' .. 'z'], ['0' .. '9']]))
diff --git a/app/Issue/Text.hs b/app/Issue/Text.hs
index 190e1c7..2d3aac4 100644
--- a/app/Issue/Text.hs
+++ b/app/Issue/Text.hs
@@ -16,9 +16,7 @@ extractText fileType rawText = (title, description)
where
text = stripComments fileType $ stripLines rawText
stripLines = T.unlines . map T.strip . T.lines
- (title, description') =
- second T.stripStart $
- T.breakOn "\n\n" text
+ (title, description') = second T.stripStart $ T.breakOn "\n\n" text
description
| T.null description' = Nothing
| otherwise = Just description'
diff --git a/app/Main.hs b/app/Main.hs
index f48d824..30495a5 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -63,10 +63,6 @@
-- Additionally to TODO, also FIXME should start an issue. There might
-- be more interesting keywords.
--- TODO Generate and show hash for each issue
---
--- The show hash should be generated by slugifying the issues title. Shell completion will help with the initially long issue ids. Internally, the slugified title should be added as an `@id` tag, unless an `@id` tag is present on the issue.
-
module Main where
import Control.Exception (Exception, catch, throw, throwIO)