diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-10-20 09:55:13 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-11-07 09:50:52 +0100 |
commit | eafbd88429a80f058efaa4efd28fbfb8271065c3 (patch) | |
tree | 35ae08955e34014fa6666bab26807a42fbbbbcee /app/Issue | |
parent | ea1236f2cf6d3ef4b739b2ca28f47a3bbed42295 (diff) |
record both creation and update in provenance
Diffstat (limited to 'app/Issue')
-rw-r--r-- | app/Issue/Provenance.hs | 47 | ||||
-rw-r--r-- | app/Issue/Tag.hs | 4 |
2 files changed, 33 insertions, 18 deletions
diff --git a/app/Issue/Provenance.hs b/app/Issue/Provenance.hs index f3d382c..4d69472 100644 --- a/app/Issue/Provenance.hs +++ b/app/Issue/Provenance.hs @@ -2,28 +2,45 @@ module Issue.Provenance ( Provenance (..), - provenanceFromHEAD, + Commit (..), + Author (..), + commitFromHEAD, ) where +import Control.Exception (throwIO) import Data.Binary (Binary, Put, get, put) import Data.ByteString.Lazy.Char8 (toStrict) import Data.Fixed (Pico) import Data.Function ((&)) -import Data.Text (Text, lines, splitOn, unpack) +import Data.Text (lines, splitOn, unpack) +import Data.Text qualified as T import Data.Text.Encoding (decodeUtf8) import Data.Time.Calendar (Day (..), toModifiedJulianDay) import Data.Time.Clock (DiffTime, UTCTime (..), picosecondsToDiffTime) +import Exception qualified as E import GHC.Generics (Generic) import Process (sh) import System.Process.Typed (setWorkingDir) import Prelude hiding (lines) data Provenance = Provenance - { firstCommit :: Text, + { first :: Commit, + last :: Commit + } + deriving (Show, Generic, Binary, Eq) + +data Commit = Commit + { -- TODO `T.Text` -> `CommitHash` + hash :: T.Text, date :: UTCTime, - authorEmail :: Text, - authorName :: Text + author :: Author + } + deriving (Show, Generic, Binary, Eq) + +data Author = Author + { name :: T.Text, + email :: T.Text } deriving (Show, Generic, Binary, Eq) @@ -43,22 +60,20 @@ instance Binary DiffTime where get = fmap picosecondsToDiffTime get put = (put :: Pico -> Put) . realToFrac -provenanceFromHEAD :: FilePath -> IO (Maybe Provenance) -provenanceFromHEAD cwd = do +commitFromHEAD :: FilePath -> IO Commit +commitFromHEAD cwd = do rawProvenance <- fmap (splitOn "\NUL" . head . lines . decodeUtf8 . toStrict) $ sh $ "git show --quiet --format='%H%x00%ai%x00%ae%x00%an'" & setWorkingDir cwd - pure $ case rawProvenance of - firstCommit' : rawDate : authorEmail : authorName : _ -> + case rawProvenance of + hash : rawDate : authorEmail : authorName : _ -> let date = read (unpack rawDate) - in Just - Provenance - { firstCommit = firstCommit', + in pure + Commit + { hash = hash, date = date, - authorEmail = authorEmail, - authorName = authorName + author = Author authorName authorEmail } - _ -> - Nothing + _ -> throwIO E.NoCommits diff --git a/app/Issue/Tag.hs b/app/Issue/Tag.hs index 42a371d..2947ec9 100644 --- a/app/Issue/Tag.hs +++ b/app/Issue/Tag.hs @@ -13,7 +13,7 @@ import Data.Text (Text, pack) import Data.Text qualified as T import Data.Time.Clock (UTCTime (utctDay)) import GHC.Generics (Generic) -import Issue.Provenance (Provenance (..)) +import Issue.Provenance (Provenance (..), Commit(..)) data Tag = Tag Text (Maybe Text) deriving (Show, Generic, Binary, Eq) @@ -46,7 +46,7 @@ internalTags title provenance' = maybe [] ( \provenance -> - [ Tag "createdAt" $ Just $ pack $ show $ utctDay provenance.date + [ Tag "createdAt" $ Just $ pack $ show $ utctDay provenance.first.date ] ) provenance' |