From e3cef3c004917931b1b45e9e933d46ba0d07917e Mon Sep 17 00:00:00 2001 From: Ryan Harg Date: Tue, 13 Feb 2024 10:01:46 +0100 Subject: [PATCH] Make release posts generic --- .../de/rpr/githubreleases/model/GithubRepo.kt | 15 ++++++++++----- .../de/rpr/githubreleases/model/Releases.kt | 2 +- .../githubreleases/publishing/PublishersTest.kt | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/de/rpr/githubreleases/model/GithubRepo.kt b/app/src/main/kotlin/de/rpr/githubreleases/model/GithubRepo.kt index e416ecb..ad705e9 100644 --- a/app/src/main/kotlin/de/rpr/githubreleases/model/GithubRepo.kt +++ b/app/src/main/kotlin/de/rpr/githubreleases/model/GithubRepo.kt @@ -4,12 +4,17 @@ data class GithubRepo(private val repositoryPath: String) { private val urlPrefix = "https://github.com/" + val repoPath: String val name: String - get() { - val usernameEnd = repoPath.indexOf("/") - return repoPath.substring(usernameEnd + 1).trimEnd { ch -> ch == '/' } - } - val repoPath: String = repoPath(repositoryPath) + + init { + repoPath = repoPath(repositoryPath) + + val usernameEnd = repoPath.indexOf("/") + name = repoPath.substring(usernameEnd + 1).trimEnd { ch -> ch == '/' } + } + + val capitalizedName = name.replaceFirstChar { it.uppercase() } val url = urlPrefix + repoPath diff --git a/app/src/main/kotlin/de/rpr/githubreleases/model/Releases.kt b/app/src/main/kotlin/de/rpr/githubreleases/model/Releases.kt index cf18ac2..67b75eb 100644 --- a/app/src/main/kotlin/de/rpr/githubreleases/model/Releases.kt +++ b/app/src/main/kotlin/de/rpr/githubreleases/model/Releases.kt @@ -10,7 +10,7 @@ data class Release( ) { val title: String get() = id val text: String = - "\uD83C\uDF89 Navidrome $title has been published!\n\nRelease notes are available here: $link\n\n#Navidrome" + "\uD83C\uDF89 ${githubRepo.capitalizedName} $title has been published!\n\nRelease notes are available here: $link\n\n#${githubRepo.capitalizedName}" } fun Release.asCollection() = listOf(this).asCollection() diff --git a/app/src/test/kotlin/de/rpr/githubreleases/publishing/PublishersTest.kt b/app/src/test/kotlin/de/rpr/githubreleases/publishing/PublishersTest.kt index 05cfbbf..a4c5f03 100644 --- a/app/src/test/kotlin/de/rpr/githubreleases/publishing/PublishersTest.kt +++ b/app/src/test/kotlin/de/rpr/githubreleases/publishing/PublishersTest.kt @@ -109,7 +109,7 @@ class PublishersTest : DescribeSpec({ ) } - assertThat(statusSlot.captured).isEqualTo("\uD83C\uDF89 Navidrome v0.0.0 has been published!\n\nRelease notes are available here: https://example.com\n\n#Navidrome") + assertThat(statusSlot.captured).isEqualTo("\uD83C\uDF89 Example v0.0.0 has been published!\n\nRelease notes are available here: https://example.com\n\n#Example") } }