diff --git a/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/RequestParsing.kt b/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/RequestParsing.kt index 56770914c..d3feaf653 100644 --- a/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/RequestParsing.kt +++ b/jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/RequestParsing.kt @@ -31,24 +31,7 @@ fun Parameters.parseRequest(extractVersion: Boolean): BindingsServerRequest? { .drop(1) .joinToString("/") .takeUnless { it.isBlank() } - val version = - if (extractVersion) { - val versionPart = this["version"]!! - if (significantVersion == COMMIT_LENIENT) { - val versionParts = versionPart.split("__") - if (versionParts.size < 2) { - return null - } - versionParts[1] - } else { - versionPart - } - } else { - "irrelevant" - } - val comment = - if ((significantVersion == COMMIT_LENIENT) && extractVersion) this["version"]!!.split("__")[0] else null - val versionForTypings = if (extractVersion) this["version"]!!.split("__")[0] else "irrelevant" + val parsedVersion = parseVersion(extractVersion, significantVersion) return BindingsServerRequest( rawName = this["name"]!!, @@ -57,11 +40,47 @@ fun Parameters.parseRequest(extractVersion: Boolean): BindingsServerRequest? { ActionCoords( owner = owner, name = name, - version = version, - versionForTypings = versionForTypings, + version = parsedVersion.version ?: return null, + versionForTypings = parsedVersion.versionForTypings!!, significantVersion = significantVersion, path = path, - comment = comment, + comment = parsedVersion.comment, ), ) } + +private fun Parameters.parseVersion( + extractVersion: Boolean, + significantVersion: SignificantVersion, +): ParsedVersion = + if (extractVersion) { + val versionPart = this["version"]!! + val (version, comment) = + if (significantVersion == COMMIT_LENIENT) { + val versionParts = versionPart.split("__", limit = 2) + if (versionParts.size == 1) { + null to null + } else { + versionParts[1] to versionParts[0] + } + } else { + versionPart to null + } + ParsedVersion( + version = version, + comment = comment, + versionForTypings = comment ?: version, + ) + } else { + ParsedVersion( + version = "irrelevant", + comment = null, + versionForTypings = "irrelevant", + ) + } + +private data class ParsedVersion( + val version: String?, + val comment: String?, + val versionForTypings: String?, +)