add diffs to RSS feed

Sun, 10 Oct 2021 14:46:10 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 10 Oct 2021 14:46:10 +0200
changeset 236
819c5178b6fe
parent 235
4258b9e010ae
child 237
84e42725bf8e

add diffs to RSS feed

build.gradle.kts file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/servlet/FeedServlet.kt file | annotate | diff | comparison | revisions
--- a/build.gradle.kts	Sat Oct 09 20:05:39 2021 +0200
+++ b/build.gradle.kts	Sun Oct 10 14:46:10 2021 +0200
@@ -43,6 +43,7 @@
                 implementation("com.vladsch.flexmark:flexmark-util-data:${flexmarkVersion}")
                 implementation("com.vladsch.flexmark:flexmark-ext-tables:${flexmarkVersion}")
                 implementation("com.vladsch.flexmark:flexmark-ext-gfm-strikethrough:${flexmarkVersion}")
+                implementation("io.github.java-diff-utils:java-diff-utils:4.5")
             }
         }
     }
--- a/src/main/kotlin/de/uapcore/lightpit/servlet/FeedServlet.kt	Sat Oct 09 20:05:39 2021 +0200
+++ b/src/main/kotlin/de/uapcore/lightpit/servlet/FeedServlet.kt	Sun Oct 10 14:46:10 2021 +0200
@@ -25,6 +25,8 @@
 
 package de.uapcore.lightpit.servlet
 
+import com.github.difflib.text.DiffRow
+import com.github.difflib.text.DiffRowGenerator
 import de.uapcore.lightpit.AbstractServlet
 import de.uapcore.lightpit.HttpRequest
 import de.uapcore.lightpit.dao.DataAccessObject
@@ -36,6 +38,7 @@
 import java.text.SimpleDateFormat
 import javax.servlet.annotation.WebServlet
 
+
 @WebServlet(urlPatterns = ["/feed/*"])
 class FeedServlet : AbstractServlet() {
 
@@ -43,8 +46,6 @@
         get("/%project/issues.rss", this::issues)
     }
 
-    private fun String.convertLF() = replace("\r", "").replace("\n", "<br>")
-
     private fun fullContent(issue: IssueHistoryData) = IssueDiff(
         issue.id,
         issue.subject,
@@ -52,7 +53,7 @@
         issue.status.name,
         issue.category.name,
         issue.subject,
-        issue.description.convertLF(),
+        issue.description.replace("\r", ""),
         issue.assignee,
         issue.eta?.let { SimpleDateFormat("dd.MM.yyyy").format(it) } ?: "",
         issue.affected,
@@ -60,9 +61,38 @@
     )
 
     private fun diffContent(cur: IssueHistoryData, next: IssueHistoryData): IssueDiff {
+        val generator = DiffRowGenerator.create()
+            .showInlineDiffs(true)
+            .mergeOriginalRevised(true)
+            .inlineDiffByWord(true)
+            .oldTag { start -> if (start) "<strike style=\"color:red\">" else "</strike>" }
+            .newTag { start -> if (start) "<i style=\"color: green\">" else "</i>" }
+            .build()
+
         val prev = fullContent(next)
         val diff = fullContent(cur)
-        // TODO: compute and apply diff
+
+        val result = generator.generateDiffRows(
+            listOf(prev.subject, prev.component, prev.status,
+                prev.category, prev.assignee, prev.eta, prev.affected, prev.resolved),
+            listOf(diff.subject, diff.component, diff.status,
+                diff.category, diff.assignee, diff.eta, diff.affected, diff.resolved)
+        )
+
+        diff.subject = result[0].oldLine
+        diff.component = result[1].oldLine
+        diff.status = result[2].oldLine
+        diff.category = result[3].oldLine
+        diff.assignee = result[4].oldLine
+        diff.eta = result[5].oldLine
+        diff.affected = result[6].oldLine
+        diff.resolved = result[7].oldLine
+
+        diff.description = generator.generateDiffRows(
+            prev.description.split('\n'),
+            diff.description.split('\n')
+        ).joinToString("<br>", transform = DiffRow::getOldLine)
+
         return diff
     }
 

mercurial