From 73130da3f8ead9ef84f8ad066a3ffb9206309de2 Mon Sep 17 00:00:00 2001 From: Pawel Pasterz Date: Fri, 11 Dec 2020 15:49:46 +0100 Subject: [PATCH] Linting --- .../full_suite_integration_tests.yml | 6 ++- .../flank/scripts/integration/CommitList.kt | 6 ++- .../flank/scripts/integration/Extensions.kt | 27 ++++++----- .../flank/scripts/integration/IssueList.kt | 2 +- .../scripts/integration/PrepareMessage.kt | 46 +++++++++---------- 5 files changed, 49 insertions(+), 38 deletions(-) diff --git a/.github/workflows/full_suite_integration_tests.yml b/.github/workflows/full_suite_integration_tests.yml index bf74b3767b..9ffc68ec56 100644 --- a/.github/workflows/full_suite_integration_tests.yml +++ b/.github/workflows/full_suite_integration_tests.yml @@ -55,4 +55,8 @@ jobs: - name: Process IT results run: | - flankScripts integration processResults --result ${{ job.status }} --url ${{ steps.run-it.outputs.build-scan-url }} --github-token=${{ secrets.GITHUB_TOKEN }} --run-id ${{ github.run_id }} + flankScripts integration processResults \ + --result ${{ job.status }} \ + --url ${{ steps.run-it.outputs.build-scan-url }} \ + --github-token ${{ secrets.GITHUB_TOKEN }} \ + --run-id ${{ github.run_id }} diff --git a/flank-scripts/src/main/kotlin/flank/scripts/integration/CommitList.kt b/flank-scripts/src/main/kotlin/flank/scripts/integration/CommitList.kt index c89cf88358..347ddb76f3 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/integration/CommitList.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/integration/CommitList.kt @@ -4,11 +4,15 @@ import com.github.kittinunf.result.getOrElse import com.github.kittinunf.result.onError import flank.scripts.github.getGitHubCommitList import flank.scripts.github.getPrDetailsByCommit +import flank.scripts.github.objects.GithubPullRequest import kotlinx.coroutines.async import kotlinx.coroutines.awaitAll import kotlinx.coroutines.coroutineScope -suspend fun getCommitListSinceDate(token: String, since: String) = coroutineScope { +suspend fun getCommitListSinceDate( + token: String, + since: String +): List> = coroutineScope { getGitHubCommitList(token, listOf("since" to since)) .onError { println(it.message) } .getOrElse { emptyList() } diff --git a/flank-scripts/src/main/kotlin/flank/scripts/integration/Extensions.kt b/flank-scripts/src/main/kotlin/flank/scripts/integration/Extensions.kt index 87086d9c37..784b3350ce 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/integration/Extensions.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/integration/Extensions.kt @@ -13,7 +13,21 @@ import flank.scripts.utils.toJson import kotlinx.coroutines.coroutineScope import kotlin.system.exitProcess -internal suspend fun IntegrationContext.createNewIssue() = createAndPostNewIssue().postComment() +internal suspend fun IntegrationContext.createNewIssue(): GitHubCreateIssueCommentRequest = + createAndPostNewIssue().postComment() + +internal suspend fun IntegrationContext.postComment(): GitHubCreateIssueCommentRequest = + createCommentPayload().also { payload -> + postNewIssueComment(token, issueNumber, payload) + println("** Comment posted") + println(payload.toJson()) + } + +internal suspend fun IntegrationContext.closeIssue(): ByteArray = + postComment().run { + println("** Closing issue") + patchIssue(token, issueNumber, GitHubUpdateIssueRequest(state = IssueState.CLOSED)).get() + } private suspend fun IntegrationContext.createAndPostNewIssue(payload: GitHubCreateIssueRequest = createIssuePayload()) = postNewIssue(token, payload) @@ -38,12 +52,6 @@ private fun createIssuePayload(): GitHubCreateIssueRequest { return issuePayload } -internal suspend fun IntegrationContext.postComment() = createCommentPayload().also { payload -> - postNewIssueComment(token, issueNumber, payload) - println("** Comment posted") - println(payload.toJson()) -} - private suspend fun IntegrationContext.createCommentPayload() = coroutineScope { val message = when (result) { ITResults.SUCCESS -> prepareSuccessMessage(lastRun, runID, url) @@ -55,11 +63,6 @@ private suspend fun IntegrationContext.createCommentPayload() = coroutineScope { GitHubCreateIssueCommentRequest(message) } -internal suspend fun IntegrationContext.closeIssue() = postComment().also { - println("** Closing issue") - patchIssue(token, issueNumber, GitHubUpdateIssueRequest(state = IssueState.CLOSED)) -} - private fun logIssueCreated(issue: GitHubCreateIssueResponse) = println( """ ** Issue created: diff --git a/flank-scripts/src/main/kotlin/flank/scripts/integration/IssueList.kt b/flank-scripts/src/main/kotlin/flank/scripts/integration/IssueList.kt index 4edad68613..c3e29a123f 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/integration/IssueList.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/integration/IssueList.kt @@ -4,7 +4,7 @@ import com.github.kittinunf.result.getOrElse import com.github.kittinunf.result.onError import flank.scripts.github.getGitHubIssueList -suspend fun checkForOpenedITIssues(token: String) = getGitHubIssueList( +suspend fun checkForOpenedITIssues(token: String): Int? = getGitHubIssueList( githubToken = token, parameters = listOf( "creator" to "github-actions[bot]", diff --git a/flank-scripts/src/main/kotlin/flank/scripts/integration/PrepareMessage.kt b/flank-scripts/src/main/kotlin/flank/scripts/integration/PrepareMessage.kt index dcb639817b..1445d60f4a 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/integration/PrepareMessage.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/integration/PrepareMessage.kt @@ -6,6 +6,29 @@ import java.time.LocalDateTime import java.time.ZoneOffset import java.time.format.DateTimeFormatter +fun prepareSuccessMessage( + lastRun: String, + runId: String, + url: String +): String = successTemplate(lastRun, runId, url) + +fun prepareFailureMessage( + lastRun: String, + runId: String, + url: String, + prs: List> +): String = buildString { + appendLine(failureTemplate(lastRun, runId, url)) + if (prs.isEmpty()) appendLine("No new commits") + else { + appendLine("|commit SHA|PR|") + appendLine("|---|:---:|") + prs.forEach { (commit, pr) -> + appendLine("|$commit|${pr?.let { "[${it.title}](${it.htmlUrl})" } ?: "---"}") + } + } +} + private val successTemplate = { lastRun: String, runId: String, url: String -> """ |### Full suite IT run :white_check_mark: SUCCEEDED :white_check_mark: @@ -29,26 +52,3 @@ private fun makeHumanFriendly(date: String) = LocalDateTime .ofInstant(Instant.from(DateTimeFormatter.ISO_INSTANT.parse(date)), ZoneOffset.UTC) .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) - -fun prepareSuccessMessage( - lastRun: String, - runId: String, - url: String -): String = successTemplate(lastRun, runId, url) - -fun prepareFailureMessage( - lastRun: String, - runId: String, - url: String, - prs: List> -): String = buildString { - appendLine(failureTemplate(lastRun, runId, url)) - if (prs.isEmpty()) appendLine("No new commits") - else { - appendLine("|commit SHA|PR|") - appendLine("|---|:---:|") - prs.forEach { (commit, pr) -> - appendLine("|$commit|${pr?.let { "[${it.title}](${it.htmlUrl})" } ?: "---"}") - } - } -}