aboutsummaryrefslogtreecommitdiffstats
path: root/app/History/Issues.hs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2023-12-18 13:50:22 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-25 07:42:51 +0100
commitfc0afaaa273f5b5d3696df87d70d5347a13bb9ac (patch)
treea7e48842f71511f39a367e5dff84f41c02f3d859 /app/History/Issues.hs
parent812fcbadae72960d200286355c9aaecfbe350bf2 (diff)
feat: compute history top to bottom
Disables caching.
Diffstat (limited to 'app/History/Issues.hs')
-rw-r--r--app/History/Issues.hs72
1 files changed, 72 insertions, 0 deletions
diff --git a/app/History/Issues.hs b/app/History/Issues.hs
new file mode 100644
index 0000000..08ad772
--- /dev/null
+++ b/app/History/Issues.hs
@@ -0,0 +1,72 @@
+module History.Issues
+ ( Issues (..),
+ )
+where
+
+import Data.Binary (Binary)
+import Data.Function (on)
+import Data.Map qualified as M
+import Data.Proxy (Proxy)
+import Data.Text qualified as T
+import GHC.Generics (Generic)
+import Git qualified
+import History.Plan (Id, Planable, Proto, assume, propagate, protoOf)
+import History.Scramble (Scramble (..), getIssuesOfFile)
+import Issue qualified as I
+
+data Issues = Issues
+ { commitHash :: Git.CommitHash,
+ issues :: M.Map T.Text I.Issue
+ }
+ deriving (Show, Generic, Binary)
+
+instance Planable Issues where
+ type Id Issues = Git.CommitHash
+ type Proto Issues = Scramble
+ protoOf :: Proxy Issues -> Git.CommitHash -> IO Scramble
+ protoOf _ commitHash = do
+ filesChanged <- Git.getChangedFilesOf commitHash
+ issues <- concat <$> mapM (getIssuesOfFile commitHash) filesChanged
+ pure $
+ Scramble
+ { issues =
+ M.unions
+ [ M.singleton issue.id issue | issue <- issues
+ ],
+ ..
+ }
+
+ assume :: Scramble -> Issues
+ assume (Scramble {..}) = Issues {..}
+
+ propagate :: [Id Issues] -> Issues -> Scramble -> Issues
+ propagate _ topIssues bottomScramble =
+ Issues
+ { commitHash = topIssues.commitHash,
+ issues =
+ M.mergeWithKey
+ ( \_ topIssue bottomIssue ->
+ Just $
+ topIssue
+ { I.provenance =
+ I.Provenance
+ { first = bottomIssue.provenance.first,
+ last =
+ if ((/=) `on` (.rawTextHash)) topIssue bottomIssue
+ then topIssue.provenance.last
+ else bottomIssue.provenance.last
+ }
+ }
+ )
+ ( \topIssues -> topIssues
+ )
+ ( \bottomIssues ->
+ M.map
+ ( \bottomIssue ->
+ bottomIssue {I.closed = True}
+ )
+ bottomIssues
+ )
+ topIssues.issues
+ bottomScramble.issues
+ }