Repository: typesafegithub/github-workflows-kt
Pull request #1252 (2024-02-02 09:21:19)

feat(automation): add links to diffs between major versions
Makes it easier to review what actually changed between the versions.


Patch:
diff --git a/automation/code-generator/src/main/kotlin/io/github/typesafegithub/workflows/codegenerator/versions/SuggestVersions.kt b/automation/code-generator/src/main/kotlin/io/github/typesafegithub/workflows/codegenerator/versions/SuggestVersions.kt
index 2116944ef..9e924fd3b 100644
--- a/automation/code-generator/src/main/kotlin/io/github/typesafegithub/workflows/codegenerator/versions/SuggestVersions.kt
+++ b/automation/code-generator/src/main/kotlin/io/github/typesafegithub/workflows/codegenerator/versions/SuggestVersions.kt
@@ -36,7 +36,7 @@ suspend fun main() {
 
     for ((coords, existingVersions) in actionsMap) {
         val available = coords.fetchAvailableVersions(githubAuthorization)
-        suggestNewerVersion(existingVersions, available)?.let { message ->
+        coords.suggestNewerVersion(existingVersions, available)?.let { message ->
             val outputForAction = "$message for ${coords.prettyPrint}"
             println(outputForAction)
             output += "$outputForAction\n"
@@ -60,7 +60,7 @@ fun List<GithubRef>.versions(): List<Version> =
         Version(version)
     }
 
-fun suggestNewerVersion(
+fun ActionCoords.suggestNewerVersion(
     existingVersions: List<Version>,
     availableVersions: List<Version>,
 ): String? {
@@ -77,6 +77,13 @@ fun suggestNewerVersion(
             .filter { it.isMajorVersion() }
             .sorted()
 
-    val newerMajorVersions = majorVersions.filter { it > maxExisting }.sorted()
+    val newerMajorVersions =
+        majorVersions.filter { it > maxExisting }.sorted()
+            .map { "$it ([diff](${this.buildGitHubComparisonUrl(maxExisting, it)}))" }
     return "new version(s) available: $newerMajorVersions".takeIf { newerMajorVersions.isNotEmpty() }
 }
+
+private fun ActionCoords.buildGitHubComparisonUrl(
+    version1: Version,
+    version2: Version,
+): String = "https://github.com/${this.owner}/${this.name}/compare/$version1...$version2#files_bucket"


Test patch:
diff --git a/automation/code-generator/src/test/kotlin/io/github/typesafegithub/workflows/codegenerator/versions/SuggestVersionsTest.kt b/automation/code-generator/src/test/kotlin/io/github/typesafegithub/workflows/codegenerator/versions/SuggestVersionsTest.kt
index 7152fe0f2..aa5489d11 100644
--- a/automation/code-generator/src/test/kotlin/io/github/typesafegithub/workflows/codegenerator/versions/SuggestVersionsTest.kt
+++ b/automation/code-generator/src/test/kotlin/io/github/typesafegithub/workflows/codegenerator/versions/SuggestVersionsTest.kt
@@ -1,5 +1,6 @@
 package io.github.typesafegithub.workflows.codegenerator.versions
 
+import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
 import io.github.typesafegithub.workflows.codegenerator.model.Version
 import io.kotest.assertions.assertSoftly
 import io.kotest.core.spec.style.FunSpec
@@ -13,6 +14,7 @@ import io.kotest.matchers.shouldBe
 
 class SuggestVersionsTest : FunSpec({
     fun String.versions(): List<Version> = split(", ").filter { it.isNotBlank() }.map { Version(it) }
+    val testCoords = ActionCoords(owner = "test-owner", name = "test-name", version = "v3")
 
     test("Compare versions") {
         val sortedVersions =
@@ -48,27 +50,29 @@ class SuggestVersionsTest : FunSpec({
                     row("v12", "v9"),
                 )
             testCases.forAll { current, available ->
-                suggestNewerVersion(current.versions(), available.versions()) shouldBe null
+                testCoords.suggestNewerVersion(current.versions(), available.versions()) shouldBe null
             }
         }
 
         test("New major version") {
             assertSoftly {
 
-                suggestNewerVersion(
+                testCoords.suggestNewerVersion(
                     "v1".versions(),
                     "v1, v1.1.1, v2, v2.0.1, v3, v3.1.1".versions(),
-                ) shouldBe "new version(s) available: [v2, v3]"
+                ) shouldBe "new version(s) available: [" +
+                    "v2 ([diff](https://github.com/test-owner/test-name/compare/v1...v2#files_bucket)), " +
+                    "v3 ([diff](https://github.com/test-owner/test-name/compare/v1...v3#files_bucket))]"
 
-                suggestNewerVersion(
+                testCoords.suggestNewerVersion(
                     "v2".versions(),
                     "v1.1.1, v2, v2.0.1, v3, v3.1.1".versions(),
-                ) shouldBe "new version(s) available: [v3]"
+                ) shouldBe "new version(s) available: [v3 ([diff](https://github.com/test-owner/test-name/compare/v2...v3#files_bucket))]"
 
-                suggestNewerVersion(
+                testCoords.suggestNewerVersion(
                     "v9".versions(),
                     "v12, v12.0.1".versions(),
-                ) shouldBe "new version(s) available: [v12]"
+                ) shouldBe "new version(s) available: [v12 ([diff](https://github.com/test-owner/test-name/compare/v9...v12#files_bucket))]"
             }
         }
     }
@@ -85,7 +89,7 @@ class SuggestVersionsTest : FunSpec({
                     "v1.1.0, v2.1.0",
                 )
             testCases.forAll { available ->
-                suggestNewerVersion(listOf(currentVersion), available.versions()) shouldBe null
+                testCoords.suggestNewerVersion(listOf(currentVersion), available.versions()) shouldBe null
             }
         }
     }