diff options
-rw-r--r-- | anissue.cabal | 1 | ||||
-rw-r--r-- | app/Issue.hs | 37 | ||||
-rw-r--r-- | app/Main.hs | 18 |
3 files changed, 39 insertions, 17 deletions
diff --git a/anissue.cabal b/anissue.cabal index 56eefd0..e4c3b9b 100644 --- a/anissue.cabal +++ b/anissue.cabal @@ -87,6 +87,7 @@ executable anissue prettyprinter, prettyprinter-ansi-terminal, text, + time, typed-process -- Directories containing source files. diff --git a/app/Issue.hs b/app/Issue.hs index e37c20e..fabd88f 100644 --- a/app/Issue.hs +++ b/app/Issue.hs @@ -5,11 +5,14 @@ module Issue (Issue (..), Provenance (..), fromMatch, id) where +import Data.ByteString.Lazy (toStrict) import Data.ByteString.Lazy.Char8 (unpack) import Data.List (find, foldl') import Data.String (fromString) import Data.Text (Text) import Data.Text qualified as T +import Data.Text.Encoding (decodeUtf8) +import Data.Time.Clock (UTCTime) import Issue.Tag (Tag (..)) import Issue.Tag qualified as I import Issue.Text qualified as I @@ -25,7 +28,7 @@ data Issue = Issue { title :: Text, description :: Maybe Text, file :: String, - provenance :: Provenance, + provenance :: Maybe Provenance, start :: G.Position, end :: G.Position, tags :: [Tag], @@ -34,7 +37,10 @@ data Issue = Issue deriving (Show) data Provenance = Provenance - { firstCommit :: Maybe String + { firstCommit :: Text, + date :: UTCTime, + authorEmail :: Text, + authorName :: Text } deriving (Show) @@ -47,29 +53,32 @@ id issue = fromMatch :: G.Result -> G.Match -> IO (Maybe Issue) fromMatch result match = do - firstCommits <- - fmap (lines . unpack) $ + rawProvenance <- + fmap (map (T.splitOn "\NUL") . T.lines . decodeUtf8 . toStrict) $ sh $ ( fromString ( printf - "git --no-pager log --reverse -S\"$(cat %s | tail -n+%d | head -%d)\" --format=%%H -- %s" + "git --no-pager log --reverse -S\"$(cat %s | tail -n+%d | head -%d)\" --format='%%H%%x00%%ai%%x00%%ae%%x00%%an' -- %s" (quote result.file) match.start.row (match.end.row - match.start.row + 1) (quote result.file) ) ) - let firstCommit = - case firstCommits of - [] -> + let provenance = + case rawProvenance of + (firstCommit' : rawDate : authorEmail : authorName : _) : _ -> + let date = read (T.unpack rawDate) + in Just + Provenance + { firstCommit = firstCommit', + date = date, + authorEmail = authorEmail, + authorName = authorName + } + _ -> Nothing - firstCommit' : _ -> - Just firstCommit' - provenance = - Provenance - { firstCommit = firstCommit - } pure ( if any (\marker -> T.isPrefixOf marker title') issueMarkers then diff --git a/app/Main.hs b/app/Main.hs index 334f3ce..5793363 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -88,7 +88,7 @@ import Options.Applicative ((<**>)) import Options.Applicative qualified as O import Prettyprinter qualified as P import Prettyprinter.Render.Terminal qualified as P -import Process (sh, sh_, quote) +import Process (quote, sh, sh_) import System.Exit (ExitCode (ExitFailure), exitWith) import System.FilePath qualified as F import System.Process.Typed qualified as P @@ -178,8 +178,7 @@ main = do ( \issue -> P.hsep ( concat - [ [P.pretty issue.provenance.firstCommit, P.pretty (" " :: String)], - [P.annotate P.bold (P.pretty issue.title)], + [ [P.annotate P.bold (P.pretty issue.title)], map ( \(I.Tag k v) -> P.annotate (P.colorDull P.Yellow) $ @@ -203,6 +202,19 @@ main = do issue.file ++ ":" ++ show issue.start.row + ++ ( case issue.provenance of + Nothing -> + "HEAD" + Just provenance -> + "\nvia " + ++ T.unpack provenance.firstCommit + ++ "\nby " + ++ T.unpack provenance.authorName + ++ " <" + ++ T.unpack provenance.authorEmail + ++ ">\nat " + ++ show provenance.date + ) ++ "\n\n" sh_ ( P.setStdin |