From 9f5ab709dec0993f6b63fa56a077789c9792d3a2 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 28 Mar 2014 10:59:51 -0700 Subject: [PATCH 01/10] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5333aaf838..d6c843bfe9 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.50 + 1.51-SNAPSHOT GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java From cef8f74c0068231d0de77f52546c2fa61b151545 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Wed, 2 Apr 2014 09:31:02 -0700 Subject: [PATCH 02/10] Added LICENSE --- LICENSE.txt | 22 ++++++++++++++++++++++ pom.xml | 7 +++++++ 2 files changed, 29 insertions(+) create mode 100644 LICENSE.txt diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000000..a12243f2fc --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,22 @@ + Copyright (c) 2011- Kohsuke Kawaguchi and other contributors + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following + conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. diff --git a/pom.xml b/pom.xml index d6c843bfe9..24ab072272 100644 --- a/pom.xml +++ b/pom.xml @@ -115,4 +115,11 @@ + + + The MIT license + http://www.opensource.org/licenses/mit-license.php + repo + + From 769cdc73e76a4a7c07d4cf8fe8edb686977f4276 Mon Sep 17 00:00:00 2001 From: Roberto Tyley Date: Wed, 2 Apr 2014 18:45:23 +0100 Subject: [PATCH 03/10] Add support for removing a user from an Organisation --- src/main/java/org/kohsuke/github/GHOrganization.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/org/kohsuke/github/GHOrganization.java b/src/main/java/org/kohsuke/github/GHOrganization.java index b354d486dd..8501ba3763 100644 --- a/src/main/java/org/kohsuke/github/GHOrganization.java +++ b/src/main/java/org/kohsuke/github/GHOrganization.java @@ -57,6 +57,14 @@ public boolean hasMember(GHUser user) { } } + /** + * Remove a member of the organisation - which will remove them from + * all teams, and remove their access to the organization’s repositories. + */ + public void remove(GHUser user) throws IOException { + root.retrieve().method("DELETE").to("/orgs/" + login + "/members/" + user.getLogin()); + } + /** * Checks if this organization has the specified user as a public member. */ From 3f8c8be77a7d3b7c416021e16bf15ecc1d26be15 Mon Sep 17 00:00:00 2001 From: Prasanna Rajaperumal Date: Wed, 9 Apr 2014 18:09:23 -0700 Subject: [PATCH 04/10] Cast url.openConnection() to HttpURLConnection instead of HttpsURLConnection. Useful for enterprise githubs which does not have https set up. --- src/main/java/org/kohsuke/github/Requester.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index fa9bc3191c..d1ce69df74 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -25,7 +25,6 @@ import org.apache.commons.io.IOUtils; -import javax.net.ssl.HttpsURLConnection; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -294,7 +293,7 @@ private void findNextURL(HttpURLConnection uc) throws MalformedURLException { private HttpURLConnection setupConnection(URL url) throws IOException { - HttpsURLConnection uc = (HttpsURLConnection) url.openConnection(); + HttpURLConnection uc = (HttpURLConnection) url.openConnection(); // if the authentication is needed but no credential is given, try it anyway (so that some calls // that do work with anonymous access in the reduced form should still work.) From a18cde2340d7830c745464e438d164292f868429 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Sun, 13 Apr 2014 08:46:21 -0700 Subject: [PATCH 05/10] Abstracted away HTTP connector and added OkHttp implementation for convenience --- pom.xml | 6 ++++ src/main/java/org/kohsuke/github/GitHub.java | 13 ++++++++ .../org/kohsuke/github/HttpConnector.java | 24 ++++++++++++++ .../java/org/kohsuke/github/Requester.java | 2 +- .../github/extras/OkHttpConnector.java | 31 +++++++++++++++++++ 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/kohsuke/github/HttpConnector.java create mode 100644 src/main/java/org/kohsuke/github/extras/OkHttpConnector.java diff --git a/pom.xml b/pom.xml index 24ab072272..ed2ed3e18f 100644 --- a/pom.xml +++ b/pom.xml @@ -92,6 +92,12 @@ 3.1.0.201310021548-r test + + com.squareup.okhttp + okhttp + 1.5.3 + optional + diff --git a/src/main/java/org/kohsuke/github/GitHub.java b/src/main/java/org/kohsuke/github/GitHub.java index c96c5de43d..167240d529 100644 --- a/src/main/java/org/kohsuke/github/GitHub.java +++ b/src/main/java/org/kohsuke/github/GitHub.java @@ -68,6 +68,8 @@ public class GitHub { private final String apiUrl; + private HttpConnector connector = HttpConnector.DEFAULT; + /** * Connects to GitHub.com */ @@ -201,6 +203,17 @@ public boolean isAnonymous() { return login==null && encodedAuthorization==null; } + public HttpConnector getConnector() { + return connector; + } + + /** + * Sets the custom connector used to make requests to GitHub. + */ + public void setConnector(HttpConnector connector) { + this.connector = connector; + } + /*package*/ void requireCredential() { if (isAnonymous()) throw new IllegalStateException("This operation requires a credential but none is given to the GitHub constructor"); diff --git a/src/main/java/org/kohsuke/github/HttpConnector.java b/src/main/java/org/kohsuke/github/HttpConnector.java new file mode 100644 index 0000000000..45cd34d95a --- /dev/null +++ b/src/main/java/org/kohsuke/github/HttpConnector.java @@ -0,0 +1,24 @@ +package org.kohsuke.github; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; + +/** + * @author Kohsuke Kawaguchi + */ +public interface HttpConnector { + /** + * Opens a connection to the given URL. + */ + HttpURLConnection connect(URL url) throws IOException; + + /** + * Default implementation that uses {@link URL#openConnection()}. + */ + HttpConnector DEFAULT = new HttpConnector() { + public HttpURLConnection connect(URL url) throws IOException { + return (HttpURLConnection) url.openConnection(); + } + }; +} diff --git a/src/main/java/org/kohsuke/github/Requester.java b/src/main/java/org/kohsuke/github/Requester.java index d1ce69df74..ef42a6e02f 100644 --- a/src/main/java/org/kohsuke/github/Requester.java +++ b/src/main/java/org/kohsuke/github/Requester.java @@ -293,7 +293,7 @@ private void findNextURL(HttpURLConnection uc) throws MalformedURLException { private HttpURLConnection setupConnection(URL url) throws IOException { - HttpURLConnection uc = (HttpURLConnection) url.openConnection(); + HttpURLConnection uc = root.getConnector().connect(url); // if the authentication is needed but no credential is given, try it anyway (so that some calls // that do work with anonymous access in the reduced form should still work.) diff --git a/src/main/java/org/kohsuke/github/extras/OkHttpConnector.java b/src/main/java/org/kohsuke/github/extras/OkHttpConnector.java new file mode 100644 index 0000000000..671c32eaca --- /dev/null +++ b/src/main/java/org/kohsuke/github/extras/OkHttpConnector.java @@ -0,0 +1,31 @@ +package org.kohsuke.github.extras; + +import com.squareup.okhttp.OkHttpClient; +import org.kohsuke.github.HttpConnector; + +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.URL; + +/** + * {@link HttpConnector} for {@link OkHttpClient}. + * + * Unlike {@link #DEFAULT}, OkHttp does response caching. + * Making a conditional request against GitHubAPI and receiving a 304 + * response does not count against the rate limit. + * See http://developer.github.com/v3/#conditional-requests + * + * @author Roberto Tyley + * @author Kohsuke Kawaguchi + */ +public class OkHttpConnector implements HttpConnector { + private final OkHttpClient client; + + public OkHttpConnector(OkHttpClient client) { + this.client = client; + } + + public HttpURLConnection connect(URL url) throws IOException { + return client.open(url); + } +} From 74090103a91a6bbb461e7dde1bcbc7489cb38e62 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Sun, 13 Apr 2014 08:48:16 -0700 Subject: [PATCH 06/10] doc improvement --- src/site/markdown/index.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index ba9fbb5287..3956df708a 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -7,6 +7,8 @@ operations that act on them as defined as methods (such as `GHUser.follow()`), a are used in favor of using string handle (such as `GHUser.isMemberOf(GHOrganization)` instead of `GHUser.isMemberOf(String)`) +The library supports both github.com and GitHub Enterprise. + There are some corners of the GitHub API that's not yet implemented, but the library is implemented with the right abstractions and libraries to make it very easy to improve the coverage. @@ -34,3 +36,10 @@ Alternatively, you can have just the OAuth token in this file: oauth=4d98173f7c075527cb64878561d1fe70 +OkHttp +---- +This library comes with a pluggable connector to use different HTTP client implementations +through `HttpConnector`. In particular, this means you can use [OkHttp](http://square.github.io/okhttp/), +so we can make use of it's HTTP response cache. +Making a conditional request against the GitHub API and receiving a 304 response +[does not count against the rate limit](http://developer.github.com/v3/#conditional-requests). \ No newline at end of file From 7993266e6e866a6d6102bce5b397af689d0e002f Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Sun, 13 Apr 2014 08:51:58 -0700 Subject: [PATCH 07/10] This is also useful for setting timeout --- src/main/java/org/kohsuke/github/HttpConnector.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/org/kohsuke/github/HttpConnector.java b/src/main/java/org/kohsuke/github/HttpConnector.java index 45cd34d95a..6cff72dc53 100644 --- a/src/main/java/org/kohsuke/github/HttpConnector.java +++ b/src/main/java/org/kohsuke/github/HttpConnector.java @@ -5,6 +5,11 @@ import java.net.URL; /** + * Pluggability for customizing HTTP request behaviors or using altogether different library. + * + *

+ * For example, you can implement this to st custom timeouts. + * * @author Kohsuke Kawaguchi */ public interface HttpConnector { From 500b9097f749d7c3512d08076ace4993b2a26425 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Sun, 13 Apr 2014 08:53:00 -0700 Subject: [PATCH 08/10] doc improvement --- src/main/java/org/kohsuke/github/GHPullRequest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index c01753988c..75c54611fb 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -33,6 +33,7 @@ * A pull request. * * @author Kohsuke Kawaguchi + * @see GHRepository#getPullRequest(int) */ @SuppressWarnings({"UnusedDeclaration"}) public class GHPullRequest extends GHIssue { From d2c59946160ad6b01fac17cbab8ee17a5eeecdf5 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Sun, 13 Apr 2014 08:57:48 -0700 Subject: [PATCH 09/10] I always get this confused --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ed2ed3e18f..53d464f5f0 100644 --- a/pom.xml +++ b/pom.xml @@ -96,7 +96,7 @@ com.squareup.okhttp okhttp 1.5.3 - optional + true From 8353499d189f4769c3cf873015811746c8212c8e Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Sun, 13 Apr 2014 08:58:49 -0700 Subject: [PATCH 10/10] [maven-release-plugin] prepare release github-api-1.51 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 53d464f5f0..c61b59b225 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.51-SNAPSHOT + 1.51 GitHub API for Java http://github-api.kohsuke.org/ GitHub API for Java @@ -16,7 +16,7 @@ scm:git:git@github.com/kohsuke/${project.artifactId}.git scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git http://${project.artifactId}.kohsuke.org/ - HEAD + github-api-1.51