Skip to content

Commit 9371f47

Browse files
authored
fix(abg): properly handle types manifest with only comments (#1793)
1 parent 6902142 commit 9371f47

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

  • action-binding-generator/src
    • main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/typing
    • test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/typing

action-binding-generator/src/main/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/typing/TypesProviding.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.typesafegithub.workflows.actionbindinggenerator.typing
22

33
import com.charleskorn.kaml.AnchorsAndAliases
4+
import com.charleskorn.kaml.EmptyYamlDocumentException
45
import com.charleskorn.kaml.Yaml
56
import io.github.oshai.kotlinlogging.KotlinLogging.logger
67
import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords
@@ -150,7 +151,14 @@ private inline fun <reified T> Yaml.decodeFromStringOrDefaultIfEmpty(
150151
default: T,
151152
): T =
152153
if (text.isNotBlank()) {
153-
decodeFromString(text)
154+
runCatching {
155+
decodeFromString<T>(text)
156+
}.getOrElse {
157+
if (it is EmptyYamlDocumentException) {
158+
return default
159+
}
160+
throw it
161+
}
154162
} else {
155163
default
156164
}

action-binding-generator/src/test/kotlin/io/github/typesafegithub/workflows/actionbindinggenerator/typing/TypesProvidingTest.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,30 @@ import java.net.URI
1212

1313
class TypesProvidingTest :
1414
FunSpec({
15+
test("copes with blank typing") {
16+
// Given
17+
val actionTypesYml = " "
18+
val actionCoord = ActionCoords("some-owner", "some-name", "v1")
19+
20+
// When
21+
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), { actionTypesYml })
22+
23+
// Then
24+
types.first shouldBe emptyMap()
25+
}
26+
27+
test("copes with comment-only typing") {
28+
// Given
29+
val actionTypesYml = "#"
30+
val actionCoord = ActionCoords("some-owner", "some-name", "v1")
31+
32+
// When
33+
val types = actionCoord.provideTypes(metadataRevision = CommitHash("some-hash"), { actionTypesYml })
34+
35+
// Then
36+
types.first shouldBe emptyMap()
37+
}
38+
1539
test("parses all allowed elements of valid typing") {
1640
// Given
1741
val actionTypesYml =

0 commit comments

Comments
 (0)