Skip to content

Commit

Permalink
Fix rate limiting issue when downloading flank with no version supplied
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Fogarty committed Apr 6, 2023
1 parent d410932 commit 78563e1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
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 = ""
}
}

0 comments on commit 78563e1

Please sign in to comment.