mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-11 00:11:25 +00:00
Compare commits
25 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38b77a9c79 | ||
|
|
7d294ee8c2 | ||
|
|
33d9422d03 | ||
|
|
bb7302c23a | ||
|
|
d50ae63a5a | ||
|
|
1961836e19 | ||
|
|
f2ed7c15ce | ||
|
|
4dce173630 | ||
|
|
86f868b2d4 | ||
|
|
363064f5c0 | ||
|
|
9d99ee9cfc | ||
|
|
db8969707d | ||
|
|
a24ac37dfd | ||
|
|
1b04d471b3 | ||
|
|
9cc400a081 | ||
|
|
e233aeec0c | ||
|
|
5dfd621900 | ||
|
|
f0f6a9988f | ||
|
|
8b38a20c18 | ||
|
|
e7b76bfdc5 | ||
|
|
3503ff6d36 | ||
|
|
192e21a9fc | ||
|
|
24e288d584 | ||
|
|
0e5ffda5e5 | ||
|
|
cdf6f18ec0 |
10
pom.xml
10
pom.xml
@@ -7,7 +7,7 @@
|
||||
</parent>
|
||||
|
||||
<artifactId>github-api</artifactId>
|
||||
<version>1.91</version>
|
||||
<version>1.93</version>
|
||||
<name>GitHub API for Java</name>
|
||||
<url>http://github-api.kohsuke.org/</url>
|
||||
<description>GitHub API for Java</description>
|
||||
@@ -16,7 +16,7 @@
|
||||
<connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection>
|
||||
<developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection>
|
||||
<url>http://${project.artifactId}.kohsuke.org/</url>
|
||||
<tag>github-api-1.91</tag>
|
||||
<tag>github-api-1.93</tag>
|
||||
</scm>
|
||||
|
||||
<distributionManagement>
|
||||
@@ -96,9 +96,9 @@
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>2.6</version>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
/**
|
||||
* How is an user associated with a repository?
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public enum GHCommentAuthorAssociation {
|
||||
/**
|
||||
* Author has been invited to collaborate on the repository.
|
||||
*/
|
||||
COLLABORATOR,
|
||||
/**
|
||||
* Author has previously committed to the repository.
|
||||
*/
|
||||
CONTRIBUTOR,
|
||||
/**
|
||||
* Author has not previously committed to GitHub.
|
||||
*/
|
||||
FIRST_TIMER,
|
||||
/**
|
||||
* Author has not previously committed to the repository.
|
||||
*/
|
||||
FIRST_TIME_CONTRIBUTOR,
|
||||
/**
|
||||
* Author is a member of the organization that owns the repository.
|
||||
*/
|
||||
MEMBER,
|
||||
/**
|
||||
* Author has no association with the repository.
|
||||
*/
|
||||
NONE,
|
||||
/**
|
||||
* Author is the owner of the repository.
|
||||
*/
|
||||
OWNER
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -49,6 +48,8 @@ import static org.kohsuke.github.Previews.*;
|
||||
* @see GHIssueSearchBuilder
|
||||
*/
|
||||
public class GHIssue extends GHObject implements Reactable{
|
||||
private static final String ASSIGNEES = "assignees";
|
||||
|
||||
GitHub root;
|
||||
GHRepository owner;
|
||||
|
||||
@@ -268,8 +269,7 @@ public class GHIssue extends GHObject implements Reactable{
|
||||
}
|
||||
|
||||
public void addAssignees(Collection<GHUser> assignees) throws IOException {
|
||||
List<String> names = toLogins(assignees);
|
||||
root.retrieve().method("POST").with("assignees",names).to(getIssuesApiRoute()+"/assignees",this);
|
||||
root.retrieve().method("POST").withLogins(ASSIGNEES,assignees).to(getIssuesApiRoute()+"/assignees",this);
|
||||
}
|
||||
|
||||
public void setAssignees(GHUser... assignees) throws IOException {
|
||||
@@ -277,7 +277,7 @@ public class GHIssue extends GHObject implements Reactable{
|
||||
}
|
||||
|
||||
public void setAssignees(Collection<GHUser> assignees) throws IOException {
|
||||
editIssue("assignees",toLogins(assignees));
|
||||
new Requester(root).withLogins(ASSIGNEES, assignees).method("PATCH").to(getIssuesApiRoute());
|
||||
}
|
||||
|
||||
public void removeAssignees(GHUser... assignees) throws IOException {
|
||||
@@ -285,16 +285,7 @@ public class GHIssue extends GHObject implements Reactable{
|
||||
}
|
||||
|
||||
public void removeAssignees(Collection<GHUser> assignees) throws IOException {
|
||||
List<String> names = toLogins(assignees);
|
||||
root.retrieve().method("DELETE").with("assignees",names).inBody().to(getIssuesApiRoute()+"/assignees",this);
|
||||
}
|
||||
|
||||
private List<String> toLogins(Collection<GHUser> assignees) {
|
||||
List<String> names = new ArrayList<String>(assignees.size());
|
||||
for (GHUser a : assignees) {
|
||||
names.add(a.getLogin());
|
||||
}
|
||||
return names;
|
||||
root.retrieve().method("DELETE").withLogins(ASSIGNEES,assignees).inBody().to(getIssuesApiRoute()+"/assignees",this);
|
||||
}
|
||||
|
||||
protected String getApiRoute() {
|
||||
|
||||
@@ -32,11 +32,13 @@ import static org.kohsuke.github.Previews.*;
|
||||
* Comment to the issue
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
* @see GHIssue#comment(String)
|
||||
* @see GHIssue#listComments()
|
||||
*/
|
||||
public class GHIssueComment extends GHObject implements Reactable {
|
||||
GHIssue owner;
|
||||
|
||||
private String body, gravatar_id;
|
||||
private String body, gravatar_id, html_url, author_association;
|
||||
private GHUser user; // not fully populated. beware.
|
||||
|
||||
/*package*/ GHIssueComment wrapUp(GHIssue owner) {
|
||||
@@ -73,12 +75,13 @@ public class GHIssueComment extends GHObject implements Reactable {
|
||||
return owner == null || owner.root.isOffline() ? user : owner.root.getUser(user.getLogin());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This object has no HTML URL.
|
||||
*/
|
||||
@Override
|
||||
public URL getHtmlUrl() {
|
||||
return null;
|
||||
return GitHub.parseURL(html_url);
|
||||
}
|
||||
|
||||
public GHCommentAuthorAssociation getAuthorAssociation() {
|
||||
return GHCommentAuthorAssociation.valueOf(author_association);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
||||
/**
|
||||
* SSH public key.
|
||||
|
||||
@@ -2,8 +2,8 @@ package org.kohsuke.github;
|
||||
|
||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringStyle;
|
||||
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import javax.annotation.CheckForNull;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -41,6 +41,7 @@ import java.util.List;
|
||||
public class GHPullRequest extends GHIssue {
|
||||
|
||||
private static final String COMMENTS_ACTION = "/comments";
|
||||
private static final String REQUEST_REVIEWERS = "/requested_reviewers";
|
||||
|
||||
private String patch_url, diff_url, issue_url;
|
||||
private GHCommitPointer base;
|
||||
@@ -345,6 +346,12 @@ public class GHPullRequest extends GHIssue {
|
||||
.to(getApiRoute() + COMMENTS_ACTION, GHPullRequestReviewComment.class).wrapUp(this);
|
||||
}
|
||||
|
||||
public void requestReviewers(List<GHUser> reviewers) throws IOException {
|
||||
new Requester(root).method("POST")
|
||||
.withLogins("reviewers", reviewers)
|
||||
.to(getApiRoute() + REQUEST_REVIEWERS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge this pull request.
|
||||
*
|
||||
@@ -393,7 +400,7 @@ public class GHPullRequest extends GHIssue {
|
||||
|
||||
private void fetchIssue() throws IOException {
|
||||
if (!fetchedIssueDetails) {
|
||||
new Requester(root).to(getIssuesApiRoute(), this);
|
||||
new Requester(root).method("GET").to(getIssuesApiRoute(), this);
|
||||
fetchedIssueDetails = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ public class GHPullRequestFileDetail {
|
||||
String raw_url;
|
||||
String contents_url;
|
||||
String patch;
|
||||
String previous_filename;
|
||||
|
||||
public String getSha() {
|
||||
return sha;
|
||||
@@ -83,4 +84,9 @@ public class GHPullRequestFileDetail {
|
||||
public String getPatch() {
|
||||
return patch;
|
||||
}
|
||||
|
||||
public String getPreviousFilename()
|
||||
{
|
||||
return previous_filename;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class GHPullRequestReviewBuilder {
|
||||
/**
|
||||
* The review action you want to perform. The review actions include: APPROVE, REQUEST_CHANGES, or COMMENT.
|
||||
* By leaving this blank, you set the review action state to PENDING,
|
||||
* which means you will need to {@linkplain GHPullRequestReview#submit() submit the pull request review} when you are ready.
|
||||
* which means you will need to {@linkplain GHPullRequestReview#submit(String, GHPullRequestReviewEvent) submit the pull request review} when you are ready.
|
||||
*/
|
||||
public GHPullRequestReviewBuilder event(GHPullRequestReviewEvent event) {
|
||||
builder.with("event",event.action());
|
||||
|
||||
@@ -27,7 +27,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.introspect.VisibilityChecker.Std;
|
||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||
@@ -909,6 +910,7 @@ public class GitHub {
|
||||
static {
|
||||
MAPPER.setVisibilityChecker(new Std(NONE, NONE, NONE, NONE, ANY));
|
||||
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
MAPPER.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true);
|
||||
}
|
||||
|
||||
/* package */ static final String GITHUB_URL = "https://api.github.com";
|
||||
|
||||
@@ -37,7 +37,7 @@ public abstract class RateLimitHandler {
|
||||
public void onError(IOException e, HttpURLConnection uc) throws IOException {
|
||||
try {
|
||||
Thread.sleep(parseWaitTime(uc));
|
||||
} catch (InterruptedException _) {
|
||||
} catch (InterruptedException x) {
|
||||
throw (InterruptedIOException)new InterruptedIOException().initCause(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ package org.kohsuke.github;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.annotation.CheckForNull;
|
||||
import javax.annotation.WillClose;
|
||||
@@ -63,7 +63,7 @@ import static java.util.Arrays.asList;
|
||||
import static java.util.logging.Level.FINE;
|
||||
import static java.util.logging.Level.FINEST;
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static org.apache.commons.lang.StringUtils.defaultString;
|
||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
import static org.kohsuke.github.GitHub.MAPPER;
|
||||
|
||||
/**
|
||||
@@ -169,6 +169,14 @@ class Requester {
|
||||
return _with(key, value);
|
||||
}
|
||||
|
||||
public Requester withLogins(String key, Collection<GHUser> users) {
|
||||
List<String> names = new ArrayList<String>(users.size());
|
||||
for (GHUser a : users) {
|
||||
names.add(a.getLogin());
|
||||
}
|
||||
return with(key,names);
|
||||
}
|
||||
|
||||
public Requester with(String key, Map<String, String> value) {
|
||||
return _with(key, value);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,25 @@
|
||||
package org.kohsuke.github.extras;
|
||||
|
||||
import com.squareup.okhttp.ConnectionSpec;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.okhttp.OkUrlFactory;
|
||||
|
||||
import org.kohsuke.github.HttpConnector;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
/**
|
||||
* {@link HttpConnector} for {@link OkHttpClient}.
|
||||
*
|
||||
@@ -23,10 +35,33 @@ public class OkHttpConnector implements HttpConnector {
|
||||
private final OkUrlFactory urlFactory;
|
||||
|
||||
public OkHttpConnector(OkUrlFactory urlFactory) {
|
||||
urlFactory.client().setSslSocketFactory(TlsSocketFactory());
|
||||
urlFactory.client().setConnectionSpecs(TlsConnectionSpecs());
|
||||
this.urlFactory = urlFactory;
|
||||
}
|
||||
|
||||
public HttpURLConnection connect(URL url) throws IOException {
|
||||
return urlFactory.open(url);
|
||||
}
|
||||
|
||||
/** Returns TLSv1.2 only SSL Socket Factory. */
|
||||
private SSLSocketFactory TlsSocketFactory() {
|
||||
SSLContext sc;
|
||||
try {
|
||||
sc = SSLContext.getInstance("TLSv1.2");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
try {
|
||||
sc.init(null, null, null);
|
||||
return sc.getSocketFactory();
|
||||
} catch (KeyManagementException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns connection spec with TLS v1.2 in it */
|
||||
private List<ConnectionSpec> TlsConnectionSpecs() {
|
||||
return Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ public class AppTest extends AbstractGitHubApiTestBase {
|
||||
|
||||
@Test
|
||||
public void testMembership() throws Exception {
|
||||
Set<String> members = gitHub.getOrganization("jenkinsci").getRepository("violations-plugin").getCollaboratorNames();
|
||||
Set<String> members = gitHub.getOrganization("github-api-test-org").getRepository("jenkins").getCollaboratorNames();
|
||||
System.out.println(members.contains("kohsuke"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user