mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-12 15:50:06 +00:00
Compare commits
13 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dcaf926a95 | ||
|
|
587278f282 | ||
|
|
cc3793cbcd | ||
|
|
c268a5dd07 | ||
|
|
58d10df5e3 | ||
|
|
ae2d01a878 | ||
|
|
dbc5b0b742 | ||
|
|
6af12c2335 | ||
|
|
dafb50d6a9 | ||
|
|
13c59b6618 | ||
|
|
8f95c4f179 | ||
|
|
9fd34aec7f | ||
|
|
17c7a3e7c5 |
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>github-api</artifactId>
|
<artifactId>github-api</artifactId>
|
||||||
<version>1.29</version>
|
<version>1.31</version>
|
||||||
<name>GitHub API for Java</name>
|
<name>GitHub API for Java</name>
|
||||||
<url>http://github-api.kohsuke.org/</url>
|
<url>http://github-api.kohsuke.org/</url>
|
||||||
<description>GitHub API for Java</description>
|
<description>GitHub API for Java</description>
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an issue on GitHub.
|
* Represents an issue on GitHub.
|
||||||
@@ -93,10 +94,13 @@ public class GHIssue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GHIssueState getState() {
|
public GHIssueState getState() {
|
||||||
return Enum.valueOf(GHIssueState.class, state);
|
return Enum.valueOf(GHIssueState.class, state.toUpperCase(Locale.ENGLISH));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<String> getLabels() {
|
public Collection<String> getLabels() {
|
||||||
|
if(labels == null){
|
||||||
|
return Collections.EMPTY_LIST;
|
||||||
|
}
|
||||||
return Collections.unmodifiableList(labels);
|
return Collections.unmodifiableList(labels);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,12 +156,27 @@ public class GHIssue {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains all the comments associated with this issue.
|
* Obtains all the comments associated with this issue.
|
||||||
|
*
|
||||||
|
* @see #listComments()
|
||||||
*/
|
*/
|
||||||
public List<GHIssueComment> getComments() throws IOException {
|
public List<GHIssueComment> getComments() throws IOException {
|
||||||
GHIssueComment[] r = root.retrieve(getApiRoute() + "/comments", GHIssueComment[].class);
|
return listComments().asList();
|
||||||
for (GHIssueComment c : r)
|
}
|
||||||
c.wrapUp(this);
|
|
||||||
return Arrays.asList(r);
|
/**
|
||||||
|
* Obtains all the comments associated with this issue.
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHIssueComment> listComments() throws IOException {
|
||||||
|
return new PagedIterable<GHIssueComment>() {
|
||||||
|
public PagedIterator<GHIssueComment> iterator() {
|
||||||
|
return new PagedIterator<GHIssueComment>(root.retrievePaged(getApiRoute() + "/comments",GHIssueComment[].class,false)) {
|
||||||
|
protected void wrapUp(GHIssueComment[] page) {
|
||||||
|
for (GHIssueComment c : page)
|
||||||
|
c.wrapUp(GHIssue.this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getApiRoute() {
|
private String getApiRoute() {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,8 +35,10 @@ import java.util.Date;
|
|||||||
public class GHIssueComment {
|
public class GHIssueComment {
|
||||||
GHIssue owner;
|
GHIssue owner;
|
||||||
|
|
||||||
private String body, gravatar_id, user, created_at, updated_at;
|
private String body, gravatar_id, created_at, updated_at;
|
||||||
|
private URL url;
|
||||||
private int id;
|
private int id;
|
||||||
|
private GHUser user;
|
||||||
|
|
||||||
/*package*/ GHIssueComment wrapUp(GHIssue owner) {
|
/*package*/ GHIssueComment wrapUp(GHIssue owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
@@ -68,17 +71,22 @@ public class GHIssueComment {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public URL getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the ID of the user who posted this comment.
|
* Gets the ID of the user who posted this comment.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public String getUserName() {
|
public String getUserName() {
|
||||||
return user;
|
return user.getLogin();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the user who posted this comment.
|
* Gets the user who posted this comment.
|
||||||
*/
|
*/
|
||||||
public GHUser getUser() throws IOException {
|
public GHUser getUser() throws IOException {
|
||||||
return owner.root.getUser(user);
|
return owner.root.getUser(user.getLogin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -358,12 +358,28 @@ public class GHRepository {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves all the pull requests of a particular state.
|
* Retrieves all the pull requests of a particular state.
|
||||||
|
*
|
||||||
|
* @see #listPullRequests(GHIssueState)
|
||||||
*/
|
*/
|
||||||
public List<GHPullRequest> getPullRequests(GHIssueState state) throws IOException {
|
public List<GHPullRequest> getPullRequests(GHIssueState state) throws IOException {
|
||||||
GHPullRequest[] r = root.retrieveWithAuth("/repos/" + owner.login + '/' + name + "/pulls?state=" + state.name().toLowerCase(Locale.ENGLISH), GHPullRequest[].class);
|
return listPullRequests(state).asList();
|
||||||
for (GHPullRequest p : r)
|
}
|
||||||
p.wrapUp(this);
|
|
||||||
return new ArrayList<GHPullRequest>(Arrays.asList(r));
|
/**
|
||||||
|
* Retrieves all the pull requests of a particular state.
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHPullRequest> listPullRequests(final GHIssueState state) {
|
||||||
|
return new PagedIterable<GHPullRequest>() {
|
||||||
|
public PagedIterator<GHPullRequest> iterator() {
|
||||||
|
return new PagedIterator<GHPullRequest>(root.retrievePaged(String.format("/repos/%s/%s/pulls?state=%s", owner.login,name,state.name().toLowerCase(Locale.ENGLISH)), GHPullRequest[].class, false)) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHPullRequest[] page) {
|
||||||
|
for (GHPullRequest pr : page)
|
||||||
|
pr.wrap(GHRepository.this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -129,11 +129,11 @@ public class GitHub {
|
|||||||
return new GitHub(props.getProperty("login"),props.getProperty("token"),props.getProperty("password"));
|
return new GitHub(props.getProperty("login"),props.getProperty("token"),props.getProperty("password"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GitHub connect(String login, String apiToken) throws IOException {
|
public static GitHub connect(String login, String apiToken){
|
||||||
return new GitHub(login,apiToken,null);
|
return new GitHub(login,apiToken,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GitHub connect(String login, String apiToken, String password) throws IOException {
|
public static GitHub connect(String login, String apiToken, String password){
|
||||||
return new GitHub(login,apiToken,password);
|
return new GitHub(login,apiToken,password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,24 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* {@link Iterable} that returns {@link PagedIterator}
|
||||||
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public interface PagedIterable<T> extends Iterable<T> {
|
public abstract class PagedIterable<T> implements Iterable<T> {
|
||||||
PagedIterator<T> iterator();
|
public abstract PagedIterator<T> iterator();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Eagerly walk {@link Iterable} and return the result in a list.
|
||||||
|
*/
|
||||||
|
public List<T> asList() {
|
||||||
|
List<T> r = new ArrayList<T>();
|
||||||
|
for(PagedIterator<T> i = iterator(); i.hasNext();) {
|
||||||
|
r.addAll(i.nextPage());
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,11 +14,13 @@ import org.kohsuke.github.GHKey;
|
|||||||
import org.kohsuke.github.GHMyself;
|
import org.kohsuke.github.GHMyself;
|
||||||
import org.kohsuke.github.GHOrganization;
|
import org.kohsuke.github.GHOrganization;
|
||||||
import org.kohsuke.github.GHOrganization.Permission;
|
import org.kohsuke.github.GHOrganization.Permission;
|
||||||
|
import org.kohsuke.github.GHPullRequest;
|
||||||
import org.kohsuke.github.GHRepository;
|
import org.kohsuke.github.GHRepository;
|
||||||
import org.kohsuke.github.GHTeam;
|
import org.kohsuke.github.GHTeam;
|
||||||
import org.kohsuke.github.GHUser;
|
import org.kohsuke.github.GHUser;
|
||||||
import org.kohsuke.github.GitHub;
|
import org.kohsuke.github.GitHub;
|
||||||
import org.kohsuke.github.PagedIterable;
|
import org.kohsuke.github.PagedIterable;
|
||||||
|
import org.kohsuke.github.PagedIterator;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@@ -64,6 +66,16 @@ public class AppTest extends TestCase {
|
|||||||
r.getPullRequests(GHIssueState.OPEN);
|
r.getPullRequests(GHIssueState.OPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testFetchPullRequestAsList() throws Exception {
|
||||||
|
GitHub gh = GitHub.connect();
|
||||||
|
GHRepository r = gh.getOrganization("symfony").getRepository("symfony-docs");
|
||||||
|
assertEquals("master", r.getMasterBranch());
|
||||||
|
PagedIterable<GHPullRequest> i = r.listPullRequests(GHIssueState.CLOSED);
|
||||||
|
List<GHPullRequest> prs = i.asList();
|
||||||
|
assertNotNull(prs);
|
||||||
|
assertTrue(prs.size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
public void testRepoPermissions() throws Exception {
|
public void testRepoPermissions() throws Exception {
|
||||||
GitHub gh = GitHub.connect();
|
GitHub gh = GitHub.connect();
|
||||||
GHRepository r = gh.getOrganization("jenkinsci").getRepository("jenkins");
|
GHRepository r = gh.getOrganization("jenkinsci").getRepository("jenkins");
|
||||||
|
|||||||
Reference in New Issue
Block a user