diff --git a/flank-scripts/build.gradle.kts b/flank-scripts/build.gradle.kts index 7c164847ed..856a0dd770 100644 --- a/flank-scripts/build.gradle.kts +++ b/flank-scripts/build.gradle.kts @@ -26,7 +26,7 @@ shadowJar.apply { } } // .. -version = "1.9.6" +version = "1.9.7" group = "com.github.flank" application { diff --git a/flank-scripts/src/main/kotlin/flank/scripts/data/github/GithubApi.kt b/flank-scripts/src/main/kotlin/flank/scripts/data/github/GithubApi.kt index 5b66d6c5f2..b4c6d4a567 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/data/github/GithubApi.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/data/github/GithubApi.kt @@ -205,10 +205,12 @@ fun Request.appendGitHubHeaders(githubToken: String, contentType: String = "appl fun githubRepo( token: String, repoPath: String -): Repo = - RtGithub(token) - .repos() - .get(Coordinates.Simple(repoPath)) +): Repo = createGitHubClient(token).repos().get(Coordinates.Simple(repoPath)) + +private fun createGitHubClient(gitHubToken: String) = when { + gitHubToken.isEmpty() -> RtGithub() + else -> RtGithub(gitHubToken) +} fun Repo.getRelease(tag: String): Release.Smart? = Releases.Smart(releases()).run { diff --git a/flank-scripts/src/main/kotlin/flank/scripts/ops/testartifacts/Helpers.kt b/flank-scripts/src/main/kotlin/flank/scripts/ops/testartifacts/Helpers.kt index 5115d399f0..c47eaff8b8 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/ops/testartifacts/Helpers.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/ops/testartifacts/Helpers.kt @@ -17,4 +17,5 @@ val File.testArtifacts: File get() = resolve(TEST_ARTIFACTS_PATH).apply { if (!e fun File.testArtifacts(branch: String = currentGitBranch()): File = testArtifacts.resolve(branch) -internal fun testArtifactsRepo(): Repo = githubRepo(getEnv(GITHUB_TOKEN_ENV_KEY), flankTestArtifactsRepository) +internal fun testArtifactsRepo(): Repo = + githubRepo(getEnv(GITHUB_TOKEN_ENV_KEY, ""), flankTestArtifactsRepository) diff --git a/flank-scripts/src/main/kotlin/flank/scripts/utils/Env.kt b/flank-scripts/src/main/kotlin/flank/scripts/utils/Env.kt index 68ec960e1d..9021796828 100644 --- a/flank-scripts/src/main/kotlin/flank/scripts/utils/Env.kt +++ b/flank-scripts/src/main/kotlin/flank/scripts/utils/Env.kt @@ -1,6 +1,5 @@ package flank.scripts.utils -fun getEnv(key: String): String = - System.getenv(key) ?: throw RuntimeException("Environment variable '$key' not found!") - +fun getEnv(key: String, default: String? = null): String = + System.getenv(key) ?: default ?: throw RuntimeException("Environment variable '$key' not found!") val isWindows: Boolean = System.getProperty("os.name").startsWith("Windows") diff --git a/flank-scripts/src/test/kotlin/flank/scripts/ops/testartifacts/TestArtifactsRepoTest.kt b/flank-scripts/src/test/kotlin/flank/scripts/ops/testartifacts/TestArtifactsRepoTest.kt new file mode 100644 index 0000000000..66adf64bcd --- /dev/null +++ b/flank-scripts/src/test/kotlin/flank/scripts/ops/testartifacts/TestArtifactsRepoTest.kt @@ -0,0 +1,18 @@ +package flank.scripts.ops.testartifacts + +import flank.scripts.data.github.getRelease +import flank.scripts.utils.getEnv +import io.mockk.every +import io.mockk.mockkStatic +import org.junit.Test + +class TestArtifactsRepoTest { + + @Test + fun `should not throw when gh token not set`() { + mockkStatic(::getEnv) + every { getEnv(any(), any()) } returns "" + testArtifactsRepo().getRelease("master") + ?.body()?.toLong() + } +}