diff --git a/README.md b/README.md index 5e1e8af..c2a6e0b 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ buildscript { dependencies { // ... - classpath 'com.appswithlove.updraft:updraft:3.0.0' + classpath 'com.appswithlove.updraft:updraft:3.0.1' } } ``` @@ -37,7 +37,7 @@ or ```kotlin plugins { - id("com.appswithlove.updraft") version "3.0.0" + id("com.appswithlove.updraft") version "3.0.1" } ``` @@ -125,7 +125,7 @@ buildscript { // ... } dependencies { - classpath 'com.appswithlove.updraft:updraft:3.0.0' + classpath 'com.appswithlove.updraft:updraft:3.0.1' // ... } } diff --git a/gradle.properties b/gradle.properties index bc2b64a..4ac3fc6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/lib/src/main/kotlin/com/appswithlove/updraft/UpdraftTask.kt b/lib/src/main/kotlin/com/appswithlove/updraft/UpdraftTask.kt index 6a26345..2b26b81 100644 --- a/lib/src/main/kotlin/com/appswithlove/updraft/UpdraftTask.kt +++ b/lib/src/main/kotlin/com/appswithlove/updraft/UpdraftTask.kt @@ -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" } diff --git a/lib/src/test/kotlin/com/appswithlove/updraft/HandleResponseTest.kt b/lib/src/test/kotlin/com/appswithlove/updraft/HandleResponseTest.kt new file mode 100644 index 0000000..83720d9 --- /dev/null +++ b/lib/src/test/kotlin/com/appswithlove/updraft/HandleResponseTest.kt @@ -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 { UpdraftTask.handleResponse("""{"detail":"Not found."}""") } + } + + @Test + fun handleResponse_withUnknownResponse_throws() { + assertThrows { UpdraftTask.handleResponse("""{"error":"invalid app"}""") } + } +}