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.
|
||||
application
|
||||
id("com.google.cloud.tools.jib") version "3.4.0"
|
||||
id("com.google.cloud.tools.jib") version "3.4.1"
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
|
|
@ -9,11 +9,8 @@ import java.util.concurrent.Executors
|
|||
import java.util.concurrent.TimeUnit
|
||||
|
||||
fun main() {
|
||||
App::class.java.classLoader.getResource("logo.txt")?.readText()!!.split("\n")
|
||||
.forEach {
|
||||
log(it)
|
||||
}
|
||||
log("github-release-bot starting up")
|
||||
logo("github-release-bot")
|
||||
|
||||
val config = Config()
|
||||
val mastodonClientFactory = MastodonClientFactory()
|
||||
val publishers = Publishers(config, mastodonClientFactory)
|
||||
|
@ -26,9 +23,8 @@ class App(
|
|||
private val config: Config,
|
||||
private val releaseRepo: ReleaseRepository,
|
||||
private val httpClient: OkHttpClient,
|
||||
private val publishers: Publishers
|
||||
private val publishers: Publishers,
|
||||
) {
|
||||
|
||||
init {
|
||||
log(config.toString())
|
||||
}
|
||||
|
@ -42,14 +38,15 @@ class App(
|
|||
private fun execute() {
|
||||
config.accounts.forEach { account ->
|
||||
log("Processing releases feed for ${account.repo.name}...")
|
||||
|
||||
val existingReleases = releaseRepo.getExistingReleases(account.repo)
|
||||
val feedService = FeedService(account.repo, httpClient)
|
||||
val newReleases = feedService.getNewReleases(existingReleases)
|
||||
val publisher = publishers.forName(account.name)
|
||||
val publishedReleases = publisher.sendReleases(newReleases)
|
||||
releaseRepo.save(publishedReleases)
|
||||
|
||||
log("Finished feed processing...")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,4 +4,13 @@ import java.io.File
|
|||
import java.nio.file.Path
|
||||
|
||||
fun String.toFile(): File = File(this)
|
||||
|
||||
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
|
||||
|
||||
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.Release
|
||||
import de.rpr.githubreleases.model.Releases
|
||||
import de.rpr.githubreleases.model.asCollection
|
||||
import de.rpr.terminenbg.LocalDateTimeAdapter
|
||||
import okhttp3.OkHttpClient
|
||||
import java.time.LocalDateTime
|
||||
import java.time.OffsetDateTime
|
||||
import java.time.ZoneId
|
||||
|
||||
class FeedService(
|
||||
private val githubRepo: GithubRepo,
|
||||
httpClient: OkHttpClient
|
||||
httpClient: OkHttpClient,
|
||||
) {
|
||||
private val syndication: Syndication = Syndication(
|
||||
private val syndication: Syndication =
|
||||
Syndication(
|
||||
url = "${githubRepo.url}/releases.atom",
|
||||
httpClient = httpClient
|
||||
httpClient = httpClient,
|
||||
)
|
||||
|
||||
fun getNewReleases(existingReleases: Releases): Releases {
|
||||
|
@ -28,14 +27,13 @@ class FeedService(
|
|||
return feedReader.readAtom()
|
||||
.items
|
||||
?.map {
|
||||
|
||||
val created = OffsetDateTime.parse(it.lastUpdatedTime)
|
||||
val link = it.links!!.first().href!!
|
||||
Release(
|
||||
id = it.title,
|
||||
link = link,
|
||||
created = created.atZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime(),
|
||||
githubRepo = githubRepo
|
||||
githubRepo = githubRepo,
|
||||
)
|
||||
}
|
||||
?.filter { !existingReleases.contains(it) }
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
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 val repoPath: String
|
||||
|
||||
@Transient val name: String
|
||||
|
||||
init {
|
||||
|
@ -18,8 +20,9 @@ data class GithubRepo(@Transient private val repositoryPath: String) {
|
|||
|
||||
val url = urlPrefix + repoPath
|
||||
|
||||
private fun repoPath(repositoryPath: String) = if (repositoryPath.startsWith(urlPrefix)) {
|
||||
repositoryPath.substring(19)
|
||||
private fun repoPath(repositoryPath: String) =
|
||||
if (repositoryPath.startsWith(urlPrefix)) {
|
||||
repositoryPath.substring(urlPrefix.length)
|
||||
} else {
|
||||
repositoryPath
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue