Compare commits

...

22 Commits

Author SHA1 Message Date
Kohsuke Kawaguchi
38b77a9c79 [maven-release-plugin] prepare release github-api-1.93 2018-05-01 07:56:27 -07:00
Kohsuke Kawaguchi
7d294ee8c2 Looks like release rollback didn't quite complete 2018-05-01 07:26:09 -07:00
Kohsuke Kawaguchi
33d9422d03 Merge pull request #422 from ggrell/fix-421-enum-case-issue
Fixes #421 - Enum case doesn't match for Pull Request Reviews
2018-05-01 07:19:42 -07:00
Kohsuke Kawaguchi
bb7302c23a Merge branch 'master' of github.com:kohsuke/github-api 2018-05-01 07:18:57 -07:00
Kohsuke Kawaguchi
d50ae63a5a Merge pull request #431 from Rechi/fixPRLabels
[fix] fetch labels with HTTP GET method
2018-05-01 07:18:43 -07:00
Kohsuke Kawaguchi
1961836e19 Merge pull request #427 from itepikin-smartling/master
Add support for previous_filename for file details in PR.
2018-05-01 07:17:32 -07:00
Kohsuke Kawaguchi
f2ed7c15ce Looks like the permission scheme changed on jenkinsci/violations-plugin 2018-05-01 07:12:30 -07:00
Kohsuke Kawaguchi
4dce173630 Extracted the List<GHUser>->List<String> out to Requester for reuse 2018-05-01 07:03:53 -07:00
Kohsuke Kawaguchi
86f868b2d4 Fixed compilation errors introduced by 8b38a20c18 2018-05-01 06:59:03 -07:00
Kohsuke Kawaguchi
363064f5c0 Merge branch 'master' of github.com:kohsuke/github-api 2018-04-30 19:58:33 -07:00
Kohsuke Kawaguchi
9d99ee9cfc Merge pull request #430 from twcurrie/tcurrie/requestReviewer
Added request reviewers function within GHPullRequest.
2018-04-30 19:58:19 -07:00
Rechi
db8969707d [fix] fetch labels with HTTP GET method 2018-04-06 10:00:00 +02:00
Trevor Currie
a24ac37dfd Added request reviewers function within GHPullRequest. 2018-03-28 23:33:08 -07:00
itepikin
1b04d471b3 Added support for previous_filename for file details in PR. 2018-03-22 11:16:09 +03:00
Gyuri Grell
9cc400a081 Fixes #421 - Enum case doesn't match for Pull Request Reviews
* Set Jackson to ignore case differences in enums.
2018-03-01 20:50:00 -05:00
Kohsuke Kawaguchi
e233aeec0c Merge pull request #410 from Limess/409/update-commons-lang
Update commons-lang to 3.7
2018-03-01 09:45:15 -08:00
Kohsuke Kawaguchi
5dfd621900 Merge pull request #420 from randomvariable/fix/tlsv12
OkHttpConnector: Enforce use of TLSv1.2 to match current Github and Github Enterprise TLS support.
2018-03-01 09:43:24 -08:00
Naadir Jeewa
f0f6a9988f OkHttpConnector: Enforce use of TLSv1.2 to match current Github
and Github Enterprise TLS support.
2018-02-28 09:36:15 +00:00
Charlie Briggs
8b38a20c18 Update commons-lang to 3.7
This fixes the vulnerabilities:
* https://issues.apache.org/jira/browse/LANG-1373
* https://issues.apache.org/jira/browse/LANG-805.
2018-01-23 11:00:58 +00:00
Kohsuke Kawaguchi
e7b76bfdc5 Doc improvements 2018-01-21 11:51:04 -08:00
Kohsuke Kawaguchi
3503ff6d36 Additional methods for issue comment 2018-01-21 11:50:22 -08:00
Kohsuke Kawaguchi
192e21a9fc [maven-release-plugin] prepare for next development iteration 2018-01-13 11:52:05 -08:00
16 changed files with 124 additions and 35 deletions

10
pom.xml
View File

@@ -7,7 +7,7 @@
</parent>
<artifactId>github-api</artifactId>
<version>1.92</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.92</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>

View File

@@ -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
}

View File

@@ -1,6 +1,6 @@
package org.kohsuke.github;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.IOException;

View File

@@ -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;

View File

@@ -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() {

View File

@@ -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);
}
/**

View File

@@ -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.

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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";

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -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"));
}