From de361849c44d9668e3cb7989dfe73e2bcb08cf78 Mon Sep 17 00:00:00 2001 From: Pawel Pasterz Date: Tue, 29 Dec 2020 07:00:07 +0100 Subject: [PATCH] Refactor --- flank-scripts/build.gradle.kts | 31 ++++++------ .../kotlin/flank/scripts/github/GithubApi.kt | 49 +++++++++---------- .../github/commons/LastWorkflowRunDate.kt | 44 +++++++++++++++++ .../scripts/github/objects/GitHubCommit.kt | 15 +++++- .../scripts/integration/WorkflowSummary.kt | 43 +--------------- .../pullrequest/GitHubIssuePropertiesCopy.kt | 1 + .../scripts/shell/firebase/FirebaseCommand.kt | 2 + .../GenerateJavaClientCommand.kt | 2 +- .../{ => apiclient}/UpdateApiJsonCommand.kt | 2 +- .../ZenHubAPI.kt} | 5 +- .../{pullrequest => zenhub}/ZenHubIssue.kt | 2 +- .../kotlin/flank/scripts/FuelMockServer.kt | 2 +- .../flank/scripts/GithubMockServerHandler.kt | 4 +- .../flank/scripts/ZenHubMockServerHandler.kt | 21 ++++++-- .../ZenHubCopyEstimationsTest.kt | 2 +- 15 files changed, 131 insertions(+), 94 deletions(-) create mode 100644 flank-scripts/src/main/kotlin/flank/scripts/github/commons/LastWorkflowRunDate.kt rename flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/{ => apiclient}/GenerateJavaClientCommand.kt (96%) rename flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/{ => apiclient}/UpdateApiJsonCommand.kt (96%) rename flank-scripts/src/main/kotlin/flank/scripts/{pullrequest/ZenHubCopyEstimations.kt => zenhub/ZenHubAPI.kt} (95%) rename flank-scripts/src/main/kotlin/flank/scripts/{pullrequest => zenhub}/ZenHubIssue.kt (92%) rename flank-scripts/src/test/kotlin/flank/scripts/{pullrequest => zenhub}/ZenHubCopyEstimationsTest.kt (97%) diff --git a/flank-scripts/build.gradle.kts b/flank-scripts/build.gradle.kts index 7498dda740..a60ca4f9f1 100644 --- a/flank-scripts/build.gradle.kts +++ b/flank-scripts/build.gradle.kts @@ -1,9 +1,8 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.jfrog.bintray.gradle.BintrayExtension -import groovy.xml.dom.DOMCategory.attributes import java.io.ByteArrayOutputStream import java.nio.file.Paths -import java.util.* +import java.util.Date plugins { application @@ -29,7 +28,7 @@ shadowJar.apply { } } // .. -version = "1.2.8" +version = "1.2.9" group = "com.github.flank" application { @@ -46,17 +45,21 @@ bintray { publish = true override = true setPublications("mavenJava") - pkg(closureOf { - repo = "maven" - name = artifactID - userOrg = "flank" - setLicenses("Apache-2.0") - vcsUrl = "https://github.com/Flank/flank.git" - version(closureOf { - name = version.name - released = Date().toString() - }) - }) + pkg( + closureOf { + repo = "maven" + name = artifactID + userOrg = "flank" + setLicenses("Apache-2.0") + vcsUrl = "https://github.com/Flank/flank.git" + version( + closureOf { + name = version.name + released = Date().toString() + } + ) + } + ) } publishing { diff --git a/flank-scripts/src/main/kotlin/flank/scripts/github/GithubApi.kt b/flank-scripts/src/main/kotlin/flank/scripts/github/GithubApi.kt index 5238d1ec5e..8abf0c86d2 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/github/GithubApi.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/github/GithubApi.kt @@ -32,71 +32,72 @@ import flank.scripts.github.objects.GithubWorkflowRunsSummaryDeserializer import flank.scripts.utils.toJson import java.lang.Exception -private const val URL_BASE = "https://api.github.com/repos/Flank/flank" +private const val FLANK_REPO = "Flank/flank" +private const val URL_BASE = "https://api.github.com/repos" // ============= HTTP GITHUB API ============= // GET -suspend fun getPrDetailsByCommit(commitSha: String, githubToken: String): Result, Exception> = - Fuel.get("$URL_BASE/commits/$commitSha/pulls") +suspend fun getPrDetailsByCommit(commitSha: String, githubToken: String, repo: String = FLANK_REPO): Result, Exception> = + Fuel.get("$URL_BASE/$repo/commits/$commitSha/pulls") .appendGitHubHeaders(githubToken, "application/vnd.github.groot-preview+json") .awaitResult(GithubPullRequestListDeserializer) .mapClientErrorToGithubException() .onError { println("Could not download info for commit $commitSha, because of ${it.message}") } -suspend fun getLatestReleaseTag(githubToken: String): Result = - Fuel.get("$URL_BASE/releases/latest") +suspend fun getLatestReleaseTag(githubToken: String, repo: String = FLANK_REPO): Result = + Fuel.get("$URL_BASE/$repo/releases/latest") .appendGitHubHeaders(githubToken) .awaitResult(GithubReleaseDeserializable) .mapClientErrorToGithubException() -suspend fun getGitHubPullRequest(githubToken: String, issueNumber: Int): Result = - Fuel.get("$URL_BASE/pulls/$issueNumber") +suspend fun getGitHubPullRequest(githubToken: String, issueNumber: Int, repo: String = FLANK_REPO): Result = + Fuel.get("$URL_BASE/$repo/pulls/$issueNumber") .appendGitHubHeaders(githubToken) .awaitResult(GithubPullRequestDeserializer) .mapClientErrorToGithubException() -suspend fun getGitHubIssue(githubToken: String, issueNumber: Int): Result = - Fuel.get("$URL_BASE/issues/$issueNumber") +suspend fun getGitHubIssue(githubToken: String, issueNumber: Int, repo: String = FLANK_REPO): Result = + Fuel.get("$URL_BASE/$repo/issues/$issueNumber") .appendGitHubHeaders(githubToken) .awaitResult(GithubPullRequestDeserializer) .mapClientErrorToGithubException() -suspend fun getGitHubIssueList(githubToken: String, parameters: Parameters = emptyList()): Result, Exception> = - Fuel.get("$URL_BASE/issues", parameters) +suspend fun getGitHubIssueList(githubToken: String, parameters: Parameters = emptyList(), repo: String = FLANK_REPO): Result, Exception> = + Fuel.get("$URL_BASE/$repo/issues", parameters) .appendGitHubHeaders(githubToken) .awaitResult(GithubPullRequestListDeserializer) .mapClientErrorToGithubException() -suspend fun getGitHubCommitList(githubToken: String, parameters: Parameters = emptyList()): Result, Exception> = - Fuel.get("$URL_BASE/commits", parameters) +suspend fun getGitHubCommitList(githubToken: String, parameters: Parameters = emptyList(), repo: String = FLANK_REPO): Result, Exception> = + Fuel.get("$URL_BASE/$repo/commits", parameters) .appendGitHubHeaders(githubToken) .awaitResult(GitHubCommitListDeserializer) .mapClientErrorToGithubException() -suspend fun getGitHubWorkflowRunsSummary(githubToken: String, workflow: String, parameters: Parameters = emptyList()): Result = - Fuel.get("$URL_BASE/actions/workflows/$workflow/runs", parameters) +suspend fun getGitHubWorkflowRunsSummary(githubToken: String, workflow: String, parameters: Parameters = emptyList(), repo: String = FLANK_REPO): Result = + Fuel.get("$URL_BASE/$repo/actions/workflows/$workflow/runs", parameters) .appendGitHubHeaders(githubToken) .awaitResult(GithubWorkflowRunsSummaryDeserializer) .mapClientErrorToGithubException() // POST -suspend fun postNewIssueComment(githubToken: String, issueNumber: Int, payload: GitHubCreateIssueCommentRequest): Result = - Fuel.post("$URL_BASE/issues/$issueNumber/comments") +suspend fun postNewIssueComment(githubToken: String, issueNumber: Int, payload: GitHubCreateIssueCommentRequest, repo: String = FLANK_REPO): Result = + Fuel.post("$URL_BASE/$repo/issues/$issueNumber/comments") .appendGitHubHeaders(githubToken) .body(payload.toJson()) .awaitResult(GitHubCreateIssueCommentResponseDeserializer) .mapClientErrorToGithubException() -suspend fun postNewIssue(githubToken: String, payload: GitHubCreateIssueRequest): Result = - Fuel.post("$URL_BASE/issues") +suspend fun postNewIssue(githubToken: String, payload: GitHubCreateIssueRequest, repo: String = FLANK_REPO): Result = + Fuel.post("$URL_BASE/$repo/issues") .appendGitHubHeaders(githubToken) .body(payload.toJson()) .awaitResult(GitHubCreateIssueResponseDeserializer) .mapClientErrorToGithubException() // PATCH -fun patchIssue(githubToken: String, issueNumber: Int, payload: GitHubUpdateIssueRequest): Result = - Fuel.patch("$URL_BASE/issues/$issueNumber") +fun patchIssue(githubToken: String, issueNumber: Int, payload: GitHubUpdateIssueRequest, repo: String = FLANK_REPO): Result = + Fuel.patch("$URL_BASE/$repo/issues/$issueNumber") .appendGitHubHeaders(githubToken) .body(payload.toJson()) .response() @@ -104,8 +105,8 @@ fun patchIssue(githubToken: String, issueNumber: Int, payload: GitHubUpdateIssue .mapClientErrorToGithubException() // DELETE -fun deleteOldTag(tag: String, username: String, password: String): Result = - Fuel.delete(DELETE_ENDPOINT + tag) +fun deleteOldTag(tag: String, username: String, password: String, repo: String = FLANK_REPO): Result = + Fuel.delete("$URL_BASE/$repo/git/refs/tags/$tag") .authentication() .basic(username, password) .response() @@ -116,8 +117,6 @@ fun Request.appendGitHubHeaders(githubToken: String, contentType: String = "appl appendHeader("Accept", contentType) .appendHeader("Authorization", "token $githubToken") -private const val DELETE_ENDPOINT = "$URL_BASE/git/refs/tags/" - // ============= JCABI GITHUB API ============= fun githubRepo( diff --git a/flank-scripts/src/main/kotlin/flank/scripts/github/commons/LastWorkflowRunDate.kt b/flank-scripts/src/main/kotlin/flank/scripts/github/commons/LastWorkflowRunDate.kt new file mode 100644 index 0000000000..cf1c5d6030 --- /dev/null +++ b/flank-scripts/src/main/kotlin/flank/scripts/github/commons/LastWorkflowRunDate.kt @@ -0,0 +1,44 @@ +package flank.scripts.github.commons + +import com.github.kittinunf.result.getOrNull +import flank.scripts.github.getGitHubWorkflowRunsSummary +import flank.scripts.github.objects.GitHubWorkflowRun +import java.time.Instant +import java.time.format.DateTimeFormatter + +suspend fun getLastWorkflowRunDate( + token: String, + workflowName: String? = null, + workflowFileName: String? = null +): String = getGitHubWorkflowRunsSummary( + githubToken = token, + workflow = requireNotNull( + workflowName ?: workflowFileName + ) { "** Missing either workflow name or workflow file name. Both can not be null" }, + parameters = listOf( + "per_page" to 20, + "page" to 1 + ) +).getOrNull() + ?.run { + workflowRuns + .filter { it.status != "in_progress" } + .filter { it.conclusion != "cancelled" } + .getOrNull(0) + .logRun() + ?.createdAt.run { DateTimeFormatter.ISO_INSTANT.format(Instant.parse(this)) } + } ?: run { + println("** No workflow run found for ${workflowName ?: workflowFileName}") + DateTimeFormatter.ISO_INSTANT.format(Instant.now()) +} + +private fun GitHubWorkflowRun?.logRun() = this?.also { + println( + """ +** Last workflow run: + name: ${it.name} + last run: ${it.createdAt} + url: ${it.htmlUrl} + """.trimIndent() + ) +} diff --git a/flank-scripts/src/main/kotlin/flank/scripts/github/objects/GitHubCommit.kt b/flank-scripts/src/main/kotlin/flank/scripts/github/objects/GitHubCommit.kt index b0039576c6..432b9a3ae1 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/github/objects/GitHubCommit.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/github/objects/GitHubCommit.kt @@ -6,7 +6,20 @@ import kotlinx.serialization.Serializable @Serializable data class GitHubCommit( - val sha: String + val sha: String, + val commit: Commit +) + +@Serializable +data class Commit( + val author: Author +) + +@Serializable +data class Author( + val name: String, + val email: String, + val date: String ) object GitHubCommitListDeserializer : ResponseDeserializable> { diff --git a/flank-scripts/src/main/kotlin/flank/scripts/integration/WorkflowSummary.kt b/flank-scripts/src/main/kotlin/flank/scripts/integration/WorkflowSummary.kt index 1c8f329d8e..bc3cb67050 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/integration/WorkflowSummary.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/integration/WorkflowSummary.kt @@ -1,49 +1,8 @@ package flank.scripts.integration -import com.github.kittinunf.result.getOrNull -import flank.scripts.github.getGitHubWorkflowRunsSummary -import flank.scripts.github.objects.GitHubWorkflowRun -import java.time.Instant -import java.time.format.DateTimeFormatter +import flank.scripts.github.commons.getLastWorkflowRunDate suspend fun getLastITWorkflowRunDate(token: String) = getLastWorkflowRunDate( token = token, workflowFileName = "full_suite_integration_tests.yml" ) - -suspend fun getLastWorkflowRunDate( - token: String, - workflowName: String? = null, - workflowFileName: String? = null -): String = getGitHubWorkflowRunsSummary( - githubToken = token, - workflow = requireNotNull( - workflowName ?: workflowFileName - ) { "** Missing either workflow name or workflow file name. Both can not be null" }, - parameters = listOf( - "per_page" to 20, - "page" to 1 - ) -).getOrNull() - ?.run { - workflowRuns - .filter { it.status != "in_progress" } - .filter { it.conclusion != "cancelled" } - .getOrNull(0) - .logRun() - ?.createdAt.run { DateTimeFormatter.ISO_INSTANT.format(Instant.parse(this)) } - } ?: run { - println("** No workflow run found for ${workflowName ?: workflowFileName}") - DateTimeFormatter.ISO_INSTANT.format(Instant.now()) -} - -private fun GitHubWorkflowRun?.logRun() = this?.also { - println( - """ -** Last workflow run: - name: ${it.name} - last run: ${it.createdAt} - url: ${it.htmlUrl} - """.trimIndent() - ) -} diff --git a/flank-scripts/src/main/kotlin/flank/scripts/pullrequest/GitHubIssuePropertiesCopy.kt b/flank-scripts/src/main/kotlin/flank/scripts/pullrequest/GitHubIssuePropertiesCopy.kt index 7151a336b7..6009126b71 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/pullrequest/GitHubIssuePropertiesCopy.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/pullrequest/GitHubIssuePropertiesCopy.kt @@ -7,6 +7,7 @@ import com.github.ajalt.clikt.parameters.types.int import com.github.kittinunf.result.onError import com.github.kittinunf.result.success import flank.scripts.github.getGitHubPullRequest +import flank.scripts.zenhub.copyEstimation import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.joinAll diff --git a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/FirebaseCommand.kt b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/FirebaseCommand.kt index 80d68d6377..a65635e5a1 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/FirebaseCommand.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/FirebaseCommand.kt @@ -2,6 +2,8 @@ package flank.scripts.shell.firebase import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.core.subcommands +import flank.scripts.shell.firebase.apiclient.GenerateJavaClientCommand +import flank.scripts.shell.firebase.apiclient.UpdateApiJsonCommand object FirebaseCommand : CliktCommand(name = "firebase", help = "Contains all firebase commands") { diff --git a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/GenerateJavaClientCommand.kt b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/apiclient/GenerateJavaClientCommand.kt similarity index 96% rename from flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/GenerateJavaClientCommand.kt rename to flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/apiclient/GenerateJavaClientCommand.kt index f4dc94355f..1995679c31 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/GenerateJavaClientCommand.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/apiclient/GenerateJavaClientCommand.kt @@ -1,4 +1,4 @@ -package flank.scripts.shell.firebase +package flank.scripts.shell.firebase.apiclient import com.github.ajalt.clikt.core.CliktCommand import flank.scripts.exceptions.ShellCommandException diff --git a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/UpdateApiJsonCommand.kt b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/apiclient/UpdateApiJsonCommand.kt similarity index 96% rename from flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/UpdateApiJsonCommand.kt rename to flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/apiclient/UpdateApiJsonCommand.kt index 3dd0d569b7..138fa85004 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/UpdateApiJsonCommand.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/shell/firebase/apiclient/UpdateApiJsonCommand.kt @@ -1,4 +1,4 @@ -package flank.scripts.shell.firebase +package flank.scripts.shell.firebase.apiclient import com.github.ajalt.clikt.core.CliktCommand import flank.common.downloadFile diff --git a/flank-scripts/src/main/kotlin/flank/scripts/pullrequest/ZenHubCopyEstimations.kt b/flank-scripts/src/main/kotlin/flank/scripts/zenhub/ZenHubAPI.kt similarity index 95% rename from flank-scripts/src/main/kotlin/flank/scripts/pullrequest/ZenHubCopyEstimations.kt rename to flank-scripts/src/main/kotlin/flank/scripts/zenhub/ZenHubAPI.kt index d87cda3882..4f618b8aa9 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/pullrequest/ZenHubCopyEstimations.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/zenhub/ZenHubAPI.kt @@ -1,4 +1,4 @@ -package flank.scripts.pullrequest +package flank.scripts.zenhub import com.github.kittinunf.fuel.Fuel import com.github.kittinunf.fuel.core.Request @@ -10,9 +10,10 @@ import com.github.kittinunf.result.success import flank.scripts.utils.toJson import kotlinx.serialization.Serializable -private const val FLANK_REPO_ID = 84221974 +const val FLANK_REPO_ID = 84221974 internal const val ZENHUB_BASE_URL = "https://api.zenhub.com/p1/repositories/$FLANK_REPO_ID" +// GET suspend fun copyEstimation(zenhubToken: String, issueNumber: Int, pullRequestNumber: Int) { getEstimation(zenhubToken, issueNumber) ?.run { setEstimation(zenhubToken, pullRequestNumber, estimate.value) } diff --git a/flank-scripts/src/main/kotlin/flank/scripts/pullrequest/ZenHubIssue.kt b/flank-scripts/src/main/kotlin/flank/scripts/zenhub/ZenHubIssue.kt similarity index 92% rename from flank-scripts/src/main/kotlin/flank/scripts/pullrequest/ZenHubIssue.kt rename to flank-scripts/src/main/kotlin/flank/scripts/zenhub/ZenHubIssue.kt index 79514565ca..011b522c8e 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/pullrequest/ZenHubIssue.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/zenhub/ZenHubIssue.kt @@ -1,4 +1,4 @@ -package flank.scripts.pullrequest +package flank.scripts.zenhub import com.github.kittinunf.fuel.core.ResponseDeserializable import flank.scripts.utils.toObject diff --git a/flank-scripts/src/test/kotlin/flank/scripts/FuelMockServer.kt b/flank-scripts/src/test/kotlin/flank/scripts/FuelMockServer.kt index 645facd61b..8372fba82e 100644 --- a/flank-scripts/src/test/kotlin/flank/scripts/FuelMockServer.kt +++ b/flank-scripts/src/test/kotlin/flank/scripts/FuelMockServer.kt @@ -4,11 +4,11 @@ import com.github.kittinunf.fuel.core.Client import com.github.kittinunf.fuel.core.Request import com.github.kittinunf.fuel.core.Response import com.github.kittinunf.fuel.core.requests.DefaultBody -import flank.scripts.pullrequest.ZENHUB_BASE_URL import flank.scripts.release.updatebugsnag.BugSnagRequest import flank.scripts.release.updatebugsnag.BugSnagResponse import flank.scripts.utils.toJson import flank.scripts.utils.toObject +import flank.scripts.zenhub.ZENHUB_BASE_URL class FuelMockServer : Client { override fun executeRequest(request: Request): Response { diff --git a/flank-scripts/src/test/kotlin/flank/scripts/GithubMockServerHandler.kt b/flank-scripts/src/test/kotlin/flank/scripts/GithubMockServerHandler.kt index c542890471..b03796ab63 100644 --- a/flank-scripts/src/test/kotlin/flank/scripts/GithubMockServerHandler.kt +++ b/flank-scripts/src/test/kotlin/flank/scripts/GithubMockServerHandler.kt @@ -3,6 +3,8 @@ package flank.scripts import com.github.kittinunf.fuel.core.Method import com.github.kittinunf.fuel.core.Request import flank.scripts.ci.releasenotes.GitHubRelease +import flank.scripts.github.objects.Author +import flank.scripts.github.objects.Commit import flank.scripts.github.objects.GitHubCommit import flank.scripts.github.objects.GitHubCreateIssueCommentResponse import flank.scripts.github.objects.GitHubCreateIssueResponse @@ -58,7 +60,7 @@ private fun Request.isFailedGithubRequest() = private fun Request.noIssueHeader() = request.headers["Authorization"].contains("token no-issue") private val testGithubIssueList = listOf( - GitHubCommit("aaaaaaaaa") + GitHubCommit("aaaaaaaaa", Commit(Author("", "", ""))) ).toJson() private val testGithubIssueCommentList = listOf( diff --git a/flank-scripts/src/test/kotlin/flank/scripts/ZenHubMockServerHandler.kt b/flank-scripts/src/test/kotlin/flank/scripts/ZenHubMockServerHandler.kt index 16c19c1023..32b2930295 100644 --- a/flank-scripts/src/test/kotlin/flank/scripts/ZenHubMockServerHandler.kt +++ b/flank-scripts/src/test/kotlin/flank/scripts/ZenHubMockServerHandler.kt @@ -2,14 +2,18 @@ package flank.scripts import com.github.kittinunf.fuel.core.Method import com.github.kittinunf.fuel.core.Request -import flank.scripts.pullrequest.ZenHubEstimate -import flank.scripts.pullrequest.ZenHubIssue import flank.scripts.utils.toJson +import flank.scripts.zenhub.ZenHubEstimate +import flank.scripts.zenhub.ZenHubIssue fun handleZenhubMockRequest(url: String, request: Request) = when { - url.contains("issues") && request.method == Method.GET && request.isSuccessful() -> + url.contains("issues") && request.isGet && request.isSuccessful() -> request.buildResponse(testZenHubIssue.toJson(), 200) - url.contains("issues") && request.method == Method.PUT && request.isSuccessful() -> + + url.contains("issues") && request.isPut && request.isSuccessful() -> + request.buildResponse("", 201) + + url.contains("issues") && request.isPost && request.isSuccessful() -> request.buildResponse("", 201) else -> request.buildResponse("Bad authentication", 401) @@ -17,4 +21,13 @@ fun handleZenhubMockRequest(url: String, request: Request) = when { val testZenHubIssue = ZenHubIssue(ZenHubEstimate(3)) +private val Request.isGet: Boolean + get() = method == Method.GET + +private val Request.isPut: Boolean + get() = method == Method.PUT + +private val Request.isPost: Boolean + get() = method == Method.POST + private fun Request.isSuccessful() = request.headers["X-Authentication-Token"].contains("success") diff --git a/flank-scripts/src/test/kotlin/flank/scripts/pullrequest/ZenHubCopyEstimationsTest.kt b/flank-scripts/src/test/kotlin/flank/scripts/zenhub/ZenHubCopyEstimationsTest.kt similarity index 97% rename from flank-scripts/src/test/kotlin/flank/scripts/pullrequest/ZenHubCopyEstimationsTest.kt rename to flank-scripts/src/test/kotlin/flank/scripts/zenhub/ZenHubCopyEstimationsTest.kt index 80eec31317..98a8a66b6c 100644 --- a/flank-scripts/src/test/kotlin/flank/scripts/pullrequest/ZenHubCopyEstimationsTest.kt +++ b/flank-scripts/src/test/kotlin/flank/scripts/zenhub/ZenHubCopyEstimationsTest.kt @@ -1,4 +1,4 @@ -package flank.scripts.pullrequest +package flank.scripts.zenhub import flank.scripts.FuelTestRunner import flank.scripts.testZenHubIssue