From 5b4c0ca1b454d9349b48865e6042edb35bfd1093 Mon Sep 17 00:00:00 2001 From: Ryan Fogarty Date: Thu, 6 Apr 2023 10:45:04 +0100 Subject: [PATCH] Fix rate limiting issue when downloading flank with no version supplied --- action.yml | 2 +- .../scripts/cli/github/DownloadFlankCommand.kt | 5 ++++- .../flank/scripts/ops/github/DownloadFlank.kt | 8 ++++---- .../flank/scripts/ops/github/DownloadFlankTest.kt | 14 +++++++++----- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/action.yml b/action.yml index e9badbd35e..270dfe3e09 100644 --- a/action.yml +++ b/action.yml @@ -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: | diff --git a/flank-scripts/src/main/kotlin/flank/scripts/cli/github/DownloadFlankCommand.kt b/flank-scripts/src/main/kotlin/flank/scripts/cli/github/DownloadFlankCommand.kt index 744e9fb0d8..fe4532789a 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/cli/github/DownloadFlankCommand.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/cli/github/DownloadFlankCommand.kt @@ -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 @@ -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) } } diff --git a/flank-scripts/src/main/kotlin/flank/scripts/ops/github/DownloadFlank.kt b/flank-scripts/src/main/kotlin/flank/scripts/ops/github/DownloadFlank.kt index 8d789fa521..3148336f13 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/ops/github/DownloadFlank.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/ops/github/DownloadFlank.kt @@ -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" diff --git a/flank-scripts/src/test/kotlin/flank/scripts/ops/github/DownloadFlankTest.kt b/flank-scripts/src/test/kotlin/flank/scripts/ops/github/DownloadFlankTest.kt index 4b0b72c57a..a4d025f7f6 100644 --- a/flank-scripts/src/test/kotlin/flank/scripts/ops/github/DownloadFlankTest.kt +++ b/flank-scripts/src/test/kotlin/flank/scripts/ops/github/DownloadFlankTest.kt @@ -10,15 +10,15 @@ 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) } @@ -26,8 +26,12 @@ class DownloadFlankTest { 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 = "" + } }