Skip to content

Commit 396d61b

Browse files
authored
feat(server): add fallback to GITHUB_TOKEN if installation token fails (#1887)
- Attempts to retrieve a GitHub App Installation token first - Falls back to GITHUB_TOKEN if the installation token fails - Logs a warning on failure of installation token retrieval
1 parent 4f501bd commit 396d61b

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

  • shared-internal/src/main/kotlin/io/github/typesafegithub/workflows/shared/internal

shared-internal/src/main/kotlin/io/github/typesafegithub/workflows/shared/internal/GithubUtils.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package io.github.typesafegithub.workflows.shared.internal
22

3+
import io.github.oshai.kotlinlogging.KotlinLogging.logger
34
import kotlinx.coroutines.runBlocking
45

6+
private val logger = logger { }
7+
58
/**
69
* Returns a token that should be used to make authorized calls to GitHub,
710
* or null if no token was configured.
@@ -10,13 +13,10 @@ import kotlinx.coroutines.runBlocking
1013
*/
1114
fun getGithubAuthTokenOrNull(): String? =
1215
runBlocking {
13-
(System.getenv("GITHUB_TOKEN") ?: getInstallationAccessToken())
14-
.also {
15-
if (it == null) {
16-
println(ERROR_NO_CONFIGURATION)
17-
}
18-
}
19-
}
16+
runCatching { getInstallationAccessToken() }
17+
.onFailure { logger.warn(it) { "Failed to get GitHub App Installation token, falling back to GITHUB_TOKEN." } }
18+
.getOrNull() ?: System.getenv("GITHUB_TOKEN")
19+
}.also { if (it == null) logger.warn { ERROR_NO_CONFIGURATION } }
2020

2121
/**
2222
* Returns a token that should be used to make authorized calls to GitHub,

0 commit comments

Comments
 (0)