Repository: typesafegithub/github-workflows-kt
Pull request #1024 (2023-10-14 19:31:56)

[#941] refactor: inline text-utils module
Another step towards making action-binding-generator a deployable library.


Patch:
diff --git a/automation/action-binding-generator/build.gradle.kts b/automation/action-binding-generator/build.gradle.kts
index 0d21db3a5..32c217bcc 100644
--- a/automation/action-binding-generator/build.gradle.kts
+++ b/automation/action-binding-generator/build.gradle.kts
@@ -9,7 +9,6 @@ plugins {
 
 dependencies {
     implementation(projects.automation.typings)
-    implementation(projects.automation.textUtils)
     implementation("com.squareup:kotlinpoet:1.14.2")
     implementation("com.charleskorn.kaml:kaml:0.55.0")
 
diff --git a/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/ClassNaming.kt b/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/ClassNaming.kt
index 47d05bc47..3b3960700 100644
--- a/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/ClassNaming.kt
+++ b/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/ClassNaming.kt
@@ -1,7 +1,6 @@
 package io.github.typesafegithub.workflows.actionbindinggenerator
 
 import io.github.typesafegithub.workflows.actionsmetadata.model.ActionCoords
-import io.github.typesafegithub.workflows.textutils.toPascalCase
 import java.util.Locale
 
 internal fun ActionCoords.buildActionClassName(): String {
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 70e7a203b..5825e14e6 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
@@ -19,7 +19,6 @@ import io.github.typesafegithub.workflows.actionbindinggenerator.Properties.CUST
 import io.github.typesafegithub.workflows.actionsmetadata.model.ActionCoords
 import io.github.typesafegithub.workflows.actionsmetadata.model.StringTyping
 import io.github.typesafegithub.workflows.actionsmetadata.model.Typing
-import io.github.typesafegithub.workflows.textutils.toCamelCase
 import java.nio.file.Path
 
 public data class ActionBinding(
diff --git a/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/TextUtils.kt b/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/TextUtils.kt
new file mode 100644
index 000000000..be3347d9f
--- /dev/null
+++ b/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/TextUtils.kt
@@ -0,0 +1,15 @@
+package io.github.typesafegithub.workflows.actionbindinggenerator
+
+import java.util.Locale
+
+internal fun String.toPascalCase(): String {
+    val hasOnlyUppercases = none { it in 'a'..'z' }
+    val normalizedString = if (hasOnlyUppercases) lowercase() else this
+    return normalizedString.replace("+", "-plus-")
+        .split("-", "_", " ", ".", "/")
+        .joinToString("") {
+            it.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
+        }
+}
+
+internal fun String.toCamelCase(): String = toPascalCase().replaceFirstChar { it.lowercase() }
diff --git a/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/TypesProviding.kt b/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/TypesProviding.kt
index 8462b1494..ff8f3e87d 100644
--- a/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/TypesProviding.kt
+++ b/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/TypesProviding.kt
@@ -13,7 +13,6 @@ import io.github.typesafegithub.workflows.actionsmetadata.model.IntegerWithSpeci
 import io.github.typesafegithub.workflows.actionsmetadata.model.ListOfTypings
 import io.github.typesafegithub.workflows.actionsmetadata.model.StringTyping
 import io.github.typesafegithub.workflows.actionsmetadata.model.Typing
-import io.github.typesafegithub.workflows.textutils.toPascalCase
 import kotlinx.serialization.decodeFromString
 import java.io.File
 import java.io.IOException
diff --git a/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/TypingGeneration.kt b/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/TypingGeneration.kt
index 3985e0567..2d29c73d3 100644
--- a/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/TypingGeneration.kt
+++ b/automation/action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/TypingGeneration.kt
@@ -19,7 +19,6 @@ import io.github.typesafegithub.workflows.actionsmetadata.model.IntegerWithSpeci
 import io.github.typesafegithub.workflows.actionsmetadata.model.ListOfTypings
 import io.github.typesafegithub.workflows.actionsmetadata.model.StringTyping
 import io.github.typesafegithub.workflows.actionsmetadata.model.Typing
-import io.github.typesafegithub.workflows.textutils.toPascalCase
 
 internal fun Typing.getClassName(
     actionPackageName: String,
diff --git a/automation/code-generator/build.gradle.kts b/automation/code-generator/build.gradle.kts
index 11a6a6537..1e4ba316b 100644
--- a/automation/code-generator/build.gradle.kts
+++ b/automation/code-generator/build.gradle.kts
@@ -18,7 +18,6 @@ dependencies {
 
     implementation(projects.automation.typings)
     implementation(projects.automation.actionBindingGenerator)
-    implementation(projects.automation.textUtils)
 
     testImplementation(projects.library)
 }
diff --git a/automation/code-generator/src/main/kotlin/io/github/typesafegithub/workflows/dsl/expressions/GenerateEventPayloads.kt b/automation/code-generator/src/main/kotlin/io/github/typesafegithub/workflows/dsl/expressions/GenerateEventPayloads.kt
index 6d0834462..feaf1c5bb 100644
--- a/automation/code-generator/src/main/kotlin/io/github/typesafegithub/workflows/dsl/expressions/GenerateEventPayloads.kt
+++ b/automation/code-generator/src/main/kotlin/io/github/typesafegithub/workflows/dsl/expressions/GenerateEventPayloads.kt
@@ -8,7 +8,6 @@ import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
 import com.squareup.kotlinpoet.PropertySpec
 import com.squareup.kotlinpoet.TypeSpec
 import com.squareup.kotlinpoet.asClassName
-import io.github.typesafegithub.workflows.textutils.toPascalCase
 import kotlinx.serialization.json.Json
 import kotlinx.serialization.json.JsonArray
 import kotlinx.serialization.json.JsonElement
diff --git a/automation/text-utils/src/main/kotlin/io/github/typesafegithub/workflows/textutils/TextUtils.kt b/automation/code-generator/src/main/kotlin/io/github/typesafegithub/workflows/dsl/expressions/TextUtils.kt
similarity index 66%
rename from automation/text-utils/src/main/kotlin/io/github/typesafegithub/workflows/textutils/TextUtils.kt
rename to automation/code-generator/src/main/kotlin/io/github/typesafegithub/workflows/dsl/expressions/TextUtils.kt
index 42ff933f2..80f3da149 100644
--- a/automation/text-utils/src/main/kotlin/io/github/typesafegithub/workflows/textutils/TextUtils.kt
+++ b/automation/code-generator/src/main/kotlin/io/github/typesafegithub/workflows/dsl/expressions/TextUtils.kt
@@ -1,8 +1,8 @@
-package io.github.typesafegithub.workflows.textutils
+package io.github.typesafegithub.workflows.dsl.expressions
 
 import java.util.Locale
 
-fun String.toPascalCase(): String {
+internal fun String.toPascalCase(): String {
     val hasOnlyUppercases = none { it in 'a'..'z' }
     val normalizedString = if (hasOnlyUppercases) lowercase() else this
     return normalizedString.replace("+", "-plus-")
@@ -12,4 +12,4 @@ fun String.toPascalCase(): String {
         }
 }
 
-fun String.toCamelCase() = toPascalCase().replaceFirstChar { it.lowercase() }
+internal fun String.toCamelCase(): String = toPascalCase().replaceFirstChar { it.lowercase() }
diff --git a/automation/metadata-reading/build.gradle.kts b/automation/metadata-reading/build.gradle.kts
deleted file mode 100644
index c05b0c903..000000000
--- a/automation/metadata-reading/build.gradle.kts
+++ /dev/null
@@ -1,9 +0,0 @@
-plugins {
-    buildsrc.convention.`kotlin-jvm`
-    kotlin("plugin.serialization")
-}
-
-dependencies {
-    implementation(projects.automation.typings)
-    implementation("com.charleskorn.kaml:kaml:0.55.0")
-}
diff --git a/automation/text-utils/build.gradle.kts b/automation/text-utils/build.gradle.kts
deleted file mode 100644
index f4c51404e..000000000
--- a/automation/text-utils/build.gradle.kts
+++ /dev/null
@@ -1,3 +0,0 @@
-plugins {
-    buildsrc.convention.`kotlin-jvm`
-}
diff --git a/settings.gradle.kts b/settings.gradle.kts
index ba34c1607..6b161fb2d 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -7,7 +7,6 @@ include(
     ":automation:typings",
     ":automation:code-generator",
     ":automation:action-binding-generator",
-    ":automation:text-utils",
 )
 
 plugins {


Test patch:
diff --git a/automation/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/TextUtilsTest.kt b/automation/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/TextUtilsTest.kt
new file mode 100644
index 000000000..13c762c8f
--- /dev/null
+++ b/automation/action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/TextUtilsTest.kt
@@ -0,0 +1,35 @@
+package io.github.typesafegithub.workflows.actionbindinggenerator
+
+import io.kotest.core.spec.style.FunSpec
+import io.kotest.matchers.shouldBe
+
+class TextUtilsTest : FunSpec({
+    context("toPascalCase") {
+        listOf(
+            "some-name" to "SomeName",
+            "some_name" to "SomeName",
+            "SOME_PROPERTY" to "SomeProperty",
+            "some+name" to "SomePlusName",
+            "some name with spaces" to "SomeNameWithSpaces",
+            "some.name.with.dots" to "SomeNameWithDots",
+            "some-action/some-subdirectory" to "SomeActionSomeSubdirectory",
+        ).forEach { (input, output) ->
+            test("should convert '$input' to '$output'") {
+                input.toPascalCase() shouldBe output
+            }
+        }
+    }
+
+    context("toCamelCase") {
+        listOf(
+            "some-name" to "someName",
+            "some_name" to "someName",
+            "some+name" to "somePlusName",
+            "SOME_NAME" to "someName",
+        ).forEach { (input, output) ->
+            test("should convert '$input' to '$output'") {
+                input.toCamelCase() shouldBe output
+            }
+        }
+    }
+})
diff --git a/automation/text-utils/src/test/kotlin/io/github/typesafegithub/workflows/textutils/TextUtilsTest.kt b/automation/code-generator/src/test/kotlin/io/github/typesafegithub/workflows/dsl/expressions/TextUtilsTest.kt
similarity index 94%
rename from automation/text-utils/src/test/kotlin/io/github/typesafegithub/workflows/textutils/TextUtilsTest.kt
rename to automation/code-generator/src/test/kotlin/io/github/typesafegithub/workflows/dsl/expressions/TextUtilsTest.kt
index 978c0e149..dca3327ea 100644
--- a/automation/text-utils/src/test/kotlin/io/github/typesafegithub/workflows/textutils/TextUtilsTest.kt
+++ b/automation/code-generator/src/test/kotlin/io/github/typesafegithub/workflows/dsl/expressions/TextUtilsTest.kt
@@ -1,4 +1,4 @@
-package io.github.typesafegithub.workflows.textutils
+package io.github.typesafegithub.workflows.dsl.expressions
 
 import io.kotest.core.spec.style.FunSpec
 import io.kotest.matchers.shouldBe