Introduce optional release title prefix

This commit is contained in:
Ryan Harg 2024-07-08 14:22:53 +02:00
parent d98e20b164
commit b2c60a0a6a
5 changed files with 15 additions and 3 deletions

View file

@ -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)

View file

@ -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?,
) {

View file

@ -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!!

View file

@ -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")
}
}
})

View file

@ -3,6 +3,7 @@
{
"accountName": "example",
"github": "{githubUsername}/${githubRepoName}",
"releasePrefix": "{someTitlePrefix}",
"mastodonInstance": "{example.com}",
"mastodonAccessToken": "{accessToken}"
}