From cffebbf54cba9b99db0629a7179a18ff8168159f Mon Sep 17 00:00:00 2001
From: Fabian Kirchner <fabian.kirchner@hereon.de>
Date: Wed, 29 Nov 2023 13:46:43 +0100
Subject: fix: compute issueEvents correctly

---
 app/History/CommitInfo.hs | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/app/History/CommitInfo.hs b/app/History/CommitInfo.hs
index bea0cd3..e260ce6 100644
--- a/app/History/CommitInfo.hs
+++ b/app/History/CommitInfo.hs
@@ -68,13 +68,15 @@ fromPartialCommitInfos (partialCommitInfo : partialCommitInfos) =
 
     eq = (==) `on` id
 
+-- | We assume that [CommitInfo] is sorted starting with the oldest
+-- commits.
 issueEvents :: [CommitInfo] -> [(CommitHash, [IssueEvent])]
-issueEvents xs = zip (map (.hash) xs') (zipWith diffCommitInfos xs xs')
+issueEvents xs = zip (map (.hash) xs) (zipWith diffCommitInfos predecessors xs)
   where
-    xs' = tail xs
+    predecessors = Nothing : map Just xs
 
-diffCommitInfos :: CommitInfo -> CommitInfo -> [IssueEvent]
-diffCommitInfos oldInfo newInfo =
+diffCommitInfos :: Maybe CommitInfo -> CommitInfo -> [IssueEvent]
+diffCommitInfos maybeOldInfo newInfo =
   concat
     [ [IssueCreated newHash issue | issue <- deleteFirstsBy eq newIssues oldIssues],
       [ IssueChanged newHash (last issues)
@@ -86,7 +88,10 @@ diffCommitInfos oldInfo newInfo =
   where
     newHash = newInfo.hash
     newIssues = newInfo.issues
-    oldIssues = oldInfo.issues
+    oldIssues =
+      case maybeOldInfo of
+        Nothing -> []
+        Just oldInfo -> oldInfo.issues
 
     eq = (==) `on` id
 
-- 
cgit v1.2.3