src/main/kotlin/de/uapcore/lightpit/viewmodel/Issues.kt

changeset 284
671c1c8fbf1c
parent 271
f8f5e82944fa
child 291
bcf05cccac6f
--- a/src/main/kotlin/de/uapcore/lightpit/viewmodel/Issues.kt	Sat Jul 22 15:07:23 2023 +0200
+++ b/src/main/kotlin/de/uapcore/lightpit/viewmodel/Issues.kt	Sat Jul 22 22:32:04 2023 +0200
@@ -99,6 +99,8 @@
     }
 }
 
+data class CommitLink(val url: String, val hash: String, val message: String)
+
 class IssueDetailView(
     val issue: Issue,
     val comments: List<IssueComment>,
@@ -110,10 +112,12 @@
     /**
      * Optional resource key to an error message for the relation editor.
      */
-    val relationError: String?
+    val relationError: String?,
+    commitRefs: List<CommitRef>
 ) : View() {
     val relationTypes = RelationType.values()
     val linkableIssues = projectIssues.filterNot { it.id == issue.id }
+    val commitLinks: List<CommitLink>
 
     private val parser: Parser
     private val renderer: HtmlRenderer
@@ -131,8 +135,24 @@
         for (comment in comments) {
             comment.commentFormatted = formatMarkdown(comment.comment)
         }
+
+        val commitBaseUrl = project.repoUrl
+        commitLinks = (if (commitBaseUrl == null || project.vcs == VcsType.None) emptyList() else commitRefs.map {
+            CommitLink(buildCommitUrl(commitBaseUrl, project.vcs, it.hash), it.hash, it.message)
+        })
     }
 
+    private fun buildCommitUrl(baseUrl: String, vcs: VcsType, hash: String): String =
+        with (StringBuilder(baseUrl)) {
+            if (!endsWith("/")) append('/')
+            when (vcs) {
+                VcsType.Mercurial -> append("rev/")
+                else -> append("commit/")
+            }
+            append(hash)
+            toString()
+        }
+
     private fun formatEmojis(text: String) = text
         .replace("(/)", "&#9989;")
         .replace("(x)", "&#10060;")

mercurial