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 5333aaf838..c61b59b225 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ github-api - 1.50 + 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 @@ -92,6 +92,12 @@ 3.1.0.201310021548-r test + + com.squareup.okhttp + okhttp + 1.5.3 + true + @@ -115,4 +121,11 @@ + + + The MIT license + http://www.opensource.org/licenses/mit-license.php + repo + + 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. */ 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 { 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..6cff72dc53 --- /dev/null +++ b/src/main/java/org/kohsuke/github/HttpConnector.java @@ -0,0 +1,29 @@ +package org.kohsuke.github; + +import java.io.IOException; +import java.net.HttpURLConnection; +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 { + /** + * 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 fa9bc3191c..ef42a6e02f 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 = 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); + } +} 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