Skip to content

Commit 00223f2

Browse files
committed
Support various YAML extensions
1 parent 6279c01 commit 00223f2

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

composeApp/src/commonMain/kotlin/ManifestFetching.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import com.charleskorn.kaml.Yaml
22
import io.ktor.client.call.body
33
import io.ktor.client.request.get
4+
import io.ktor.http.HttpStatusCode
45
import kotlinx.serialization.decodeFromString
56

67
suspend fun fetchManifest(actionCoords: String): Metadata? {
7-
val yaml = client.get(urlString = "https://raw.githubusercontent.com/${actionCoords.replace("@", "/")}/action.yml")
8-
.body<String>()
8+
val yaml = listOf("yml", "yaml").firstNotNullOfOrNull { extension ->
9+
val response = client
10+
.get(urlString = "https://raw.githubusercontent.com/${actionCoords.replace("@", "/")}/action.$extension")
11+
if (response.status == HttpStatusCode.OK) {
12+
response.body<String>()
13+
} else {
14+
null
15+
}
16+
} ?: return null
17+
918
return try {
1019
myYaml.decodeFromString<Metadata>(yaml)
1120
} catch (e: Exception) {

0 commit comments

Comments
 (0)