Skip to content

Commit 1b1da04

Browse files
authored
refactor: move getGithubToken to shared-internal (#1397)
A step towards having fetching available action versions in shared-internal.
1 parent e11002d commit 1b1da04

File tree

6 files changed

+16
-12
lines changed

6 files changed

+16
-12
lines changed

automation/code-generator/src/main/kotlin/io/github/typesafegithub/workflows/codegenerator/updating/CreateActionUpdatePRs.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import io.github.typesafegithub.workflows.codegenerator.bindingsToGenerate
1010
import io.github.typesafegithub.workflows.codegenerator.model.ActionBindingRequest
1111
import io.github.typesafegithub.workflows.codegenerator.versions.GithubRef
1212
import io.github.typesafegithub.workflows.codegenerator.versions.GithubTag
13-
import io.github.typesafegithub.workflows.codegenerator.versions.getGithubToken
1413
import io.github.typesafegithub.workflows.codegenerator.versions.httpClient
1514
import io.github.typesafegithub.workflows.codegenerator.versions.json
15+
import io.github.typesafegithub.workflows.shared.internal.getGithubToken
1616
import io.ktor.client.request.bearerAuth
1717
import io.ktor.client.request.get
1818
import io.ktor.client.statement.bodyAsText

automation/code-generator/src/main/kotlin/io/github/typesafegithub/workflows/codegenerator/versions/Http.kt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@ val ActionCoords.apiTagsUrl: String
1818
val ActionCoords.apiBranchesUrl: String
1919
get() = "https://api.github.com/repos/$owner/$name/git/matching-refs/heads/v"
2020

21-
fun getGithubToken(): String =
22-
System.getenv("GITHUB_TOKEN")
23-
?: error(
24-
"""
25-
Missing environment variable export GITHUB_TOKEN=token
26-
Create a personal token at https://github.com/settings/tokens
27-
The token needs to have public_repo scope.
28-
""".trimIndent(),
29-
)
30-
3121
@Serializable
3222
data class GithubRef(
3323
val ref: String,

automation/code-generator/src/main/kotlin/io/github/typesafegithub/workflows/codegenerator/versions/SuggestVersions.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import io.github.typesafegithub.workflows.actionbindinggenerator.domain.prettyPr
99
import io.github.typesafegithub.workflows.actionbindinggenerator.metadata.Metadata
1010
import io.github.typesafegithub.workflows.actionbindinggenerator.metadata.fetchMetadata
1111
import io.github.typesafegithub.workflows.codegenerator.bindingsToGenerate
12+
import io.github.typesafegithub.workflows.shared.internal.getGithubToken
1213
import io.github.typesafegithub.workflows.shared.internal.model.Version
1314
import java.io.File
1415

jit-binding-server/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies {
1414
implementation("ch.qos.logback:logback-classic:1.5.6")
1515

1616
implementation(projects.mavenBindingBuilder)
17+
implementation(projects.sharedInternal)
1718
}
1819

1920
application {

jit-binding-server/src/main/kotlin/io/github/typesafegithub/workflows/jitbindingserver/Main.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import io.github.typesafegithub.workflows.mavenbinding.JarArtifact
88
import io.github.typesafegithub.workflows.mavenbinding.TextArtifact
99
import io.github.typesafegithub.workflows.mavenbinding.buildPackageArtifacts
1010
import io.github.typesafegithub.workflows.mavenbinding.buildVersionArtifacts
11+
import io.github.typesafegithub.workflows.shared.internal.getGithubToken
1112
import io.ktor.http.ContentType
1213
import io.ktor.http.HttpStatusCode
1314
import io.ktor.server.application.call
@@ -110,7 +111,7 @@ fun main() {
110111
name = name,
111112
version = "irrelevant",
112113
)
113-
val bindingArtifacts = actionCoords.buildPackageArtifacts(githubToken = System.getenv("GITHUB_TOKEN"))
114+
val bindingArtifacts = actionCoords.buildPackageArtifacts(githubToken = getGithubToken())
114115
if (file in bindingArtifacts) {
115116
when (val artifact = bindingArtifacts[file]) {
116117
is String -> call.respondText(artifact)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package io.github.typesafegithub.workflows.shared.internal
2+
3+
fun getGithubToken(): String =
4+
System.getenv("GITHUB_TOKEN")
5+
?: error(
6+
"""
7+
Missing environment variable export GITHUB_TOKEN=token
8+
Create a personal token at https://github.com/settings/tokens
9+
The token needs to have public_repo scope.
10+
""".trimIndent(),
11+
)

0 commit comments

Comments
 (0)