aboutsummaryrefslogtreecommitdiffstats
path: root/app/Issue/Provenance.hs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2023-12-08 03:04:43 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2023-12-08 03:04:43 +0100
commit5842e730152a2ae11fc8772a505baa3ba81b1e9c (patch)
treeb1c51d7371a173e646d6ac1bb0f9a15e96e34c58 /app/Issue/Provenance.hs
parentc1ff403387064ff0027b9e762cc6f6a8fa20c8d9 (diff)
chore: drop `Git.withWorkingTree`
Diffstat (limited to 'app/Issue/Provenance.hs')
-rw-r--r--app/Issue/Provenance.hs76
1 files changed, 5 insertions, 71 deletions
diff --git a/app/Issue/Provenance.hs b/app/Issue/Provenance.hs
index 18255da..321f6a2 100644
--- a/app/Issue/Provenance.hs
+++ b/app/Issue/Provenance.hs
@@ -1,80 +1,14 @@
-{-# OPTIONS_GHC -fno-warn-orphans #-}
-
module Issue.Provenance
( Provenance (..),
- 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 (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 Data.Binary (Binary)
import GHC.Generics (Generic)
-import Git.CommitHash (CommitHash)
-import Git.CommitHash qualified as C
-import Process (sh)
-import System.Process.Typed (setWorkingDir)
-import Prelude hiding (lines)
+import Git qualified
data Provenance = Provenance
- { first :: Commit,
- last :: Commit
- }
- deriving (Show, Generic, Binary, Eq)
-
-data Commit = Commit
- { hash :: CommitHash,
- date :: UTCTime,
- author :: Author
- }
- deriving (Show, Generic, Binary, Eq)
-
-data Author = Author
- { name :: T.Text,
- email :: T.Text
+ { first :: Git.Commit,
+ last :: Git.Commit
}
- deriving (Show, Generic, Binary, Eq)
-
--- XXX These are taken from `Data.Binary.Orphans` [1]. I cannot get importing
--- the instance from the package to work.. so we use `-fno-warn-orphans` here.
---
--- [1] https://hackage.haskell.org/package/binary-orphans-0.1.5.1/docs/src/Data-Binary-Orphans.html#line-132
-instance Binary UTCTime where
- get = UTCTime <$> get <*> get
- put (UTCTime d dt) = put d >> put dt
-
-instance Binary Day where
- get = fmap ModifiedJulianDay get
- put = put . toModifiedJulianDay
-
-instance Binary DiffTime where
- get = fmap picosecondsToDiffTime get
- put = (put :: Pico -> Put) . realToFrac
-
-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
- case rawProvenance of
- hash : rawDate : authorEmail : authorName : _ ->
- let date = read (unpack rawDate)
- in pure
- Commit
- { hash = C.Commit hash,
- date = date,
- author = Author authorName authorEmail
- }
- _ -> throwIO E.NoCommits
+ deriving (Eq, Show, Generic, Binary)