Skip to content

Commit

Permalink
fix(abg): properly handle types manifest with only comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Jan 22, 2025
1 parent 6902142 commit 7f4ecb9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.typesafegithub.workflows.actionbindinggenerator.typing

import com.charleskorn.kaml.AnchorsAndAliases
import com.charleskorn.kaml.EmptyYamlDocumentException
import com.charleskorn.kaml.Yaml
import io.github.oshai.kotlinlogging.KotlinLogging.logger
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
Expand Down Expand Up @@ -150,7 +151,14 @@ private inline fun <reified T> Yaml.decodeFromStringOrDefaultIfEmpty(
default: T,
): T =
if (text.isNotBlank()) {
decodeFromString(text)
runCatching {
decodeFromString<T>(text)
}.getOrElse {
if (it is EmptyYamlDocumentException) {
return default
}
throw it
}
} else {
default
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,32 @@ import java.net.URI

class TypesProvidingTest :
FunSpec({
test("copes with blank typing") {
// Given
val actionTypesYml = " "
val actionCoord = ActionCoords("some-owner", "some-name", "v1")

// When
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), { actionTypesYml })

// Then
types.first shouldBe emptyMap()
}

test("copes with comment-only typing") {
// Given
val actionTypesYml = """
#
""".trimIndent()
val actionCoord = ActionCoords("some-owner", "some-name", "v1")

// When
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), { actionTypesYml })

// Then
types.first shouldBe emptyMap()
}

test("parses all allowed elements of valid typing") {
// Given
val actionTypesYml =
Expand Down

0 comments on commit 7f4ecb9

Please sign in to comment.