aboutsummaryrefslogtreecommitdiffstats
path: root/app/Issue/Provenance.hs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2023-10-20 09:55:13 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2023-11-07 09:50:52 +0100
commiteafbd88429a80f058efaa4efd28fbfb8271065c3 (patch)
tree35ae08955e34014fa6666bab26807a42fbbbbcee /app/Issue/Provenance.hs
parentea1236f2cf6d3ef4b739b2ca28f47a3bbed42295 (diff)
record both creation and update in provenance
Diffstat (limited to 'app/Issue/Provenance.hs')
-rw-r--r--app/Issue/Provenance.hs47
1 files changed, 31 insertions, 16 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