aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2023-11-30 03:49:39 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2023-11-30 03:49:41 +0100
commit650d139254a0e17be0b1011f2fda6ea67f903e71 (patch)
treeebfcd8606da922c536cb6414cfa816d2aa65c17f /app
parentff5535f0a55201c6883c48c3892c9ef357904356 (diff)
feat: support closed issues
Closed issues can be shown, but listing closed issues requires passing `--closed`.
Diffstat (limited to 'app')
-rw-r--r--app/History/CommitInfo.hs56
-rw-r--r--app/History/PartialCommitInfo.hs3
-rw-r--r--app/Issue.hs6
-rw-r--r--app/Main.hs42
4 files changed, 69 insertions, 38 deletions
diff --git a/app/History/CommitInfo.hs b/app/History/CommitInfo.hs
index e260ce6..8e9f3b9 100644
--- a/app/History/CommitInfo.hs
+++ b/app/History/CommitInfo.hs
@@ -9,14 +9,14 @@ where
import Data.Binary (Binary)
import Data.Function (on)
import Data.List (deleteFirstsBy, find)
-import Data.Maybe (catMaybes, isJust)
+import Data.Maybe (isJust)
import GHC.Generics (Generic)
import History.CommitHash (CommitHash)
import History.IssueEvent (IssueEvent (..))
import History.PartialCommitInfo (PartialCommitInfo (..))
-import Issue (Issue (..), id)
+import Issue (Issue (..))
import Issue.Provenance qualified as I
-import Prelude hiding (id)
+import Prelude
-- TODO Change `CommitInfo` -> `CommitIssuesAll`
data CommitInfo = CommitInfo
@@ -38,35 +38,33 @@ fromPartialCommitInfos (partialCommitInfo : partialCommitInfos) =
propagate oldInfo newInfo@(PartialCommitInfo {..}) =
CommitInfo
{ issues =
- catMaybes $
- mergeListsBy
- eq
- ( \old new ->
- Just
- new
- { provenance =
- I.Provenance
- { first = old.provenance.first,
- last =
- if ((/=) `on` (.rawText)) old new
- then new.provenance.last
- else old.provenance.last
- }
- }
- )
- ( \old ->
- if elemBy eq old newInfo.issues
- || not (old.file `elem` newInfo.filesChanged)
- then Just old
- else Nothing
- )
- (\new -> Just new)
- oldInfo.issues
- newInfo.issues,
+ mergeListsBy
+ eq
+ ( \old new ->
+ new
+ { provenance =
+ I.Provenance
+ { first = old.provenance.first,
+ last =
+ if ((/=) `on` (.rawText)) old new
+ then new.provenance.last
+ else old.provenance.last
+ }
+ }
+ )
+ ( \old ->
+ if elemBy eq old newInfo.issues
+ || not (old.file `elem` newInfo.filesChanged)
+ then old
+ else old {closed = True}
+ )
+ id
+ oldInfo.issues
+ newInfo.issues,
..
}
- eq = (==) `on` id
+ eq = (==) `on` (.id)
-- | We assume that [CommitInfo] is sorted starting with the oldest
-- commits.
diff --git a/app/History/PartialCommitInfo.hs b/app/History/PartialCommitInfo.hs
index f973938..48b631e 100644
--- a/app/History/PartialCommitInfo.hs
+++ b/app/History/PartialCommitInfo.hs
@@ -102,7 +102,8 @@ fromComment cwd comment = do
markers = markers,
rawText = rawText,
commentStyle = commentStyle,
- comments = comments
+ comments = comments,
+ closed = False
}
else Nothing
)
diff --git a/app/Issue.hs b/app/Issue.hs
index f0940f2..bcb5333 100644
--- a/app/Issue.hs
+++ b/app/Issue.hs
@@ -31,7 +31,8 @@ data Issue = Issue
markers :: [T.Text],
rawText :: T.Text,
commentStyle :: G.CommentStyle,
- comments :: [T.Text]
+ comments :: [T.Text],
+ closed :: Bool
}
deriving (Show, Binary, Generic, Eq)
@@ -48,7 +49,8 @@ internalTags (Issue {..}) =
Tag "createdAt" $ Just $ T.pack $ show $ utctDay provenance.first.date,
Tag "modifiedAt" $ Just $ T.pack $ show $ utctDay provenance.last.date,
Tag "author" $ Just $ provenance.first.author.name,
- Tag "editor" $ Just $ provenance.last.author.name
+ Tag "editor" $ Just $ provenance.last.author.name,
+ Tag "state" $ Just $ if closed then "closed" else "open"
],
map (Tag "type" . Just) markers
]
diff --git a/app/Main.hs b/app/Main.hs
index 06327c4..26e3401 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -483,7 +483,8 @@ data Command
{ files :: [String],
filters :: [Filter],
sort :: [Sort],
- group :: Maybe T.Text
+ group :: Maybe T.Text,
+ closed :: Bool
}
| Log
| Show
@@ -513,6 +514,7 @@ listCmd =
<*> I.filterArg
<*> I.sortArg
<*> I.groupArg
+ <*> closedArg
logCmd :: O.Parser Command
logCmd =
@@ -531,6 +533,13 @@ tagsCmd =
filesArg :: O.Parser [String]
filesArg = O.many (O.strArgument (O.metavar "FILE" <> O.action "file"))
+closedArg :: O.Parser Bool
+closedArg =
+ O.switch
+ ( O.long "closed"
+ <> O.help "Show closed issues."
+ )
+
idArg :: O.Parser String
idArg =
O.strArgument
@@ -555,9 +564,16 @@ main :: IO ()
main = do
settings <- readSettings
O.execParser (O.info (options <**> O.helper) O.idm) >>= \case
- Options {internalTags, colorize, noPager, width, command = List {sort, filters, files, group = Just group}} -> do
+ Options {internalTags, colorize, noPager, width, command = List {sort, filters, files, group = Just group, closed}} -> do
let withinPath issue = if null files then True else any (\file -> file `isPrefixOf` issue.file) files
- ungroupedIssues <- applySorts sort . applyFilters filters . filter withinPath . trd3 . last <$> getHistory
+ ungroupedIssues <-
+ applySorts sort
+ . applyFilters filters
+ . filter withinPath
+ . applyClosed closed
+ . trd3
+ . last
+ <$> getHistory
let groupedIssues = I.groupIssuesBy group ungroupedIssues
putDoc colorize noPager width
. P.vsep
@@ -595,9 +611,16 @@ main = do
)
)
(M.toList groupedIssues)
- Options {internalTags, colorize, noPager, width, command = List {sort, filters, files, group = Nothing}} -> do
+ Options {internalTags, colorize, noPager, width, command = List {sort, filters, files, group = Nothing, closed}} -> do
let withinPath issue = if null files then True else any (\file -> file `isPrefixOf` issue.file) files
- issues <- applySorts sort . applyFilters filters . filter withinPath . trd3 . last <$> getHistory
+ issues <-
+ applySorts sort
+ . applyFilters filters
+ . filter withinPath
+ . applyClosed closed
+ . trd3
+ . last
+ <$> getHistory
putDoc colorize noPager width . P.vsep $
map
( \issue ->
@@ -643,7 +666,11 @@ main = do
Just issue -> pure issue
let meta = I.getMeta issues issue
let s =
- (LT.fromStrict (T.intercalate " " issue.markers) <> " " <> LT.fromStrict issue.title)
+ ( (if issue.closed then "**(CLOSED)** " else "")
+ <> LT.fromStrict (T.intercalate " " issue.markers)
+ <> " "
+ <> LT.fromStrict issue.title
+ )
<> maybe "" (("\n\n" <>) . LT.fromStrict) issue.description
<> LT.intercalate "\n" (map ((("***\n" :: LT.Text) <>) . LT.fromStrict) issue.comments)
if edit
@@ -734,6 +761,9 @@ main = do
)
tagsAndValues
+applyClosed :: Bool -> [Issue] -> [Issue]
+applyClosed closed = filter (\issue -> closed || not issue.closed)
+
prettyTags :: [I.Tag] -> [P.Doc P.AnsiStyle]
prettyTags =
map