Skip to content

Commit

Permalink
Do not force using all GitHub variables with --github mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszwawrzyk committed Apr 18, 2023
1 parent c0ba358 commit c1fab69
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ Read more about personal tokens [here](https://docs.github.com/en/authentication
* Set `--github` flag - Bazel Steward now only works with GitHub as a platform. Without the flag, it will only push the branches, but is not able to check PR status or open/close them.
* Set `GITHUB_TOKEN` env - necessary for PR management
* Set `GITHUB_REPOSITORY` env to your repository location. Example value: `VirtusLab/bazel-steward`
* Optionally set `GITHUB_API_URL` if you are not using the public GitHub. Default is `https://api.github.com`

### Command line arguments
```
Expand Down
18 changes: 13 additions & 5 deletions app/src/main/kotlin/org/virtuslab/bazelsteward/app/AppBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object AppBuilder {

parser.parse(args)

val repositoryRoot = if (github) GithubClient.getRepoPath(env) else Path(repository)
val repositoryRoot = Path(repository).let { if (github) GithubClient.getRepoPath(env, it) else it }
val gitClient = GitClient(repositoryRoot)
val baseBranchName = baseBranch ?: runBlocking {
gitClient.run("rev-parse", "--abbrev-ref", "HEAD").trim()
Expand All @@ -86,16 +86,24 @@ object AppBuilder {
val mavenRepository = MavenRepository()
val updateLogic = UpdateLogic()
val gitOperations = GitOperations(appConfig.workspaceRoot, appConfig.baseBranch)
val gitHostClient =
if (github) GithubClient.getClient(env, appConfig.baseBranch, appConfig.gitAuthor) else GitHostClient.stub
val gitHostClient = if (github) {
GithubClient.getClient(env, appConfig.baseBranch, appConfig.gitAuthor)
} else {
logger.warn {
"""Using stub client for git host. Pull Request management will not work correctly.
|Use --github flag to enable GitHub support. Other Platforms are not supported yet.
""".trimMargin()
}
GitHostClient.stub
}
val bazelRulesExtractor = BazelRulesExtractor()
val bazelUpdater = BazelUpdater()
val gitHubClient = (
val githubApi = (
env["GITHUB_TOKEN"]
?.let(GitHub::connectUsingOAuth)
?: GitHub.connectAnonymously()
)
val githubRulesResolver = GithubRulesResolver(gitHubClient)
val githubRulesResolver = GithubRulesResolver(githubApi)
val fileFinder = FileFinder(appConfig.workspaceRoot)

val dependencyKinds = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,15 @@ class GithubClient private constructor(

companion object {
fun getClient(env: Environment, baseBranch: String, gitAuthor: GitClient.GitAuthor): GithubClient {
val url = env.getOrThrow("GITHUB_API_URL")
val url = env.getOrDefault("GITHUB_API_URL", "https://api.github.com")
val repository = env.getOrThrow("GITHUB_REPOSITORY")
val token = env.getOrThrow("GITHUB_TOKEN")
val personalToken = env["PERSONAL_TOKEN"].let { if (it.isNullOrBlank()) null else it }
return GithubClient(url, baseBranch, gitAuthor, repository, token, personalToken)
}

fun getRepoPath(env: Environment): Path {
val workspace = env.getOrThrow("GITHUB_WORKSPACE")
return Path(workspace)
fun getRepoPath(env: Environment, fallback: Path): Path {
return env["GITHUB_WORKSPACE"]?.let { Path(it) } ?: fallback
}
}
}

0 comments on commit c1fab69

Please sign in to comment.