1.1 --- a/src/main/kotlin/de/uapcore/lightpit/viewmodel/Issues.kt Sat Jul 22 15:07:23 2023 +0200 1.2 +++ b/src/main/kotlin/de/uapcore/lightpit/viewmodel/Issues.kt Sat Jul 22 22:32:04 2023 +0200 1.3 @@ -99,6 +99,8 @@ 1.4 } 1.5 } 1.6 1.7 +data class CommitLink(val url: String, val hash: String, val message: String) 1.8 + 1.9 class IssueDetailView( 1.10 val issue: Issue, 1.11 val comments: List<IssueComment>, 1.12 @@ -110,10 +112,12 @@ 1.13 /** 1.14 * Optional resource key to an error message for the relation editor. 1.15 */ 1.16 - val relationError: String? 1.17 + val relationError: String?, 1.18 + commitRefs: List<CommitRef> 1.19 ) : View() { 1.20 val relationTypes = RelationType.values() 1.21 val linkableIssues = projectIssues.filterNot { it.id == issue.id } 1.22 + val commitLinks: List<CommitLink> 1.23 1.24 private val parser: Parser 1.25 private val renderer: HtmlRenderer 1.26 @@ -131,8 +135,24 @@ 1.27 for (comment in comments) { 1.28 comment.commentFormatted = formatMarkdown(comment.comment) 1.29 } 1.30 + 1.31 + val commitBaseUrl = project.repoUrl 1.32 + commitLinks = (if (commitBaseUrl == null || project.vcs == VcsType.None) emptyList() else commitRefs.map { 1.33 + CommitLink(buildCommitUrl(commitBaseUrl, project.vcs, it.hash), it.hash, it.message) 1.34 + }) 1.35 } 1.36 1.37 + private fun buildCommitUrl(baseUrl: String, vcs: VcsType, hash: String): String = 1.38 + with (StringBuilder(baseUrl)) { 1.39 + if (!endsWith("/")) append('/') 1.40 + when (vcs) { 1.41 + VcsType.Mercurial -> append("rev/") 1.42 + else -> append("commit/") 1.43 + } 1.44 + append(hash) 1.45 + toString() 1.46 + } 1.47 + 1.48 private fun formatEmojis(text: String) = text 1.49 .replace("(/)", "✅") 1.50 .replace("(x)", "❌")