From f849fe4f8bd424a57de870d6cb8f038221dd7ff2 Mon Sep 17 00:00:00 2001
From: Alexander Foremny <aforemny@posteo.de>
Date: Fri, 20 Oct 2023 09:55:53 +0200
Subject: add internal tag @modifiedAt

---
 app/History/CommitInfo.hs | 45 +++++++++++++++++++++++++--------------------
 app/Issue/Tag.hs          |  5 +++--
 app/Main.hs               |  7 +++++--
 3 files changed, 33 insertions(+), 24 deletions(-)

diff --git a/app/History/CommitInfo.hs b/app/History/CommitInfo.hs
index b42e1ba..5285e68 100644
--- a/app/History/CommitInfo.hs
+++ b/app/History/CommitInfo.hs
@@ -46,14 +46,18 @@ fromPartialCommitInfos (partialCommitInfo : partialCommitInfos) =
                     Just
                       new
                         { provenance =
-                            (\oldProvenance newProvenance ->
-                              ( I.Provenance
-                                  { first = oldProvenance.first,
-                                    last = newProvenance.last
-                                  }
-                              )
+                            ( \oldProvenance newProvenance ->
+                                ( I.Provenance
+                                    { first = oldProvenance.first,
+                                      last =
+                                        if clear old /= clear new
+                                          then newProvenance.last
+                                          else oldProvenance.last
+                                    }
+                                )
                             )
-                            <$> old.provenance <*> new.provenance,
+                              <$> old.provenance
+                              <*> new.provenance,
                           internalTags = I.internalTags new.title old.provenance
                         }
                 )
@@ -91,21 +95,22 @@ diffCommitInfos oldInfo newInfo =
     newIssues = newInfo.issues
     oldIssues = oldInfo.issues
 
-    -- TODO Fix issue comparison
-    --
-    -- Because issues carry `provenance` and `internalTags`, issues compare
-    -- unequally when we want them to be equal.
-    clear i =
-      i
-        { provenance = Nothing,
-          internalTags = [],
-          start = Position 0 0,
-          end = Position 0 0,
-          file = ""
-        }
-
     eq = (==) `on` id
 
+-- TODO Fix issue comparison
+--
+-- Because issues carry `provenance` and `internalTags`, issues compare
+-- unequally when we want them to be equal.
+clear :: Issue -> Issue
+clear i =
+  i
+    { provenance = Nothing,
+      internalTags = [],
+      start = Position 0 0,
+      end = Position 0 0,
+      file = ""
+    }
+
 mergeListsBy :: (a -> a -> Bool) -> (a -> a -> b) -> (a -> b) -> (a -> b) -> [a] -> [a] -> [b]
 mergeListsBy eq onBoth onLeft onRight lefts rights =
   concat
diff --git a/app/Issue/Tag.hs b/app/Issue/Tag.hs
index 2947ec9..8bbbba9 100644
--- a/app/Issue/Tag.hs
+++ b/app/Issue/Tag.hs
@@ -13,7 +13,7 @@ import Data.Text (Text, pack)
 import Data.Text qualified as T
 import Data.Time.Clock (UTCTime (utctDay))
 import GHC.Generics (Generic)
-import Issue.Provenance (Provenance (..), Commit(..))
+import Issue.Provenance (Commit (..), Provenance (..))
 
 data Tag = Tag Text (Maybe Text) deriving (Show, Generic, Binary, Eq)
 
@@ -46,7 +46,8 @@ internalTags title provenance' =
       maybe
         []
         ( \provenance ->
-            [ Tag "createdAt" $ Just $ pack $ show $ utctDay provenance.first.date
+            [ Tag "createdAt" $ Just $ pack $ show $ utctDay provenance.first.date,
+              Tag "modifiedAt" $ Just $ pack $ show $ utctDay provenance.last.date
             ]
         )
         provenance'
diff --git a/app/Main.hs b/app/Main.hs
index 28a32bb..3d71ebc 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -616,8 +616,10 @@ main = do
                     \I.Provenance {first} ->
                       ( keyword "by" <+> value (first.author.name <> " <" <> first.author.email <> ">")
                       )
-                  date' = fromProvenance $
+                  createdAt = fromProvenance $
                     \I.Provenance {first} -> keyword "on" <+> value (show (utctDay first.date))
+                  modifiedAt = fromProvenance $
+                    \I.Provenance {last = last'} -> keyword "modified" <+> value (show (utctDay last'.date))
 
                   fromProvenanceDef def = flip (maybe def) issue.provenance
                   fromProvenance = flip fmap issue.provenance
@@ -630,7 +632,8 @@ main = do
                       Just fileAndRow,
                       Just commit,
                       author,
-                      date'
+                      createdAt,
+                      modifiedAt
                     ]
           )
           issues
-- 
cgit v1.2.3