Skip to content

Commit 8ce14b2

Browse files
authored
feat(automation): add links to diffs between major versions (#1252)
Makes it easier to review what actually changed between the versions.
1 parent 28b40cb commit 8ce14b2

File tree

2 files changed

+22
-11
lines changed
  • automation/code-generator/src

2 files changed

+22
-11
lines changed

automation/code-generator/src/main/kotlin/io/github/typesafegithub/workflows/codegenerator/versions/SuggestVersions.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ suspend fun main() {
3636

3737
for ((coords, existingVersions) in actionsMap) {
3838
val available = coords.fetchAvailableVersions(githubAuthorization)
39-
suggestNewerVersion(existingVersions, available)?.let { message ->
39+
coords.suggestNewerVersion(existingVersions, available)?.let { message ->
4040
val outputForAction = "$message for ${coords.prettyPrint}"
4141
println(outputForAction)
4242
output += "$outputForAction\n"
@@ -60,7 +60,7 @@ fun List<GithubRef>.versions(): List<Version> =
6060
Version(version)
6161
}
6262

63-
fun suggestNewerVersion(
63+
fun ActionCoords.suggestNewerVersion(
6464
existingVersions: List<Version>,
6565
availableVersions: List<Version>,
6666
): String? {
@@ -77,6 +77,13 @@ fun suggestNewerVersion(
7777
.filter { it.isMajorVersion() }
7878
.sorted()
7979

80-
val newerMajorVersions = majorVersions.filter { it > maxExisting }.sorted()
80+
val newerMajorVersions =
81+
majorVersions.filter { it > maxExisting }.sorted()
82+
.map { "$it ([diff](${this.buildGitHubComparisonUrl(maxExisting, it)}))" }
8183
return "new version(s) available: $newerMajorVersions".takeIf { newerMajorVersions.isNotEmpty() }
8284
}
85+
86+
private fun ActionCoords.buildGitHubComparisonUrl(
87+
version1: Version,
88+
version2: Version,
89+
): String = "https://github.com/${this.owner}/${this.name}/compare/$version1...$version2#files_bucket"

automation/code-generator/src/test/kotlin/io/github/typesafegithub/workflows/codegenerator/versions/SuggestVersionsTest.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.typesafegithub.workflows.codegenerator.versions
22

3+
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
34
import io.github.typesafegithub.workflows.codegenerator.model.Version
45
import io.kotest.assertions.assertSoftly
56
import io.kotest.core.spec.style.FunSpec
@@ -13,6 +14,7 @@ import io.kotest.matchers.shouldBe
1314

1415
class SuggestVersionsTest : FunSpec({
1516
fun String.versions(): List<Version> = split(", ").filter { it.isNotBlank() }.map { Version(it) }
17+
val testCoords = ActionCoords(owner = "test-owner", name = "test-name", version = "v3")
1618

1719
test("Compare versions") {
1820
val sortedVersions =
@@ -48,27 +50,29 @@ class SuggestVersionsTest : FunSpec({
4850
row("v12", "v9"),
4951
)
5052
testCases.forAll { current, available ->
51-
suggestNewerVersion(current.versions(), available.versions()) shouldBe null
53+
testCoords.suggestNewerVersion(current.versions(), available.versions()) shouldBe null
5254
}
5355
}
5456

5557
test("New major version") {
5658
assertSoftly {
5759

58-
suggestNewerVersion(
60+
testCoords.suggestNewerVersion(
5961
"v1".versions(),
6062
"v1, v1.1.1, v2, v2.0.1, v3, v3.1.1".versions(),
61-
) shouldBe "new version(s) available: [v2, v3]"
63+
) shouldBe "new version(s) available: [" +
64+
"v2 ([diff](https://github.com/test-owner/test-name/compare/v1...v2#files_bucket)), " +
65+
"v3 ([diff](https://github.com/test-owner/test-name/compare/v1...v3#files_bucket))]"
6266

63-
suggestNewerVersion(
67+
testCoords.suggestNewerVersion(
6468
"v2".versions(),
6569
"v1.1.1, v2, v2.0.1, v3, v3.1.1".versions(),
66-
) shouldBe "new version(s) available: [v3]"
70+
) shouldBe "new version(s) available: [v3 ([diff](https://github.com/test-owner/test-name/compare/v2...v3#files_bucket))]"
6771

68-
suggestNewerVersion(
72+
testCoords.suggestNewerVersion(
6973
"v9".versions(),
7074
"v12, v12.0.1".versions(),
71-
) shouldBe "new version(s) available: [v12]"
75+
) shouldBe "new version(s) available: [v12 ([diff](https://github.com/test-owner/test-name/compare/v9...v12#files_bucket))]"
7276
}
7377
}
7478
}
@@ -85,7 +89,7 @@ class SuggestVersionsTest : FunSpec({
8589
"v1.1.0, v2.1.0",
8690
)
8791
testCases.forAll { available ->
88-
suggestNewerVersion(listOf(currentVersion), available.versions()) shouldBe null
92+
testCoords.suggestNewerVersion(listOf(currentVersion), available.versions()) shouldBe null
8993
}
9094
}
9195
}

0 commit comments

Comments
 (0)