Introduce optional release title prefix
This commit is contained in:
parent
d98e20b164
commit
b2c60a0a6a
5 changed files with 15 additions and 3 deletions
|
@ -41,7 +41,7 @@ class App(
|
||||||
|
|
||||||
val existingReleases = releaseRepo.getExistingReleases(account.repo)
|
val existingReleases = releaseRepo.getExistingReleases(account.repo)
|
||||||
val feedService = FeedService(account.repo, httpClient)
|
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 publisher = publishers.forName(account.name)
|
||||||
val publishedReleases = publisher.sendReleases(newReleases)
|
val publishedReleases = publisher.sendReleases(newReleases)
|
||||||
releaseRepo.save(publishedReleases)
|
releaseRepo.save(publishedReleases)
|
||||||
|
|
|
@ -13,6 +13,7 @@ class Config(configInputStream: InputStream) {
|
||||||
data class Account(
|
data class Account(
|
||||||
private val accountName: String?,
|
private val accountName: String?,
|
||||||
private val github: String?,
|
private val github: String?,
|
||||||
|
val releasePrefix: String? = null,
|
||||||
private val mastodonInstance: String?,
|
private val mastodonInstance: String?,
|
||||||
private val mastodonAccessToken: String?,
|
private val mastodonAccessToken: String?,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -20,12 +20,13 @@ class FeedService(
|
||||||
httpClient = httpClient,
|
httpClient = httpClient,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun getNewReleases(existingReleases: Releases): Releases {
|
fun getNewReleases(existingReleases: Releases, releasePrefix: String): Releases {
|
||||||
log("Consuming releases feed for ${githubRepo.repoPath}")
|
log("Consuming releases feed for ${githubRepo.repoPath}")
|
||||||
|
|
||||||
val feedReader = syndication.create(FeedReader::class.java)
|
val feedReader = syndication.create(FeedReader::class.java)
|
||||||
return feedReader.readAtom()
|
return feedReader.readAtom()
|
||||||
.items
|
.items
|
||||||
|
?.filter { it.title.startsWith(releasePrefix) }
|
||||||
?.map {
|
?.map {
|
||||||
val created = OffsetDateTime.parse(it.lastUpdatedTime)
|
val created = OffsetDateTime.parse(it.lastUpdatedTime)
|
||||||
val link = it.links!!.first().href!!
|
val link = it.links!!.first().href!!
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package de.rpr.githubreleases.feed
|
package de.rpr.githubreleases.feed
|
||||||
|
|
||||||
import assertk.assertThat
|
import assertk.assertThat
|
||||||
|
import assertk.assertions.containsExactly
|
||||||
import assertk.assertions.doesNotContain
|
import assertk.assertions.doesNotContain
|
||||||
|
import assertk.assertions.hasSize
|
||||||
import de.rpr.githubreleases.model.GithubRepo
|
import de.rpr.githubreleases.model.GithubRepo
|
||||||
|
import de.rpr.githubreleases.model.Releases
|
||||||
import de.rpr.githubreleases.model.asCollection
|
import de.rpr.githubreleases.model.asCollection
|
||||||
import de.rpr.githubreleases.testRelease
|
import de.rpr.githubreleases.testRelease
|
||||||
import io.kotest.core.spec.style.DescribeSpec
|
import io.kotest.core.spec.style.DescribeSpec
|
||||||
|
@ -36,8 +39,14 @@ class FeedServiceTest : DescribeSpec({
|
||||||
|
|
||||||
it("should only return new releases") {
|
it("should only return new releases") {
|
||||||
val feedService = FeedService(GithubRepo("navidrome/navidrome"), httpClient)
|
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")
|
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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
|
@ -3,6 +3,7 @@
|
||||||
{
|
{
|
||||||
"accountName": "example",
|
"accountName": "example",
|
||||||
"github": "{githubUsername}/${githubRepoName}",
|
"github": "{githubUsername}/${githubRepoName}",
|
||||||
|
"releasePrefix": "{someTitlePrefix}",
|
||||||
"mastodonInstance": "{example.com}",
|
"mastodonInstance": "{example.com}",
|
||||||
"mastodonAccessToken": "{accessToken}"
|
"mastodonAccessToken": "{accessToken}"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue