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: rate limiting issue when downloading flank with no version supplied #2360

Merged
merged 4 commits into from
Apr 28, 2023
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
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ runs:
shell: bash
- id: download_flank
run: |
./flankScripts github download_flank --version=${{ inputs.version }}
./flankScripts github download_flank --version=${{ inputs.version }} --token=${{ secrets.GITHUB_TOKEN }}
shell: bash
- id: authentication
run: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package flank.scripts.cli.github

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.options.option
import flank.scripts.ops.github.downloadFlank
import kotlinx.coroutines.runBlocking
Expand All @@ -16,7 +17,9 @@ object DownloadFlankCommand : CliktCommand(
help = "If the version not set, the latest version will be used."
)

private val token by option(help = "Git Token").default("")

override fun run() = runBlocking {
downloadFlank(version)
downloadFlank(version, token)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import com.google.common.annotations.VisibleForTesting
import flank.common.downloadFile
import flank.scripts.data.github.getLatestReleaseTag

suspend fun downloadFlank(version: String?) =
version.getVersion().prepareDownloadUrl().downloadFlank()
suspend fun downloadFlank(version: String?, token: String) =
version.getVersion(token).prepareDownloadUrl().downloadFlank()

@VisibleForTesting
internal suspend fun String?.getVersion(): String =
takeUnless { it.isNullOrBlank() } ?: getLatestReleaseTag("").map { it.tag }.get()
internal suspend fun String?.getVersion(token: String): String =
takeUnless { it.isNullOrBlank() } ?: getLatestReleaseTag(token).map { it.tag }.get()

private fun String.prepareDownloadUrl() = "https://github.com/Flank/flank/releases/download/$this/$FLANK_JAR"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,28 @@ class DownloadFlankTest {

@Test
fun `Should return latest tag if version is null`() {
val downloadedVersion = runBlocking { null.getVersion() }
val latestVersion = runBlocking { getLatestReleaseTag("").map { it.tag }.get() }
val downloadedVersion = runBlocking { null.getVersion(token) }
val latestVersion = runBlocking { getLatestReleaseTag(token).map { it.tag }.get() }
Assert.assertEquals(downloadedVersion, latestVersion)
}

@Test
fun `Should return latest tag if version is empty`() {
val downloadedVersion = runBlocking { "".getVersion() }
val latestVersion = runBlocking { getLatestReleaseTag("").map { it.tag }.get() }
val downloadedVersion = runBlocking { "".getVersion(token) }
val latestVersion = runBlocking { getLatestReleaseTag(token).map { it.tag }.get() }
Assert.assertEquals(downloadedVersion, latestVersion)
}

@Test
fun `Should return specified release tag`() {
val expectedReleaseTag = "v.1.1.1"

val downloadedVersion = runBlocking { expectedReleaseTag.getVersion() }
val downloadedVersion = runBlocking { expectedReleaseTag.getVersion(token) }

Assert.assertEquals(downloadedVersion, expectedReleaseTag)
}

companion object {
private const val token = ""
}
}