diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-10-17 12:34:58 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-10-17 12:34:58 +0200 |
commit | 8c374417d9ca0ee4c4d75ee171d8b4e2f150bf78 (patch) | |
tree | 1c28eb3ba9cf4e8ef088e622b1ea3546c7332aff | |
parent | 08f75854a59c2ebc4cf6685d5d5f7041d7ef29e3 (diff) |
add `log` command
-rw-r--r-- | app/History.hs | 20 | ||||
-rw-r--r-- | app/Main.hs | 36 |
2 files changed, 54 insertions, 2 deletions
diff --git a/app/History.hs b/app/History.hs index fee1f2e..36dc1fc 100644 --- a/app/History.hs +++ b/app/History.hs @@ -1,4 +1,10 @@ -module History (getIssues, listIssues) where +module History + ( getIssues, + listIssues, + listEvents, + IssueEvent (..), + ) +where import Control.Exception (Exception, catch, handle, throw) import Data.Aeson (eitherDecode) @@ -28,6 +34,18 @@ import TreeGrepper.Result qualified as G import Prelude hiding (id, lines) import Prelude qualified as Prelude +listEvents :: IO [[IssueEvent]] +listEvents = do + commitHashes <- fmap reverse getCommitHashes + case commitHashes of + [] -> pure [] + hashFirst : hashesRest -> do + issuesInitial <- cached (append hashFirst (pack ".all")) (\_ -> getIssuesCommitAll hashFirst) + commitInfos <- mapM (\hash -> cached (append hash (pack ".changed")) (\_ -> getCommitInfo hash)) hashesRest + commitInfoWorkingTree <- getCommitInfoWorkingTree [] + let eventses = getEvents hashFirst issuesInitial (commitInfos ++ [commitInfoWorkingTree]) + pure eventses + listIssues :: [Sort] -> [Filter] -> [FilePath] -> IO [Issue] listIssues sort filters paths = do commitHashes <- fmap reverse getCommitHashes diff --git a/app/Main.hs b/app/Main.hs index 28632ad..a7901bd 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -453,7 +453,7 @@ import Data.Text qualified as T import Data.Text.Lazy qualified as LT import Data.Text.Lazy.IO qualified as LT import Data.Time.Clock (UTCTime (utctDay)) -import History (listIssues) +import History (IssueEvent (..), listEvents, listIssues) import Issue (Issue (..)) import Issue qualified as I import Issue.Filter (Filter) @@ -545,6 +545,7 @@ data Command filters :: [Filter], sort :: [Sort] } + | Log | Show { id :: String } @@ -555,6 +556,8 @@ cmd = O.hsubparser . mconcat $ [ O.command "list" . O.info listCmd $ O.progDesc "List all issues", + O.command "log" . O.info logCmd $ + O.progDesc "Show a log of all issues", O.command "show" . O.info showCmd $ O.progDesc "Show details of all issues" ] @@ -566,6 +569,10 @@ listCmd = <*> I.filterArg <*> I.sortArg +logCmd :: O.Parser Command +logCmd = + pure Log + showCmd :: O.Parser Command showCmd = Show @@ -625,6 +632,33 @@ main = do ] ) issues + Options {colorize, noPager, width, command = Log} -> do + -- TODO Reconcile log + -- + -- When viewing the log I am confused by + -- + -- (1) lots of sequential commits "changing" the same one issue, but no + -- others, + -- (2) having unknown hashes interleaved + -- + -- I would assume changes to be less frequent, or, if no changes are + -- considered changes, the log output sorted by hashes (and not + -- commits?). I would expect only the first commit hash to be unknown. + -- + -- Thoughts? :-) + es <- concat <$> listEvents + putDoc colorize noPager width . P.vsep $ + map + ( \e -> + let shortHash = P.annotate (P.color P.Yellow) . P.pretty $ maybe "UNKNOWN" (T.take 7) e.hash + kwd = P.annotate (P.color P.Green) . P.pretty . T.pack + title issue = P.annotate (P.color P.Blue) . P.annotate P.bold $ P.pretty issue.title + in case e of + IssueCreated {issue} -> shortHash <+> kwd "created" <+> title issue + IssueChanged {issue} -> shortHash <+> kwd "changed" <+> title issue + IssueDeleted {} -> shortHash <+> kwd "deleted" + ) + es Options {colorize, width, command = Show {id}} -> do issues <- listIssues [] [] [] case find ((==) (Just id) . I.id) issues of |