Skip to content

Commit 3863fed

Browse files
Vampirekrzema12
andauthored
fix(server): use fallback typings for non-major version and pinned commits (#2252)
Fixes #2253 --------- Co-authored-by: Piotr Krzemiński <3110813+krzema12@users.noreply.github.com> Co-authored-by: Piotr Krzeminski <git@krzeminski.it>
1 parent eb563eb commit 3863fed

2 files changed

Lines changed: 17 additions & 25 deletions

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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal suspend fun ActionCoords.provideTypes(
3030
): ActionTypings =
3131
(
3232
this.fetchTypingMetadata(metadataRevision, httpClient)
33-
?: this.toMajorVersion().fetchFromTypingsFromCatalog(httpClient)
33+
?: this.toMajorVersionForTypings().fetchFromTypingsFromCatalog(httpClient)
3434
)?.let { (typings, typingActualSource) ->
3535
ActionTypings(
3636
inputTypings = typings.toTypesMap(),
@@ -49,7 +49,7 @@ private const val CATALOG_BASE_URL =
4949
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/main/typings"
5050

5151
private fun ActionCoords.actionTypesFromCatalog() =
52-
"$CATALOG_BASE_URL/${owner.lowercase()}/${name.lowercase()}/$version$subName/action-types.yml"
52+
"$CATALOG_BASE_URL/${owner.lowercase()}/${name.lowercase()}/$versionForTypings$subName/action-types.yml"
5353

5454
private fun ActionCoords.catalogMetadata() = "$CATALOG_BASE_URL/${owner.lowercase()}/${name.lowercase()}/metadata.yml"
5555

@@ -115,7 +115,7 @@ private suspend fun ActionCoords.fetchTypingsForOlderVersionFromCatalog(httpClie
115115
return null
116116
}
117117
logger.info { " ... using fallback version: $fallbackVersion" }
118-
val adjustedCoords = this.copy(version = fallbackVersion)
118+
val adjustedCoords = this.copy(versionForTypings = fallbackVersion)
119119
return fetchTypingsFromUrl(
120120
url = adjustedCoords.actionTypesFromCatalog(),
121121
httpClient = httpClient,
@@ -151,8 +151,8 @@ internal fun ActionTypes.toTypesMap(): Map<String, Typing> =
151151
value.toTyping(key)
152152
} ?: emptyMap()
153153

154-
private fun ActionCoords.toMajorVersion(): ActionCoords =
155-
this.copy(version = this.versionForTypings.substringBefore("."))
154+
private fun ActionCoords.toMajorVersionForTypings(): ActionCoords =
155+
this.copy(versionForTypings = this.versionForTypings.substringBefore("."))
156156

157157
private fun ActionType.toTyping(fieldName: String): Typing =
158158
when (this.type) {

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

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -633,12 +633,10 @@ class TypesProvidingTest :
633633

634634
// Then
635635
types shouldBe
636-
// This assertion shows an undesired behavior - a result of a regression.
637-
// TODO: fix it in scope of https://github.com/typesafegithub/github-workflows-kt/issues/2253
638636
ActionTypings(
639-
inputTypings = emptyMap(),
640-
source = null,
641-
fromFallbackVersion = false,
637+
inputTypings = mapOf("stored-in-typing-catalog-for-older-version" to StringTyping),
638+
source = TypingActualSource.TYPING_CATALOG,
639+
fromFallbackVersion = true,
642640
)
643641
}
644642

@@ -716,12 +714,10 @@ class TypesProvidingTest :
716714

717715
// Then
718716
types shouldBe
719-
// This assertion shows an undesired behavior - a result of a regression.
720-
// TODO: fix it in scope of https://github.com/typesafegithub/github-workflows-kt/issues/2253
721717
ActionTypings(
722-
inputTypings = emptyMap(),
723-
source = null,
724-
fromFallbackVersion = false,
718+
inputTypings = mapOf("stored-in-typing-catalog-for-older-version" to StringTyping),
719+
source = TypingActualSource.TYPING_CATALOG,
720+
fromFallbackVersion = true,
725721
)
726722
}
727723

@@ -832,12 +828,10 @@ class TypesProvidingTest :
832828

833829
// Then
834830
types shouldBe
835-
// This assertion shows an undesired behavior - a result of a regression.
836-
// TODO: fix it in scope of https://github.com/typesafegithub/github-workflows-kt/issues/2253
837831
ActionTypings(
838-
inputTypings = emptyMap(),
839-
source = null,
840-
fromFallbackVersion = false,
832+
inputTypings = mapOf("stored-in-typing-catalog-for-older-version" to StringTyping),
833+
source = TypingActualSource.TYPING_CATALOG,
834+
fromFallbackVersion = true,
841835
)
842836
}
843837

@@ -923,12 +917,10 @@ class TypesProvidingTest :
923917

924918
// Then
925919
types shouldBe
926-
// This assertion shows an undesired behavior - a result of a regression.
927-
// TODO: fix it in scope of https://github.com/typesafegithub/github-workflows-kt/issues/2253
928920
ActionTypings(
929-
inputTypings = emptyMap(),
930-
source = null,
931-
fromFallbackVersion = false,
921+
inputTypings = mapOf("stored-in-typing-catalog-for-older-version" to StringTyping),
922+
source = TypingActualSource.TYPING_CATALOG,
923+
fromFallbackVersion = true,
932924
)
933925
}
934926

0 commit comments

Comments
 (0)