Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ buildscript {

dependencies {
// ...
classpath 'com.appswithlove.updraft:updraft:3.0.0'
classpath 'com.appswithlove.updraft:updraft:3.0.1'
}
}
```
Expand All @@ -37,7 +37,7 @@ or

```kotlin
plugins {
id("com.appswithlove.updraft") version "3.0.0"
id("com.appswithlove.updraft") version "3.0.1"
}
```

Expand Down Expand Up @@ -125,7 +125,7 @@ buildscript {
// ...
}
dependencies {
classpath 'com.appswithlove.updraft:updraft:3.0.0'
classpath 'com.appswithlove.updraft:updraft:3.0.1'
// ...
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

GROUP=com.appswithlove.updraft
POM_ARTIFACT_ID=updraft
VERSION_NAME=3.0.0
VERSION_NAME=3.0.1

POM_NAME=updraft-plugin-android
POM_DESCRIPTION=This is a gradle Android plugin for automated uploads to Updraft
Expand Down
64 changes: 38 additions & 26 deletions lib/src/main/kotlin/com/appswithlove/updraft/UpdraftTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,37 +78,49 @@ abstract class UpdraftTask : DefaultTask() {
it.standardOutput = os
}

val execResponse = JsonSlurperClassic().parseText(os.toString())

if (execResponse is Map<*, *> && execResponse.isNotEmpty()) {
when {
execResponse["success"] == "ok" -> {
val publicUrl = execResponse["public_link"]
println("\n--------------------------------------")
println("Your App was successfully updrafted!")
if (publicUrl != null) println("Get it here -> $publicUrl")
println("--------------------------------------")
}

execResponse["detail"] == "Not found." -> {
throw GradleException("Could not updraft to the given url. Please recheck that.")
}

else -> {
throw GradleException(os.toString())
}
}
} else {
println(execResponse)
println("\n--------------------------------------")
println("Your App was successfully updrafted!")
println("--------------------------------------")
}
handleResponse(os.toString())
}
}
}

companion object {
internal fun handleResponse(response: String) {
val execResponse = JsonSlurperClassic().parseText(response)

if (execResponse is Map<*, *> && execResponse.isNotEmpty()) {
when {
execResponse["success"] == "ok" -> {
val publicUrl = execResponse["public_link"]
println("\n--------------------------------------")
println("Your App was successfully updrafted!")
if (publicUrl != null) println("Get it here -> $publicUrl")
println("--------------------------------------")
}

// App bundles (AAB) are processed asynchronously: Updraft accepts the upload and returns a task id
execResponse["task_id"] != null -> {
println("\n--------------------------------------")
println("Your App was uploaded to Updraft and is being processed.")
execResponse["task_upload_description"]?.let { println(it) }
println("--------------------------------------")
}

execResponse["detail"] == "Not found." -> {
throw GradleException("Could not updraft to the given url. Please recheck that.")
}

else -> {
throw GradleException(response)
}
}
} else {
println(execResponse)
println("\n--------------------------------------")
println("Your App was successfully updrafted!")
println("--------------------------------------")
}
}

internal fun createCurlParam(text: String?, name: String): String {
return if (text.isNullOrBlank()) "" else "-F $name=$text"
}
Expand Down
31 changes: 31 additions & 0 deletions lib/src/test/kotlin/com/appswithlove/updraft/HandleResponseTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.appswithlove.updraft

import org.gradle.api.GradleException
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertDoesNotThrow
import org.junit.jupiter.api.assertThrows

class HandleResponseTest {

@Test
fun handleResponse_withSuccessOk_succeeds() {
assertDoesNotThrow { UpdraftTask.handleResponse("""{"success":"ok","public_link":"https://example.com"}""") }
}

@Test
fun handleResponse_withTaskId_succeeds() {
assertDoesNotThrow {
UpdraftTask.handleResponse("""{"task_id":"b0e7","task_upload_description":"You can check the results of the build processing at the link: https://example.com/b0e7/"}""")
}
}

@Test
fun handleResponse_withNotFound_throws() {
assertThrows<GradleException> { UpdraftTask.handleResponse("""{"detail":"Not found."}""") }
}

@Test
fun handleResponse_withUnknownResponse_throws() {
assertThrows<GradleException> { UpdraftTask.handleResponse("""{"error":"invalid app"}""") }
}
}
Loading