github-api icon indicating copy to clipboard operation
github-api copied to clipboard

enterprise apiUrl

Open dimmonn opened this issue 4 years ago • 6 comments

org.kohsuke.github.GitHubBuilder#fromProperties() as well as org.kohsuke.github.GitHubBuilder#fromEnvironment() doesn't support custom apiUrl

dimmonn avatar May 09 '20 08:05 dimmonn

Shouldn't fromEnvironment() work if you set the environment variable GITHUB_ENDPOINT? See the code.

Alternatively, you can manually call the method withEndpoint(String).

GithubBuilder builder = new GithubBuilder();
builder.withEndpoint(<your-api-url>);

bmuschko avatar May 15 '20 14:05 bmuschko

@bmuschko The fromEnvironment() builds the GitHub object in one call it doesn't return a builder. So withEndpoint(String) can't be used.

But good catch about GITHUB_ENDPOINT. I didn't even go looking. Do you think we need a change to some documentation or is this just closable?

bitwiseman avatar May 16 '20 05:05 bitwiseman

Shouldn't fromEnvironment() work if you set the environment variable GITHUB_ENDPOINT? See the code.

Alternatively, you can manually call the method withEndpoint(String).

GithubBuilder builder = new GithubBuilder();
builder.withEndpoint(<your-api-url>);

No it doesn't work this way, the url is hardcoded, so whatever url you set in env won't be picked and default hardcoded value is used

dimmonn avatar May 16 '20 06:05 dimmonn

No it doesn't work this way, the url is hardcoded

I guess you are exclusively referring to the environment variable. I use withEndpoint in a code base so I know that works. I understand it's less convenient.

But good catch about GITHUB_ENDPOINT. I didn't even go looking. Do you think we need a change to some documentation or is this just closable?

  1. Write a test case (if it doesn't exist yet) for fromEnvironment to ensure that reading all supported environment variables are picked up properly. @dimmonn Contributing a test case would be a good way forward.
  2. I think the Javadocs are good enough for documenting the supported environment variables.

bmuschko avatar May 16 '20 14:05 bmuschko

@dimmonn

No it doesn't work this way, the url is hardcoded, so whatever url you set in env won't be picked and default hardcoded value is used

This should load the value or default to the hard coded one.

https://github.com/hub4j/github-api/blob/85c44b352958bf6d81b74ab8b21920f1d313a287/src/main/java/org/kohsuke/github/GitHubBuilder.java#L221

But really, as @bmuschko says, tests need to be updated for this.
They are found here: https://github.com/hub4j/github-api/blob/85c44b352958bf6d81b74ab8b21920f1d313a287/src/test/java/org/kohsuke/github/GitHubConnectionTest.java#L55-L93

As a side note, the fromEnvironment() and fromEnvironment(String,,,,,) methods follow independent code paths and have significantly different JavaDocs. Also, we're missing a fromEnvironment(String,,,,,) that includes JWT. This area could use some love. https://github.com/hub4j/github-api/blob/85c44b352958bf6d81b74ab8b21920f1d313a287/src/main/java/org/kohsuke/github/GitHubBuilder.java#L108-L172

@dimmonn - would you be willing to submit a PR for this?

bitwiseman avatar May 18 '20 16:05 bitwiseman

@dimmonn - would you be willing to submit a PR for this?

ill check once will get some time, thanks for info

dimmonn avatar May 18 '20 16:05 dimmonn