Repository: typesafegithub/github-workflows-kt
Pull request #1061 (2023-10-28 10:18:43)

[#1059] fix(abg): do not add imports for nested types


Patch:
diff --git a/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/Generation.kt b/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/Generation.kt
index 19665e0ca..89f8b2ad6 100644
--- a/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/Generation.kt
+++ b/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/Generation.kt
@@ -117,6 +117,14 @@ private fun generateActionBindingSourceCode(
             .build()
     return buildString {
         fileSpec.writeTo(this)
+    }.let {
+        if (generateForScript) {
+            it.lines()
+                .filter { !it.startsWith("import io.github.typesafegithub.workflows.actions.") }
+                .joinToString(separator = "\n")
+        } else {
+            it
+        }
     }
 }
 


Test patch:
diff --git a/automation/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/GenerationTest.kt b/automation/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/GenerationTest.kt
index 7f7248a42..49aa5b8e0 100644
--- a/automation/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/GenerationTest.kt
+++ b/automation/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/GenerationTest.kt
@@ -444,6 +444,10 @@ class GenerationTest : FunSpec({
                 metadataRevision = FromLockfile,
                 metadata = actionManifest,
                 generateForScript = true,
+                inputTypings =
+                    mapOf(
+                        "baz-goo" to EnumTyping(null, listOf("helloworld"), listOf("HelloWorld")),
+                    ),
             )
 
         // then
@@ -488,7 +492,7 @@ class GenerationTest : FunSpec({
                  * with multiline description
                  */
                 @Deprecated("this is deprecated")
-                public val bazGoo: String,
+                public val bazGoo: ActionForScript.BazGoo,
                 /**
                  * Type-unsafe map where you can put any inputs that are not yet supported by the binding
                  */
@@ -502,7 +506,7 @@ class GenerationTest : FunSpec({
                 public constructor(
                     vararg pleaseUseNamedArguments: Unit,
                     fooBar: String,
-                    bazGoo: String,
+                    bazGoo: ActionForScript.BazGoo,
                     _customInputs: Map<String, String> = mapOf(),
                     _customVersion: String? = null,
                 ) : this(fooBar=fooBar, bazGoo=bazGoo, _customInputs=_customInputs,
@@ -512,12 +516,22 @@ class GenerationTest : FunSpec({
                 override fun toYamlArguments(): LinkedHashMap<String, String> = linkedMapOf(
                     *listOfNotNull(
                         "foo-bar" to fooBar,
-                        "baz-goo" to bazGoo,
+                        "baz-goo" to bazGoo.stringValue,
                         *_customInputs.toList().toTypedArray(),
                     ).toTypedArray()
                 )
 
                 override fun buildOutputObject(stepId: String): Action.Outputs = Outputs(stepId)
+
+                public sealed class BazGoo(
+                    public val stringValue: String,
+                ) {
+                    public object HelloWorld : ActionForScript.BazGoo("helloworld")
+
+                    public class Custom(
+                        customStringValue: String,
+                    ) : ActionForScript.BazGoo(customStringValue)
+                }
             }
 
             """.trimIndent()