Skip to content

Commit

Permalink
Add build scan server to config + test
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacSweers committed Jun 15, 2023
1 parent 0217e83 commit 8843b60
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/slack/cli/exec/ProcessedExecConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private const val CURRENT_VERSION = 1
@JsonClass(generateAdapter = true)
internal data class ProcessedExecConfig(
val version: Int = CURRENT_VERSION,
@Json(name = "gradle_enterprise_server") val gradleEnterpriseServer: String? = null,
@Json(name = "known_issues")
val knownIssues: List<Issue> =
KnownIssues::class.declaredMemberProperties.map { it.get(KnownIssues) as Issue },
Expand Down
27 changes: 13 additions & 14 deletions src/main/kotlin/slack/cli/exec/ResultProcessor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ internal class ResultProcessor(
// Group by the throwable message
report.setGroupingHash(issue.groupingHash)
report.addToTab("Run Info", "After-Retry", isAfterRetry)
logLinesReversed.parseBuildScan()?.let { scanLink ->
config.gradleEnterpriseServer?.let(logLinesReversed::parseBuildScan)?.let { scanLink ->
report.addToTab("Run Info", "Build-Scan", scanLink)
}
}
Expand All @@ -85,19 +85,6 @@ internal class ResultProcessor(
return RetrySignal.Unknown
}

// TODO test this
private fun List<String>.parseBuildScan(): String? {
// Find a build scan URL like so
// Publishing build scan...
// https://some-server.com/s/ueizlbptdqv6q

// Index of the publish log. Scan link should be above or below this.
val indexOfBuildScan = indexOfFirst { it.contains("Publishing build scan...") }
// Note the lines may be in reverse order here, so try both above and below
return get(indexOfBuildScan - 1).trim().takeUnless { "https" !in it }
?: get(indexOfBuildScan + 1).trim().takeUnless { "https" !in it }
}

private fun verboseEcho(message: String) {
if (verbose) echo(message)
}
Expand Down Expand Up @@ -158,3 +145,15 @@ private fun Report.populateBuildKiteTab() {
}

private fun envOrNull(envKey: String) = System.getenv(envKey)?.takeUnless { it.isBlank() }

internal fun List<String>.parseBuildScan(serverUrl: String): String? {
// Find a build scan URL like so
// Publishing build scan...
// https://some-server.com/s/ueizlbptdqv6q

// Index of the publish log. Scan link should be above or below this.
val indexOfBuildScan = indexOfFirst { it.contains("Publishing build scan...") }
// Note the lines may be in reverse order here, so try both above and below
return get(indexOfBuildScan - 1).trim().takeIf { serverUrl in it }
?: get(indexOfBuildScan + 1).trim().takeIf { serverUrl in it }
}
10 changes: 9 additions & 1 deletion src/test/kotlin/slack/cli/exec/ProcessedExecConfigTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ProcessedExecConfigTest {
"""
{
"version": 1,
"gradle_enterprise_server": "https://gradle-enterprise.example.com",
"known_issues": [
{
"message": "${KnownIssues.ftlRateLimit.message}",
Expand All @@ -47,7 +48,14 @@ class ProcessedExecConfigTest {
.trimIndent()

val issue = adapter.fromJson(json)!!
assertThat(issue).isEqualTo(ProcessedExecConfig(1, listOf(KnownIssues.ftlRateLimit)))
assertThat(issue)
.isEqualTo(
ProcessedExecConfig(
1,
"https://gradle-enterprise.example.com",
listOf(KnownIssues.ftlRateLimit)
)
)
}

@Test
Expand Down
16 changes: 16 additions & 0 deletions src/test/kotlin/slack/cli/exec/ResultProcessorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ class ResultProcessorTest {
check(signal is RetrySignal.Ack)
}

@Test
fun parseBuildScan() {
val url = "https://gradle-enterprise.example.com"
val scanUrl = "$url/s/ueizlbptdqv6q"
val log =
"""
Publishing build scan...
$scanUrl
""".trimIndent().padWithTestLogs()

// Assert in both directions they match
assertThat(log.lines().parseBuildScan(url)).isEqualTo(scanUrl)
assertThat(log.lines().reversed().parseBuildScan(url)).isEqualTo(scanUrl)
}

private fun newProcessor(): ResultProcessor {
return ResultProcessor(
verbose = true,
Expand Down

0 comments on commit 8843b60

Please sign in to comment.