From b2c60a0a6abc895a0afa1dedffee9cd2cd1960e7 Mon Sep 17 00:00:00 2001 From: Ryan Harg Date: Mon, 8 Jul 2024 14:22:53 +0200 Subject: [PATCH] Introduce optional release title prefix --- app/src/main/kotlin/de/rpr/githubreleases/App.kt | 2 +- app/src/main/kotlin/de/rpr/githubreleases/Config.kt | 1 + .../kotlin/de/rpr/githubreleases/feed/FeedService.kt | 3 ++- .../de/rpr/githubreleases/feed/FeedServiceTest.kt | 11 ++++++++++- config.json.template | 1 + 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/de/rpr/githubreleases/App.kt b/app/src/main/kotlin/de/rpr/githubreleases/App.kt index 5a79501..8fdb8ed 100644 --- a/app/src/main/kotlin/de/rpr/githubreleases/App.kt +++ b/app/src/main/kotlin/de/rpr/githubreleases/App.kt @@ -41,7 +41,7 @@ class App( val existingReleases = releaseRepo.getExistingReleases(account.repo) val feedService = FeedService(account.repo, httpClient) - val newReleases = feedService.getNewReleases(existingReleases) + val newReleases = feedService.getNewReleases(existingReleases, account.releasePrefix ?: "") val publisher = publishers.forName(account.name) val publishedReleases = publisher.sendReleases(newReleases) releaseRepo.save(publishedReleases) diff --git a/app/src/main/kotlin/de/rpr/githubreleases/Config.kt b/app/src/main/kotlin/de/rpr/githubreleases/Config.kt index 6824ad2..b2cca34 100644 --- a/app/src/main/kotlin/de/rpr/githubreleases/Config.kt +++ b/app/src/main/kotlin/de/rpr/githubreleases/Config.kt @@ -13,6 +13,7 @@ class Config(configInputStream: InputStream) { data class Account( private val accountName: String?, private val github: String?, + val releasePrefix: String? = null, private val mastodonInstance: String?, private val mastodonAccessToken: String?, ) { diff --git a/app/src/main/kotlin/de/rpr/githubreleases/feed/FeedService.kt b/app/src/main/kotlin/de/rpr/githubreleases/feed/FeedService.kt index 26c29de..41fe97a 100644 --- a/app/src/main/kotlin/de/rpr/githubreleases/feed/FeedService.kt +++ b/app/src/main/kotlin/de/rpr/githubreleases/feed/FeedService.kt @@ -20,12 +20,13 @@ class FeedService( httpClient = httpClient, ) - fun getNewReleases(existingReleases: Releases): Releases { + fun getNewReleases(existingReleases: Releases, releasePrefix: String): Releases { log("Consuming releases feed for ${githubRepo.repoPath}") val feedReader = syndication.create(FeedReader::class.java) return feedReader.readAtom() .items + ?.filter { it.title.startsWith(releasePrefix) } ?.map { val created = OffsetDateTime.parse(it.lastUpdatedTime) val link = it.links!!.first().href!! diff --git a/app/src/test/kotlin/de/rpr/githubreleases/feed/FeedServiceTest.kt b/app/src/test/kotlin/de/rpr/githubreleases/feed/FeedServiceTest.kt index 669b936..d8f1095 100644 --- a/app/src/test/kotlin/de/rpr/githubreleases/feed/FeedServiceTest.kt +++ b/app/src/test/kotlin/de/rpr/githubreleases/feed/FeedServiceTest.kt @@ -1,8 +1,11 @@ package de.rpr.githubreleases.feed import assertk.assertThat +import assertk.assertions.containsExactly import assertk.assertions.doesNotContain +import assertk.assertions.hasSize import de.rpr.githubreleases.model.GithubRepo +import de.rpr.githubreleases.model.Releases import de.rpr.githubreleases.model.asCollection import de.rpr.githubreleases.testRelease import io.kotest.core.spec.style.DescribeSpec @@ -36,8 +39,14 @@ class FeedServiceTest : DescribeSpec({ it("should only return new releases") { val feedService = FeedService(GithubRepo("navidrome/navidrome"), httpClient) - val result = feedService.getNewReleases(testRelease.copy(id = "v0.50.2").asCollection()) + val result = feedService.getNewReleases(testRelease.copy(id = "v0.50.2").asCollection(),"") assertThat(result.map { it.id }).doesNotContain("v0.50.2") } + + it("should only return correctly prefixed new releases") { + val feedService = FeedService(GithubRepo("navidrome/navidrome"), httpClient) + val result = feedService.getNewReleases(Releases(),"v0.47") + assertThat(result.map { it.id }).containsExactly("v0.47.5") + } } }) \ No newline at end of file diff --git a/config.json.template b/config.json.template index aa9e277..b4fcb26 100644 --- a/config.json.template +++ b/config.json.template @@ -3,6 +3,7 @@ { "accountName": "example", "github": "{githubUsername}/${githubRepoName}", + "releasePrefix": "{someTitlePrefix}", "mastodonInstance": "{example.com}", "mastodonAccessToken": "{accessToken}" }