Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(abg): do not use double slash for top-level action URL #1599

Merged
merged 1 commit into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public val ActionCoords.repoName: String get() =
* action lives.
*/
public val ActionCoords.subName: String get() =
if (isTopLevel) "" else name.substringAfter("/")
if (isTopLevel) "" else "/${name.substringAfter("/")}"

internal fun String.toActionCoords(): ActionCoords {
val (ownerAndName, version) = this.split('@')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ internal fun ActionCoords.provideTypes(
?: Pair(emptyMap(), null)

private fun ActionCoords.actionTypesYmlUrl(gitRef: String) =
"https://raw.githubusercontent.com/$owner/$repoName/$gitRef/$subName/action-types.yml"
"https://raw.githubusercontent.com/$owner/$repoName/$gitRef$subName/action-types.yml"

private fun ActionCoords.actionTypesFromCatalog() =
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
"main/typings/$owner/$repoName/$version/$subName/action-types.yml"
"main/typings/$owner/$repoName/$version$subName/action-types.yml"

private fun ActionCoords.catalogMetadata() =
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
"main/typings/$owner/$repoName/metadata.yml"

private fun ActionCoords.actionTypesYamlUrl(gitRef: String) =
"https://raw.githubusercontent.com/$owner/$repoName/$gitRef/$subName/action-types.yaml"
"https://raw.githubusercontent.com/$owner/$repoName/$gitRef$subName/action-types.yaml"

private fun ActionCoords.fetchTypingMetadata(
metadataRevision: MetadataRevision,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class TypesProvidingTest :
// Given
val fetchUri: (URI) -> String = {
when (it) {
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash//action-types.yml") -> hostedByActionYml
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/action-types.yml") -> hostedByActionYml
Vampire marked this conversation as resolved.
Show resolved Hide resolved
else -> throw IOException()
}
}
Expand All @@ -116,11 +116,31 @@ class TypesProvidingTest :
types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION)
}

test("only hosted by the subaction (.yml)") {
// Given
val fetchUri: (URI) -> String = {
when (it) {
URI(
"https://raw.githubusercontent.com/some-owner/some-name/some-hash/some-sub/action-types.yml",
),
-> hostedByActionYml
else -> throw IOException()
}
}
val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3")

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

// Then
types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION)
}

test("only hosted by the action (.yaml)") {
// Given
val fetchUri: (URI) -> String = {
when (it) {
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash//action-types.yaml") -> hostedByActionYaml
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/action-types.yaml") -> hostedByActionYaml
else -> throw IOException()
}
}
Expand All @@ -133,12 +153,32 @@ class TypesProvidingTest :
types shouldBe Pair(mapOf("hosted-by-action-yaml" to StringTyping), TypingActualSource.ACTION)
}

test("only hosted by the subaction (.yaml)") {
// Given
val fetchUri: (URI) -> String = {
when (it) {
URI(
"https://raw.githubusercontent.com/some-owner/some-name/some-hash/some-sub/action-types.yaml",
),
-> hostedByActionYaml
else -> throw IOException()
}
}
val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3")

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

// Then
types shouldBe Pair(mapOf("hosted-by-action-yaml" to StringTyping), TypingActualSource.ACTION)
}

test("only hosted by the action, both extensions") {
// Given
val fetchUri: (URI) -> String = {
when (it) {
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash//action-types.yml") -> hostedByActionYml
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash//action-types.yaml") -> hostedByActionYaml
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/action-types.yml") -> hostedByActionYml
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/action-types.yaml") -> hostedByActionYaml
else -> throw IOException()
}
}
Expand All @@ -151,13 +191,37 @@ class TypesProvidingTest :
types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION)
}

test("only hosted by the subaction, both extensions") {
// Given
val fetchUri: (URI) -> String = {
when (it) {
URI(
"https://raw.githubusercontent.com/some-owner/some-name/some-hash/some-sub/action-types.yml",
),
-> hostedByActionYml
URI(
"https://raw.githubusercontent.com/some-owner/some-name/some-hash/some-sub/action-types.yaml",
),
-> hostedByActionYaml
else -> throw IOException()
}
}
val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3")

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

// Then
types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION)
}

test("only stored in typing catalog") {
// Given
val fetchUri: (URI) -> String = {
when (it) {
URI(
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
"main/typings/some-owner/some-name/v3//action-types.yml",
"main/typings/some-owner/some-name/v3/action-types.yml",
),
-> storedInTypingCatalog
else -> throw IOException()
Expand All @@ -172,18 +236,39 @@ class TypesProvidingTest :
types shouldBe Pair(mapOf("stored-in-typing-catalog" to StringTyping), TypingActualSource.TYPING_CATALOG)
}

test("only stored in typing catalog for subaction") {
// Given
val fetchUri: (URI) -> String = {
when (it) {
URI(
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
"main/typings/some-owner/some-name/v3/some-sub/action-types.yml",
),
-> storedInTypingCatalog
else -> throw IOException()
}
}
val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3")

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

// Then
types shouldBe Pair(mapOf("stored-in-typing-catalog" to StringTyping), TypingActualSource.TYPING_CATALOG)
}

test("hosted by action and stored in typing catalog") {
// Given
val fetchUri: (URI) -> String = {
when (it) {
URI(
"https://raw.githubusercontent.com/some-owner/some-name/" +
"some-hash//action-types.yml",
"some-hash/action-types.yml",
),
-> hostedByActionYml
URI(
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
"main/typings/some-owner/some-name/v3//action-types.yml",
"main/typings/some-owner/some-name/v3/action-types.yml",
),
-> storedInTypingCatalog
else -> throw IOException()
Expand All @@ -198,6 +283,32 @@ class TypesProvidingTest :
types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION)
}

test("hosted by subaction and stored in typing catalog") {
// Given
val fetchUri: (URI) -> String = {
when (it) {
URI(
"https://raw.githubusercontent.com/some-owner/some-name/" +
"some-hash/some-sub/action-types.yml",
),
-> hostedByActionYml
URI(
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
"main/typings/some-owner/some-name/v3/some-sub/action-types.yml",
),
-> storedInTypingCatalog
else -> throw IOException()
}
}
val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v3")

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

// Then
types shouldBe Pair(mapOf("hosted-by-action-yml" to StringTyping), TypingActualSource.ACTION)
}

test("only stored in typing catalog for older version") {
// Given
val fetchUri: (URI) -> String = {
Expand All @@ -209,7 +320,7 @@ class TypesProvidingTest :
-> metadata
URI(
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
"main/typings/some-owner/some-name/v4//action-types.yml",
"main/typings/some-owner/some-name/v4/action-types.yml",
),
-> storedInTypingCatalogForOlderVersion
else -> throw IOException()
Expand All @@ -224,6 +335,32 @@ class TypesProvidingTest :
types shouldBe Pair(mapOf("stored-in-typing-catalog-for-older-version" to StringTyping), TypingActualSource.TYPING_CATALOG)
}

test("only stored in typing catalog for older version of subaction") {
// Given
val fetchUri: (URI) -> String = {
when (it) {
URI(
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
"main/typings/some-owner/some-name/metadata.yml",
),
-> metadata
URI(
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
"main/typings/some-owner/some-name/v4/some-sub/action-types.yml",
),
-> storedInTypingCatalogForOlderVersion
else -> throw IOException()
}
}
val actionCoord = ActionCoords("some-owner", "some-name/some-sub", "v6")

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

// Then
types shouldBe Pair(mapOf("stored-in-typing-catalog-for-older-version" to StringTyping), TypingActualSource.TYPING_CATALOG)
}

test("metadata available but no version available") {
// Given
val fetchUri: (URI) -> String = {
Expand Down Expand Up @@ -288,7 +425,7 @@ class TypesProvidingTest :
// Given
val fetchUri: (URI) -> String = {
when (it) {
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash//action-types.yml") -> typingYml
URI("https://raw.githubusercontent.com/some-owner/some-name/some-hash/action-types.yml") -> typingYml
else -> throw IOException()
}
}
Expand All @@ -315,7 +452,7 @@ class TypesProvidingTest :
when (it) {
URI(
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
"main/typings/some-owner/some-name/v3//action-types.yml",
"main/typings/some-owner/some-name/v3/action-types.yml",
),
-> typingYml
else -> throw IOException()
Expand Down Expand Up @@ -349,7 +486,7 @@ class TypesProvidingTest :
-> metadata
URI(
"https://raw.githubusercontent.com/typesafegithub/github-actions-typing-catalog/" +
"main/typings/some-owner/some-name/v4//action-types.yml",
"main/typings/some-owner/some-name/v4/action-types.yml",
),
-> typingYml
else -> throw IOException()
Expand Down
Loading