From 91e188fbb70c20b939c221a95123934358d1c6c5 Mon Sep 17 00:00:00 2001 From: Fabian Kirchner Date: Wed, 29 Nov 2023 14:14:33 +0100 Subject: feat: collect issues referencing issue --- anissue.cabal | 1 + app/Issue.hs | 3 +++ app/Issue/Meta.hs | 27 +++++++++++++++++++++++++++ app/Main.hs | 2 ++ 4 files changed, 33 insertions(+) create mode 100644 app/Issue/Meta.hs diff --git a/anissue.cabal b/anissue.cabal index 170f0ae..5352c7c 100644 --- a/anissue.cabal +++ b/anissue.cabal @@ -80,6 +80,7 @@ executable anissue Issue Issue.Filter Issue.Group + Issue.Meta Issue.Provenance Issue.Sort Issue.Tag diff --git a/app/Issue.hs b/app/Issue.hs index f8bf0ec..f0940f2 100644 --- a/app/Issue.hs +++ b/app/Issue.hs @@ -56,6 +56,9 @@ internalTags (Issue {..}) = instance HasField "internalTags" Issue [Tag] where getField issue = internalTags issue +instance HasField "id" Issue (Maybe String) where + getField issue = id issue + toSpinalCase :: T.Text -> T.Text toSpinalCase = T.replace " " "-" . T.filter keep . T.toLower where diff --git a/app/Issue/Meta.hs b/app/Issue/Meta.hs new file mode 100644 index 0000000..d9851ec --- /dev/null +++ b/app/Issue/Meta.hs @@ -0,0 +1,27 @@ +module Issue.Meta + ( Meta (..), + getMeta, + ) +where + +import Data.Text qualified as T +import Issue (Issue (..)) +import Issue.Tag (Tag, tagValue) + +data Meta = Meta + { referencedBy :: [(Issue, Tag)] + } + deriving (Show) + +getMeta :: [Issue] -> Issue -> Meta +getMeta issues issue = + Meta + { referencedBy = + concatMap + ( \issueOther -> + let tagsRelevant = + filter (\tag -> tagValue tag == fmap T.pack issue.id) issueOther.tags + in map (\tag -> (issue, tag)) tagsRelevant + ) + issues + } diff --git a/app/Main.hs b/app/Main.hs index d6f653c..a16ee7e 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -403,6 +403,7 @@ import Issue qualified as I import Issue.Filter (Filter, applyFilters) import Issue.Filter qualified as I import Issue.Group qualified as I +import Issue.Meta qualified as I import Issue.Provenance qualified as I import Issue.Sort (Sort, applySorts) import Issue.Sort qualified as I @@ -652,6 +653,7 @@ main = do case find ((==) (Just id) . I.id) issues of Nothing -> die (printf "no issue with id `%s'\n" id) Just issue -> pure issue + let meta = I.getMeta issues issue let s = (LT.fromStrict (T.intercalate " " issue.markers) <> " " <> LT.fromStrict issue.title) <> maybe "" (("\n\n" <>) . LT.fromStrict) issue.description -- cgit v1.2.3