mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Simplify.
This commit is contained in:
parent
d0349d44ce
commit
8fef0a5700
1 changed files with 12 additions and 14 deletions
|
@ -15,6 +15,7 @@ import retrofit.mime.TypedByteArray
|
||||||
import retrofit.mime.TypedFile
|
import retrofit.mime.TypedFile
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.*
|
||||||
import java.util.concurrent.Callable
|
import java.util.concurrent.Callable
|
||||||
import java.util.concurrent.Future
|
import java.util.concurrent.Future
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -25,7 +26,6 @@ import javax.inject.Inject
|
||||||
public class GithubApi @Inject constructor(val executors: KobaltExecutors,
|
public class GithubApi @Inject constructor(val executors: KobaltExecutors,
|
||||||
val localProperties: LocalProperties, val http: Http) {
|
val localProperties: LocalProperties, val http: Http) {
|
||||||
companion object {
|
companion object {
|
||||||
const val RELEASES_URL = "https://api.github.com/repos/cbeust/kobalt/releases"
|
|
||||||
const val PROPERTY_ACCESS_TOKEN = "github.accessToken"
|
const val PROPERTY_ACCESS_TOKEN = "github.accessToken"
|
||||||
const val PROPERTY_USERNAME = "github.username"
|
const val PROPERTY_USERNAME = "github.username"
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ public class GithubApi @Inject constructor(val executors: KobaltExecutors,
|
||||||
class RetrofitErrorResponse(val code: String?, val field: String?)
|
class RetrofitErrorResponse(val code: String?, val field: String?)
|
||||||
class RetrofitErrorsResponse(val message: String?, val errors: List<RetrofitErrorResponse>)
|
class RetrofitErrorsResponse(val message: String?, val errors: List<RetrofitErrorResponse>)
|
||||||
|
|
||||||
private val docUrl = DocUrl.PUBLISH_PLUGIN_URL
|
private val DOC_URL = DocUrl.PUBLISH_PLUGIN_URL
|
||||||
|
|
||||||
private fun parseRetrofitError(e: Throwable) : RetrofitErrorsResponse {
|
private fun parseRetrofitError(e: Throwable) : RetrofitErrorsResponse {
|
||||||
val re = e as RetrofitError
|
val re = e as RetrofitError
|
||||||
|
@ -44,8 +44,8 @@ public class GithubApi @Inject constructor(val executors: KobaltExecutors,
|
||||||
fun uploadRelease(packageName: String, tagName: String, zipFile: File) {
|
fun uploadRelease(packageName: String, tagName: String, zipFile: File) {
|
||||||
log(1, "Uploading release ${zipFile.name}")
|
log(1, "Uploading release ${zipFile.name}")
|
||||||
|
|
||||||
val username = localProperties.get(PROPERTY_USERNAME, docUrl)
|
val username = localProperties.get(PROPERTY_USERNAME, DOC_URL)
|
||||||
val accessToken = localProperties.get(PROPERTY_ACCESS_TOKEN, docUrl)
|
val accessToken = localProperties.get(PROPERTY_ACCESS_TOKEN, DOC_URL)
|
||||||
try {
|
try {
|
||||||
service.createRelease(username, accessToken, packageName, CreateRelease(tagName))
|
service.createRelease(username, accessToken, packageName, CreateRelease(tagName))
|
||||||
.flatMap { response ->
|
.flatMap { response ->
|
||||||
|
@ -115,22 +115,20 @@ 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, docUrl)
|
val username = localProperties.get(PROPERTY_USERNAME, DOC_URL)
|
||||||
val accessToken = localProperties.get(PROPERTY_ACCESS_TOKEN, docUrl)
|
val accessToken = localProperties.get(PROPERTY_ACCESS_TOKEN, DOC_URL)
|
||||||
try {
|
try {
|
||||||
val releases = service.getReleases(username, accessToken, "kobalt")
|
val releases = service.getReleases(username, accessToken, "kobalt")
|
||||||
if (releases.size > 0) {
|
releases.firstOrNull()?.let {
|
||||||
var versionName = releases[0].name
|
try {
|
||||||
if (versionName == null || versionName.isBlank()) {
|
result = listOf(it.name, it.tagName).filterNotNull().first { !it.isBlank() }
|
||||||
versionName = releases[0].tagName
|
} catch(ex: NoSuchElementException) {
|
||||||
if (versionName != null && !versionName.isBlank()) {
|
throw KobaltException("Couldn't find the latest release")
|
||||||
result = versionName
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(e: RetrofitError) {
|
} catch(e: RetrofitError) {
|
||||||
val error = parseRetrofitError(e)
|
val error = parseRetrofitError(e)
|
||||||
throw KobaltException("Couldn't upload release, ${error.message}: "
|
throw KobaltException("Couldn't retrieve releases, ${error.message}: "
|
||||||
+ error.errors[0].code + " field: " + error.errors[0].field)
|
+ error.errors[0].code + " field: " + error.errors[0].field)
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue