mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Better upload logic.
This commit is contained in:
parent
caa2a9424d
commit
5a7d730ac5
2 changed files with 30 additions and 42 deletions
|
@ -70,7 +70,7 @@ private class Main @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun run(jc: JCommander, args: Args, argv: Array<String>): Int {
|
public fun run(jc: JCommander, args: Args, argv: Array<String>): Int {
|
||||||
// github.uploadRelease()
|
// github.uploadRelease("kobalt", "0.101", File("/Users/beust/t/a.zip"))
|
||||||
|
|
||||||
//
|
//
|
||||||
// Add all the repos from repo contributors (at least those that return values without a Project)
|
// Add all the repos from repo contributors (at least those that return values without a Project)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.beust.kobalt.misc
|
package com.beust.kobalt.misc
|
||||||
|
|
||||||
import com.beust.kobalt.homeDir
|
|
||||||
import com.beust.kobalt.maven.KobaltException
|
import com.beust.kobalt.maven.KobaltException
|
||||||
|
import com.google.gson.Gson
|
||||||
import com.google.gson.JsonArray
|
import com.google.gson.JsonArray
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import com.google.gson.JsonParser
|
import com.google.gson.JsonParser
|
||||||
|
@ -36,44 +36,33 @@ public class GithubApi @Inject constructor(val executors: KobaltExecutors) {
|
||||||
const val RELEASES_URL = "https://api.github.com/repos/cbeust/kobalt/releases"
|
const val RELEASES_URL = "https://api.github.com/repos/cbeust/kobalt/releases"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun uploadRelease(): Int {
|
class RetrofitErrorResponse(val code: String?, val field: String?)
|
||||||
val releaseName = "0.100"
|
class RetrofitErrorsResponse(val message: String?, val errors: List<RetrofitErrorResponse>)
|
||||||
val release = service.getReleaseByTagName(Prop.username, "kobalt", releaseName)
|
|
||||||
|
|
||||||
uploadService.uploadRelease(Prop.username, Prop.accessToken, "kobalt", release.id!!, "zipFile", "label",
|
private fun parseRetrofitError(e: Throwable) : RetrofitErrorsResponse {
|
||||||
TypedFile("text/plain", File(homeDir("kotlin", "kobalt", "kobalt", "src", "Build.kt"))))
|
val re = e as RetrofitError
|
||||||
.subscribe(
|
val body = e.body
|
||||||
{ println("success") },
|
val json = String((re.response.body as TypedByteArray).bytes)
|
||||||
{ e: Throwable ->
|
return Gson().fromJson(json, RetrofitErrorsResponse::class.java)
|
||||||
println("error" + (e as RetrofitError).response.bodyContent())
|
}
|
||||||
println("")
|
|
||||||
},
|
fun uploadRelease(packageName: String, tagName: String, zipFile: File) {
|
||||||
{ println("complete") }
|
log(1, "Uploading release ${zipFile.name}")
|
||||||
)
|
try {
|
||||||
println("createRelease()")
|
service.createRelease(Prop.username, Prop.accessToken, packageName, CreateRelease(tagName))
|
||||||
// service.createRelease(username, accessToken, "kobalt",
|
.flatMap { response ->
|
||||||
//// hashMapOf("tag_name" to "0.502tagName")
|
uploadService.uploadAsset(Prop.username, Prop.accessToken,
|
||||||
// CreateRelease(releaseName)
|
packageName, response.id!!, zipFile.name, TypedFile("application/zip", zipFile))
|
||||||
//// CreateRelease().apply { tag_name = "0.500tagName"}
|
}
|
||||||
//// CreateRelease("0.500tagName",
|
.toBlocking()
|
||||||
//// "master", "0.500name",
|
.forEach { action ->
|
||||||
//// "A test release",
|
log(1, "Release successfully uploaded ${zipFile.name}")
|
||||||
//// draft = false, prerelease = true)
|
}
|
||||||
// )
|
} catch(e: RetrofitError) {
|
||||||
// .map { response: CreateReleaseResponse? ->
|
val error = parseRetrofitError(e)
|
||||||
// uploadRelease(response?.id!!)
|
throw KobaltException("Couldn't upload release, ${error.message}: "
|
||||||
// println("Received id " + response?.id)
|
+ error.errors[0].code + " field: " + error.errors[0].field)
|
||||||
// }
|
}
|
||||||
// .subscribe(
|
|
||||||
// { println("success") },
|
|
||||||
// { e: Throwable ->
|
|
||||||
// println("error" + (e as RetrofitError).response.bodyContent())
|
|
||||||
// },
|
|
||||||
// { println("complete")}
|
|
||||||
// )
|
|
||||||
//// })
|
|
||||||
Thread.sleep(10000)
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -125,16 +114,15 @@ public class GithubApi @Inject constructor(val executors: KobaltExecutors) {
|
||||||
.build()
|
.build()
|
||||||
.create(UploadApi::class.java)
|
.create(UploadApi::class.java)
|
||||||
|
|
||||||
class UploadReleaseResponse(var id: String? = null)
|
class UploadReleaseResponse(var id: String? = null, val name: String? = null)
|
||||||
|
|
||||||
interface UploadApi {
|
interface UploadApi {
|
||||||
@POST("/repos/{owner}/{repo}/releases/{id}/assets")
|
@POST("/repos/{owner}/{repo}/releases/{id}/assets")
|
||||||
fun uploadRelease(@Path("owner") owner: String,
|
fun uploadAsset(@Path("owner") owner: String,
|
||||||
@Query("access_token") accessToken: String,
|
@Query("access_token") accessToken: String,
|
||||||
@Path("repo") repo: String,
|
@Path("repo") repo: String,
|
||||||
@Path("id") id: String,
|
@Path("id") id: String,
|
||||||
@Query("name") name: String,
|
@Query("name") name: String,
|
||||||
@Query("label") label: String,
|
|
||||||
@Body file: TypedFile)
|
@Body file: TypedFile)
|
||||||
// @Query("Content-Type") contentType: String = "text/plain")//"application/zip")
|
// @Query("Content-Type") contentType: String = "text/plain")//"application/zip")
|
||||||
: Observable<UploadReleaseResponse>
|
: Observable<UploadReleaseResponse>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue