Skip to content
This repository was archived by the owner on Oct 14, 2024. It is now read-only.

Commit 8843b60

Browse files
committed
Add build scan server to config + test
1 parent 0217e83 commit 8843b60

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

src/main/kotlin/slack/cli/exec/ProcessedExecConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ private const val CURRENT_VERSION = 1
2525
@JsonClass(generateAdapter = true)
2626
internal data class ProcessedExecConfig(
2727
val version: Int = CURRENT_VERSION,
28+
@Json(name = "gradle_enterprise_server") val gradleEnterpriseServer: String? = null,
2829
@Json(name = "known_issues")
2930
val knownIssues: List<Issue> =
3031
KnownIssues::class.declaredMemberProperties.map { it.get(KnownIssues) as Issue },

src/main/kotlin/slack/cli/exec/ResultProcessor.kt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ internal class ResultProcessor(
6565
// Group by the throwable message
6666
report.setGroupingHash(issue.groupingHash)
6767
report.addToTab("Run Info", "After-Retry", isAfterRetry)
68-
logLinesReversed.parseBuildScan()?.let { scanLink ->
68+
config.gradleEnterpriseServer?.let(logLinesReversed::parseBuildScan)?.let { scanLink ->
6969
report.addToTab("Run Info", "Build-Scan", scanLink)
7070
}
7171
}
@@ -85,19 +85,6 @@ internal class ResultProcessor(
8585
return RetrySignal.Unknown
8686
}
8787

88-
// TODO test this
89-
private fun List<String>.parseBuildScan(): String? {
90-
// Find a build scan URL like so
91-
// Publishing build scan...
92-
// https://some-server.com/s/ueizlbptdqv6q
93-
94-
// Index of the publish log. Scan link should be above or below this.
95-
val indexOfBuildScan = indexOfFirst { it.contains("Publishing build scan...") }
96-
// Note the lines may be in reverse order here, so try both above and below
97-
return get(indexOfBuildScan - 1).trim().takeUnless { "https" !in it }
98-
?: get(indexOfBuildScan + 1).trim().takeUnless { "https" !in it }
99-
}
100-
10188
private fun verboseEcho(message: String) {
10289
if (verbose) echo(message)
10390
}
@@ -158,3 +145,15 @@ private fun Report.populateBuildKiteTab() {
158145
}
159146

160147
private fun envOrNull(envKey: String) = System.getenv(envKey)?.takeUnless { it.isBlank() }
148+
149+
internal fun List<String>.parseBuildScan(serverUrl: String): String? {
150+
// Find a build scan URL like so
151+
// Publishing build scan...
152+
// https://some-server.com/s/ueizlbptdqv6q
153+
154+
// Index of the publish log. Scan link should be above or below this.
155+
val indexOfBuildScan = indexOfFirst { it.contains("Publishing build scan...") }
156+
// Note the lines may be in reverse order here, so try both above and below
157+
return get(indexOfBuildScan - 1).trim().takeIf { serverUrl in it }
158+
?: get(indexOfBuildScan + 1).trim().takeIf { serverUrl in it }
159+
}

src/test/kotlin/slack/cli/exec/ProcessedExecConfigTest.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class ProcessedExecConfigTest {
3030
"""
3131
{
3232
"version": 1,
33+
"gradle_enterprise_server": "https://gradle-enterprise.example.com",
3334
"known_issues": [
3435
{
3536
"message": "${KnownIssues.ftlRateLimit.message}",
@@ -47,7 +48,14 @@ class ProcessedExecConfigTest {
4748
.trimIndent()
4849

4950
val issue = adapter.fromJson(json)!!
50-
assertThat(issue).isEqualTo(ProcessedExecConfig(1, listOf(KnownIssues.ftlRateLimit)))
51+
assertThat(issue)
52+
.isEqualTo(
53+
ProcessedExecConfig(
54+
1,
55+
"https://gradle-enterprise.example.com",
56+
listOf(KnownIssues.ftlRateLimit)
57+
)
58+
)
5159
}
5260

5361
@Test

src/test/kotlin/slack/cli/exec/ResultProcessorTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,22 @@ class ResultProcessorTest {
9898
check(signal is RetrySignal.Ack)
9999
}
100100

101+
@Test
102+
fun parseBuildScan() {
103+
val url = "https://gradle-enterprise.example.com"
104+
val scanUrl = "$url/s/ueizlbptdqv6q"
105+
val log =
106+
"""
107+
Publishing build scan...
108+
$scanUrl
109+
110+
""".trimIndent().padWithTestLogs()
111+
112+
// Assert in both directions they match
113+
assertThat(log.lines().parseBuildScan(url)).isEqualTo(scanUrl)
114+
assertThat(log.lines().reversed().parseBuildScan(url)).isEqualTo(scanUrl)
115+
}
116+
101117
private fun newProcessor(): ResultProcessor {
102118
return ResultProcessor(
103119
verbose = true,

0 commit comments

Comments
 (0)