diff options
Diffstat (limited to 'app/Issue.hs')
-rw-r--r-- | app/Issue.hs | 37 |
1 files changed, 23 insertions, 14 deletions
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 |