Minor improvements
This commit is contained in:
parent
5e446b84a0
commit
26ddd41345
5 changed files with 35 additions and 28 deletions
|
@ -15,7 +15,7 @@ plugins {
|
||||||
|
|
||||||
// Apply the application plugin to add support for building a CLI application in Java.
|
// Apply the application plugin to add support for building a CLI application in Java.
|
||||||
application
|
application
|
||||||
id("com.google.cloud.tools.jib") version "3.4.0"
|
id("com.google.cloud.tools.jib") version "3.4.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
|
|
@ -9,11 +9,8 @@ import java.util.concurrent.Executors
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
App::class.java.classLoader.getResource("logo.txt")?.readText()!!.split("\n")
|
logo("github-release-bot")
|
||||||
.forEach {
|
|
||||||
log(it)
|
|
||||||
}
|
|
||||||
log("github-release-bot starting up")
|
|
||||||
val config = Config()
|
val config = Config()
|
||||||
val mastodonClientFactory = MastodonClientFactory()
|
val mastodonClientFactory = MastodonClientFactory()
|
||||||
val publishers = Publishers(config, mastodonClientFactory)
|
val publishers = Publishers(config, mastodonClientFactory)
|
||||||
|
@ -26,9 +23,8 @@ class App(
|
||||||
private val config: Config,
|
private val config: Config,
|
||||||
private val releaseRepo: ReleaseRepository,
|
private val releaseRepo: ReleaseRepository,
|
||||||
private val httpClient: OkHttpClient,
|
private val httpClient: OkHttpClient,
|
||||||
private val publishers: Publishers
|
private val publishers: Publishers,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
log(config.toString())
|
log(config.toString())
|
||||||
}
|
}
|
||||||
|
@ -42,14 +38,15 @@ class App(
|
||||||
private fun execute() {
|
private fun execute() {
|
||||||
config.accounts.forEach { account ->
|
config.accounts.forEach { account ->
|
||||||
log("Processing releases feed for ${account.repo.name}...")
|
log("Processing releases feed for ${account.repo.name}...")
|
||||||
|
|
||||||
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)
|
||||||
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)
|
||||||
|
|
||||||
log("Finished feed processing...")
|
log("Finished feed processing...")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,4 +4,13 @@ import java.io.File
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
|
||||||
fun String.toFile(): File = File(this)
|
fun String.toFile(): File = File(this)
|
||||||
|
|
||||||
fun String.toPath(): Path = this.toFile().toPath()
|
fun String.toPath(): Path = this.toFile().toPath()
|
||||||
|
|
||||||
|
fun logo(applicationName: String) {
|
||||||
|
object {}::class.java.classLoader.getResource("logo.txt")?.readText()!!.split("\n")
|
||||||
|
.forEach {
|
||||||
|
log(it)
|
||||||
|
}
|
||||||
|
log("$applicationName starting up")
|
||||||
|
}
|
||||||
|
|
|
@ -1,24 +1,23 @@
|
||||||
package de.rpr.githubreleases.feed
|
package de.rpr.githubreleases.feed
|
||||||
|
|
||||||
import com.ouattararomuald.syndication.Syndication
|
import com.ouattararomuald.syndication.Syndication
|
||||||
import de.rpr.githubreleases.*
|
import de.rpr.githubreleases.log
|
||||||
import de.rpr.githubreleases.model.GithubRepo
|
import de.rpr.githubreleases.model.GithubRepo
|
||||||
import de.rpr.githubreleases.model.Release
|
import de.rpr.githubreleases.model.Release
|
||||||
import de.rpr.githubreleases.model.Releases
|
import de.rpr.githubreleases.model.Releases
|
||||||
import de.rpr.githubreleases.model.asCollection
|
import de.rpr.githubreleases.model.asCollection
|
||||||
import de.rpr.terminenbg.LocalDateTimeAdapter
|
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import java.time.LocalDateTime
|
|
||||||
import java.time.OffsetDateTime
|
import java.time.OffsetDateTime
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
|
|
||||||
class FeedService(
|
class FeedService(
|
||||||
private val githubRepo: GithubRepo,
|
private val githubRepo: GithubRepo,
|
||||||
httpClient: OkHttpClient
|
httpClient: OkHttpClient,
|
||||||
) {
|
) {
|
||||||
private val syndication: Syndication = Syndication(
|
private val syndication: Syndication =
|
||||||
|
Syndication(
|
||||||
url = "${githubRepo.url}/releases.atom",
|
url = "${githubRepo.url}/releases.atom",
|
||||||
httpClient = httpClient
|
httpClient = httpClient,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun getNewReleases(existingReleases: Releases): Releases {
|
fun getNewReleases(existingReleases: Releases): Releases {
|
||||||
|
@ -28,14 +27,13 @@ class FeedService(
|
||||||
return feedReader.readAtom()
|
return feedReader.readAtom()
|
||||||
.items
|
.items
|
||||||
?.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!!
|
||||||
Release(
|
Release(
|
||||||
id = it.title,
|
id = it.title,
|
||||||
link = link,
|
link = link,
|
||||||
created = created.atZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(),
|
created = created.atZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(),
|
||||||
githubRepo = githubRepo
|
githubRepo = githubRepo,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
?.filter { !existingReleases.contains(it) }
|
?.filter { !existingReleases.contains(it) }
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package de.rpr.githubreleases.model
|
package de.rpr.githubreleases.model
|
||||||
|
|
||||||
data class GithubRepo(@Transient private val repositoryPath: String) {
|
data class GithubRepo(
|
||||||
|
@Transient private val repositoryPath: String,
|
||||||
|
) {
|
||||||
@Transient private val urlPrefix = "https://github.com/"
|
@Transient private val urlPrefix = "https://github.com/"
|
||||||
|
|
||||||
@Transient val repoPath: String
|
@Transient val repoPath: String
|
||||||
|
|
||||||
@Transient val name: String
|
@Transient val name: String
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
@ -18,8 +20,9 @@ data class GithubRepo(@Transient private val repositoryPath: String) {
|
||||||
|
|
||||||
val url = urlPrefix + repoPath
|
val url = urlPrefix + repoPath
|
||||||
|
|
||||||
private fun repoPath(repositoryPath: String) = if (repositoryPath.startsWith(urlPrefix)) {
|
private fun repoPath(repositoryPath: String) =
|
||||||
repositoryPath.substring(19)
|
if (repositoryPath.startsWith(urlPrefix)) {
|
||||||
|
repositoryPath.substring(urlPrefix.length)
|
||||||
} else {
|
} else {
|
||||||
repositoryPath
|
repositoryPath
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue