diff options
Diffstat (limited to 'app/History')
-rw-r--r-- | app/History/Cache.hs | 33 | ||||
-rw-r--r-- | app/History/CommitHash.hs | 37 | ||||
-rw-r--r-- | app/History/IssueEvent.hs | 54 |
3 files changed, 0 insertions, 124 deletions
diff --git a/app/History/Cache.hs b/app/History/Cache.hs deleted file mode 100644 index 978f3d9..0000000 --- a/app/History/Cache.hs +++ /dev/null @@ -1,33 +0,0 @@ -module History.Cache - ( cached, - cachedMaybe, - ) -where - -import Data.Binary (Binary, decodeFileOrFail, encodeFile) -import Data.Text qualified as T -import Debug -import Git qualified -import System.Directory (createDirectoryIfMissing, doesFileExist) -import System.FilePath ((</>)) - -cached :: Binary a => T.Text -> IO a -> IO a -cached key func = do - root <- Git.getRootDir - createDirectoryIfMissing True (root </> ".anissue") - let file = (root </> ".anissue" </> T.unpack key) - doesFileExist file >>= \case - True -> - decodeFileOrFail file >>= \case - Left e -> debug "e" e `seq` generate file - Right blob -> pure blob - False -> generate file - where - generate file = do - blob <- func - encodeFile (debug "cache miss" file) blob - pure blob - -cachedMaybe :: Binary a => Maybe T.Text -> IO a -> IO a -cachedMaybe Nothing func = func -cachedMaybe (Just key) func = cached key func diff --git a/app/History/CommitHash.hs b/app/History/CommitHash.hs deleted file mode 100644 index 1075b2f..0000000 --- a/app/History/CommitHash.hs +++ /dev/null @@ -1,37 +0,0 @@ -module History.CommitHash - ( CommitHash (..), - toShortText, - toText, - ) -where - -import Data.Binary (Binary) -import Data.Maybe (fromMaybe) -import Data.Text qualified as T -import GHC.Generics (Generic) -import Render qualified as P - -data CommitHash - = WorkingTree - | Commit T.Text - deriving (Eq, Show, Binary, Generic) - -toShortText :: CommitHash -> Maybe T.Text -toShortText = fmap (T.take 7) . toText - -toText :: CommitHash -> Maybe T.Text -toText WorkingTree = Nothing -toText (Commit hash) = Just hash - -instance P.Render CommitHash where - render = P.render . P.Detailed - -instance P.Render (P.Detailed CommitHash) where - render (P.Detailed commitHash) = - P.styled [P.color P.Yellow] $ - P.render (fromMaybe "<dirty>" (toText commitHash)) - -instance P.Render (P.Summarized CommitHash) where - render (P.Summarized commitHash) = - P.styled [P.color P.Yellow] $ - P.render (fromMaybe "<dirty>" (toShortText commitHash)) diff --git a/app/History/IssueEvent.hs b/app/History/IssueEvent.hs deleted file mode 100644 index 932cfd9..0000000 --- a/app/History/IssueEvent.hs +++ /dev/null @@ -1,54 +0,0 @@ -module History.IssueEvent (IssueEvent (..)) where - -import Data.Binary (Binary) -import GHC.Generics (Generic) -import History.CommitHash (CommitHash) -import Issue (Issue) -import Issue.Render qualified as I -import Patch (Patch) -import Render ((<<<)) -import Render qualified as P - -data IssueEvent - = IssueCreated - { hash :: CommitHash, - issue :: Issue, - patch :: Patch - } - | IssueChanged - { hash :: CommitHash, - oldIssue :: Issue, - issue :: Issue, - patch :: Patch - } - | IssueDeleted - { hash :: CommitHash, - issue :: Issue, - patch :: Patch - } - deriving (Show, Generic, Binary) - -instance P.Render IssueEvent where - render = P.render . P.Detailed - -instance P.Render (P.Detailed IssueEvent) where - render (P.Detailed issueEvent) = - P.Summarized issueEvent - <<< P.hardline @P.AnsiStyle - <<< issueEvent.patch - -instance P.Render (P.Summarized IssueEvent) where - render (P.Summarized issueEvent) = - case issueEvent of - IssueCreated {hash, issue} -> - P.Summarized hash - <<< P.styled [P.color P.Green] "created" - <<< I.IssueTitle issue - IssueChanged {hash, issue} -> - P.Summarized hash - <<< P.styled [P.color P.Green] "changed" - <<< I.IssueTitle issue - IssueDeleted {hash, issue} -> - P.Summarized hash - <<< P.styled [P.color P.Green] "deleted" - <<< I.IssueTitle issue |