From 40d8f4a352d57dbb214759d32c6f38ffbeb2914d Mon Sep 17 00:00:00 2001 From: iraleigh Date: Tue, 24 Oct 2017 14:24:25 -0700 Subject: [PATCH 1/3] Fixed OAuth connection to enterprise API --- src/main/java/org/kohsuke/github/GitHub.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 62c1b4e80c..7eabda9a54 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -178,6 +178,10 @@ public static GitHub connectToEnterprise(String apiUrl, String oauthAccessToken) return new GitHubBuilder().withEndpoint(apiUrl).withOAuthToken(oauthAccessToken).build(); } + public static GitHub connectToEnterpriseWtihOAuth(String apiUrl, String login, String oauthAccessToken) throws IOException { + return new GitHubBuilder().withEndpoint(apiUrl).withOAuthToken(oauthAccessToken, login).build(); + } + public static GitHub connectToEnterprise(String apiUrl, String login, String password) throws IOException { return new GitHubBuilder().withEndpoint(apiUrl).withPassword(login, password).build(); } From 46dce17abc958dcb70b5a655d6931c13f6ecf9a9 Mon Sep 17 00:00:00 2001 From: iraleigh Date: Tue, 24 Oct 2017 14:53:23 -0700 Subject: [PATCH 2/3] Fixed Typo --- src/main/java/org/kohsuke/github/GitHub.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index 7eabda9a54..c486445ce1 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -178,7 +178,7 @@ public static GitHub connectToEnterprise(String apiUrl, String oauthAccessToken) return new GitHubBuilder().withEndpoint(apiUrl).withOAuthToken(oauthAccessToken).build(); } - public static GitHub connectToEnterpriseWtihOAuth(String apiUrl, String login, String oauthAccessToken) throws IOException { + public static GitHub connectToEnterpriseWithOAuth(String apiUrl, String login, String oauthAccessToken) throws IOException { return new GitHubBuilder().withEndpoint(apiUrl).withOAuthToken(oauthAccessToken, login).build(); } From 4849619d679d3f94d1637aa99229714372e33a72 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Sat, 28 Oct 2017 07:54:41 -0700 Subject: [PATCH 3/3] None of the connectToEnterprise methods are preferrable so document accordingly --- src/main/java/org/kohsuke/github/GitHub.java | 20 +++++++++++++++---- .../org/kohsuke/github/GitHubBuilder.java | 6 ++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index c486445ce1..60fe15e493 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -166,6 +166,16 @@ public static GitHub connect() throws IOException { return GitHubBuilder.fromCredentials().build(); } + /** + * Version that connects to GitHub Enterprise. + * + * @deprecated + * Use {@link #connectToEnterpriseWithOAuth(String, String, String)} + */ + public static GitHub connectToEnterprise(String apiUrl, String oauthAccessToken) throws IOException { + return connectToEnterpriseWithOAuth(apiUrl,null,oauthAccessToken); + } + /** * Version that connects to GitHub Enterprise. * @@ -174,14 +184,16 @@ public static GitHub connect() throws IOException { * "http://ghe.acme.com/api/v3". Note that GitHub Enterprise has /api/v3 in the URL. * For historical reasons, this parameter still accepts the bare domain name, but that's considered deprecated. */ - public static GitHub connectToEnterprise(String apiUrl, String oauthAccessToken) throws IOException { - return new GitHubBuilder().withEndpoint(apiUrl).withOAuthToken(oauthAccessToken).build(); - } - public static GitHub connectToEnterpriseWithOAuth(String apiUrl, String login, String oauthAccessToken) throws IOException { return new GitHubBuilder().withEndpoint(apiUrl).withOAuthToken(oauthAccessToken, login).build(); } + /** + * Version that connects to GitHub Enterprise. + * + * @deprecated + * Use with caution. Login with password is not a preferred method. + */ public static GitHub connectToEnterprise(String apiUrl, String login, String password) throws IOException { return new GitHubBuilder().withEndpoint(apiUrl).withPassword(login, password).build(); } diff --git a/src/main/java/org/kohsuke/github/GitHubBuilder.java b/src/main/java/org/kohsuke/github/GitHubBuilder.java index 62a99a6272..e54359892c 100644 --- a/src/main/java/org/kohsuke/github/GitHubBuilder.java +++ b/src/main/java/org/kohsuke/github/GitHubBuilder.java @@ -154,6 +154,12 @@ public static GitHubBuilder fromProperties(Properties props) { return self; } + /** + * @param endpoint + * The URL of GitHub (or GitHub enterprise) API endpoint, such as "https://api.github.com" or + * "http://ghe.acme.com/api/v3". Note that GitHub Enterprise has /api/v3 in the URL. + * For historical reasons, this parameter still accepts the bare domain name, but that's considered deprecated. + */ public GitHubBuilder withEndpoint(String endpoint) { this.endpoint = endpoint; return this;