1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Fallback for getReleases() if no auth.

This commit is contained in:
Cedric Beust 2015-12-16 00:50:47 +04:00
parent e023dabf4e
commit a599d0699b
2 changed files with 16 additions and 5 deletions

View file

@ -108,6 +108,10 @@ public class GithubApi @Inject constructor(val executors: KobaltExecutors,
fun getReleases(@Path("owner") owner: String, fun getReleases(@Path("owner") owner: String,
@Query("access_token") accessToken: String, @Query("access_token") accessToken: String,
@Path("repo") repo: String): List<ReleasesResponse> @Path("repo") repo: String): List<ReleasesResponse>
@GET("/repos/{owner}/{repo}/releases")
fun getReleasesNoAuth(@Path("owner") owner: String,
@Path("repo") repo: String): List<ReleasesResponse>
} }
val latestKobaltVersion: Future<String> val latestKobaltVersion: Future<String>
@ -115,10 +119,15 @@ public class GithubApi @Inject constructor(val executors: KobaltExecutors,
val callable = Callable<String> { val callable = Callable<String> {
var result = "0" var result = "0"
val username = localProperties.get(PROPERTY_USERNAME, DOC_URL) val username = localProperties.getNoThrows(PROPERTY_USERNAME, DOC_URL)
val accessToken = localProperties.get(PROPERTY_ACCESS_TOKEN, DOC_URL) val accessToken = localProperties.getNoThrows(PROPERTY_ACCESS_TOKEN, DOC_URL)
try { try {
val releases = service.getReleases(username, accessToken, "kobalt") val releases =
if (username != null && accessToken != null) {
service.getReleases(username, accessToken, "kobalt")
} else {
service.getReleasesNoAuth("cbeust", "kobalt")
}
releases.firstOrNull()?.let { releases.firstOrNull()?.let {
try { try {
result = listOf(it.name, it.tagName).filterNotNull().first { !it.isBlank() } result = listOf(it.name, it.tagName).filterNotNull().first { !it.isBlank() }

View file

@ -12,7 +12,7 @@ class LocalProperties {
val result = Properties() val result = Properties()
val filePath = Paths.get("local.properties") val filePath = Paths.get("local.properties")
filePath.let { path -> filePath.let { path ->
if (Files.exists(path)) { if (path.toFile().exists()) {
Files.newInputStream(path).use { Files.newInputStream(path).use {
result.load(it) result.load(it)
} }
@ -22,8 +22,10 @@ class LocalProperties {
result result
} }
fun getNoThrows(name: String, docUrl: String? = null) = localProperties.getProperty(name)
fun get(name: String, docUrl: String? = null) : String { fun get(name: String, docUrl: String? = null) : String {
val result = localProperties.getProperty(name) val result = getNoThrows(name, docUrl)
?: throw KobaltException("Couldn't find $name in local.properties", docUrl = docUrl) ?: throw KobaltException("Couldn't find $name in local.properties", docUrl = docUrl)
return result as String return result as String
} }