Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelpasterz committed Dec 11, 2020
1 parent c0d4c0e commit 73130da
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 38 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/full_suite_integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pair<String, GithubPullRequest?>> = coroutineScope {
getGitHubCommitList(token, listOf("since" to since))
.onError { println(it.message) }
.getOrElse { emptyList() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pair<String, GithubPullRequest?>>
): 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:
Expand All @@ -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<Pair<String, GithubPullRequest?>>
): 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})" } ?: "---"}")
}
}
}

0 comments on commit 73130da

Please sign in to comment.