mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-13 08:21:20 +00:00
Compare commits
13 Commits
github-api
...
github-api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
733d78abdd | ||
|
|
d5809e375c | ||
|
|
2440a676bd | ||
|
|
03ac6c72e7 | ||
|
|
1bbbcabae0 | ||
|
|
9149b6b998 | ||
|
|
2603b5a402 | ||
|
|
dbddf5b9eb | ||
|
|
841f77bac2 | ||
|
|
83ffe75baa | ||
|
|
8cb7094803 | ||
|
|
ed8cd0ad19 | ||
|
|
90d8e65a3b |
4
pom.xml
4
pom.xml
@@ -7,7 +7,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>github-api</artifactId>
|
<artifactId>github-api</artifactId>
|
||||||
<version>1.71</version>
|
<version>1.72</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>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
<connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection>
|
<connection>scm:git:git@github.com/kohsuke/${project.artifactId}.git</connection>
|
||||||
<developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection>
|
<developerConnection>scm:git:ssh://git@github.com/kohsuke/${project.artifactId}.git</developerConnection>
|
||||||
<url>http://${project.artifactId}.kohsuke.org/</url>
|
<url>http://${project.artifactId}.kohsuke.org/</url>
|
||||||
<tag>github-api-1.71</tag>
|
<tag>github-api-1.72</tag>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
|
|||||||
@@ -192,21 +192,24 @@ public class GHCommit {
|
|||||||
/**
|
/**
|
||||||
* Number of lines added + removed.
|
* Number of lines added + removed.
|
||||||
*/
|
*/
|
||||||
public int getLinesChanged() {
|
public int getLinesChanged() throws IOException {
|
||||||
|
populate();
|
||||||
return stats.total;
|
return stats.total;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of lines added.
|
* Number of lines added.
|
||||||
*/
|
*/
|
||||||
public int getLinesAdded() {
|
public int getLinesAdded() throws IOException {
|
||||||
|
populate();
|
||||||
return stats.additions;
|
return stats.additions;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of lines removed.
|
* Number of lines removed.
|
||||||
*/
|
*/
|
||||||
public int getLinesDeleted() {
|
public int getLinesDeleted() throws IOException {
|
||||||
|
populate();
|
||||||
return stats.deletions;
|
return stats.deletions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,7 +226,8 @@ public class GHCommit {
|
|||||||
* @return
|
* @return
|
||||||
* Can be empty but never null.
|
* Can be empty but never null.
|
||||||
*/
|
*/
|
||||||
public List<File> getFiles() {
|
public List<File> getFiles() throws IOException {
|
||||||
|
populate();
|
||||||
return files!=null ? Collections.unmodifiableList(files) : Collections.<File>emptyList();
|
return files!=null ? Collections.unmodifiableList(files) : Collections.<File>emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,8 +277,8 @@ public class GHCommit {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHCommitComment> listComments() {
|
public PagedIterable<GHCommitComment> listComments() {
|
||||||
return new PagedIterable<GHCommitComment>() {
|
return new PagedIterable<GHCommitComment>() {
|
||||||
public PagedIterator<GHCommitComment> iterator() {
|
public PagedIterator<GHCommitComment> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHCommitComment>(owner.root.retrieve().asIterator(String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha), GHCommitComment[].class)) {
|
return new PagedIterator<GHCommitComment>(owner.root.retrieve().asIterator(String.format("/repos/%s/%s/commits/%s/comments", owner.getOwnerName(), owner.getName(), sha), GHCommitComment[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHCommitComment[] page) {
|
protected void wrapUp(GHCommitComment[] page) {
|
||||||
for (GHCommitComment c : page)
|
for (GHCommitComment c : page)
|
||||||
@@ -301,7 +305,7 @@ public class GHCommit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GHCommitComment createComment(String body) throws IOException {
|
public GHCommitComment createComment(String body) throws IOException {
|
||||||
return createComment(body,null,null,null);
|
return createComment(body, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -318,6 +322,14 @@ public class GHCommit {
|
|||||||
return owner.getLastCommitStatus(sha);
|
return owner.getLastCommitStatus(sha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some of the fields are not always filled in when this object is retrieved as a part of another API call.
|
||||||
|
*/
|
||||||
|
void populate() throws IOException {
|
||||||
|
if (files==null && stats==null)
|
||||||
|
owner.root.retrieve().to(owner.getApiTailUrl("commits/" + sha), this);
|
||||||
|
}
|
||||||
|
|
||||||
GHCommit wrapUp(GHRepository owner) {
|
GHCommit wrapUp(GHRepository owner) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
@@ -92,8 +92,8 @@ public class GHCommitQueryBuilder {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHCommit> list() {
|
public PagedIterable<GHCommit> list() {
|
||||||
return new PagedIterable<GHCommit>() {
|
return new PagedIterable<GHCommit>() {
|
||||||
public PagedIterator<GHCommit> iterator() {
|
public PagedIterator<GHCommit> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHCommit>(req.asIterator(repo.getApiTailUrl("commits"), GHCommit[].class)) {
|
return new PagedIterator<GHCommit>(req.asIterator(repo.getApiTailUrl("commits"), GHCommit[].class, pageSize)) {
|
||||||
protected void wrapUp(GHCommit[] page) {
|
protected void wrapUp(GHCommit[] page) {
|
||||||
for (GHCommit c : page)
|
for (GHCommit c : page)
|
||||||
c.wrapUp(repo);
|
c.wrapUp(repo);
|
||||||
|
|||||||
@@ -152,8 +152,8 @@ public class GHContent {
|
|||||||
throw new IllegalStateException(path+" is not a directory");
|
throw new IllegalStateException(path+" is not a directory");
|
||||||
|
|
||||||
return new PagedIterable<GHContent>() {
|
return new PagedIterable<GHContent>() {
|
||||||
public PagedIterator<GHContent> iterator() {
|
public PagedIterator<GHContent> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHContent>(root.retrieve().asIterator(url, GHContent[].class)) {
|
return new PagedIterator<GHContent>(root.retrieve().asIterator(url, GHContent[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHContent[] page) {
|
protected void wrapUp(GHContent[] page) {
|
||||||
GHContent.wrap(page, repository);
|
GHContent.wrap(page, repository);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public class GHDeploymentStatusBuilder {
|
|||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
this.deploymentId = deploymentId;
|
this.deploymentId = deploymentId;
|
||||||
this.builder = new Requester(repo.root);
|
this.builder = new Requester(repo.root);
|
||||||
this.builder.with("state",state.toString().toLowerCase(Locale.ENGLISH));
|
this.builder.with("state",state);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GHDeploymentStatusBuilder description(String description) {
|
public GHDeploymentStatusBuilder description(String description) {
|
||||||
|
|||||||
10
src/main/java/org/kohsuke/github/GHDirection.java
Normal file
10
src/main/java/org/kohsuke/github/GHDirection.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort direction
|
||||||
|
*
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
*/
|
||||||
|
public enum GHDirection {
|
||||||
|
ASC, DESC
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ public class GHEventInfo {
|
|||||||
// we don't want to expose Jackson dependency to the user. This needs databinding
|
// we don't want to expose Jackson dependency to the user. This needs databinding
|
||||||
private ObjectNode payload;
|
private ObjectNode payload;
|
||||||
|
|
||||||
|
private long id;
|
||||||
private String created_at;
|
private String created_at;
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
@@ -54,6 +55,10 @@ public class GHEventInfo {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
public Date getCreatedAt() {
|
public Date getCreatedAt() {
|
||||||
return GitHub.parseDate(created_at);
|
return GitHub.parseDate(created_at);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,8 +140,8 @@ public class GHGist extends GHObject {
|
|||||||
|
|
||||||
public PagedIterable<GHGist> listForks() {
|
public PagedIterable<GHGist> listForks() {
|
||||||
return new PagedIterable<GHGist>() {
|
return new PagedIterable<GHGist>() {
|
||||||
public PagedIterator<GHGist> iterator() {
|
public PagedIterator<GHGist> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHGist>(root.retrieve().asIterator(getApiTailUrl("forks"), GHGist[].class)) {
|
return new PagedIterator<GHGist>(root.retrieve().asIterator(getApiTailUrl("forks"), GHGist[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHGist[] page) {
|
protected void wrapUp(GHGist[] page) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -205,8 +205,8 @@ public class GHIssue extends GHObject {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHIssueComment> listComments() throws IOException {
|
public PagedIterable<GHIssueComment> listComments() throws IOException {
|
||||||
return new PagedIterable<GHIssueComment>() {
|
return new PagedIterable<GHIssueComment>() {
|
||||||
public PagedIterator<GHIssueComment> iterator() {
|
public PagedIterator<GHIssueComment> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHIssueComment>(root.retrieve().asIterator(getIssuesApiRoute() + "/comments", GHIssueComment[].class)) {
|
return new PagedIterator<GHIssueComment>(root.retrieve().asIterator(getIssuesApiRoute() + "/comments", GHIssueComment[].class, pageSize)) {
|
||||||
protected void wrapUp(GHIssueComment[] page) {
|
protected void wrapUp(GHIssueComment[] page) {
|
||||||
for (GHIssueComment c : page)
|
for (GHIssueComment c : page)
|
||||||
c.wrapUp(GHIssue.this);
|
c.wrapUp(GHIssue.this);
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class GHIssueSearchBuilder extends GHSearchBuilder<GHIssue> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GHIssueSearchBuilder sort(Sort sort) {
|
public GHIssueSearchBuilder sort(Sort sort) {
|
||||||
req.with("sort",sort.toString().toLowerCase(Locale.ENGLISH));
|
req.with("sort",sort);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,11 @@
|
|||||||
|
|
||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see GHPullRequestQueryBuilder#state(GHIssueState)
|
||||||
|
*/
|
||||||
public enum GHIssueState {
|
public enum GHIssueState {
|
||||||
OPEN,
|
OPEN,
|
||||||
CLOSED
|
CLOSED,
|
||||||
|
ALL
|
||||||
}
|
}
|
||||||
@@ -158,9 +158,8 @@ public class GHMyself extends GHUser {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHRepository> listRepositories(final int pageSize, final RepositoryListFilter repoType) {
|
public PagedIterable<GHRepository> listRepositories(final int pageSize, final RepositoryListFilter repoType) {
|
||||||
return new PagedIterable<GHRepository>() {
|
return new PagedIterable<GHRepository>() {
|
||||||
public PagedIterator<GHRepository> iterator() {
|
public PagedIterator<GHRepository> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/user/repos?per_page=" + pageSize +
|
return new PagedIterator<GHRepository>(root.retrieve().with("type",repoType).asIterator("/user/repos", GHRepository[].class, pageSize)) {
|
||||||
"&type=" + repoType.name().toLowerCase(Locale.ENGLISH), GHRepository[].class)) {
|
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHRepository[] page) {
|
protected void wrapUp(GHRepository[] page) {
|
||||||
for (GHRepository c : page)
|
for (GHRepository c : page)
|
||||||
@@ -168,7 +167,7 @@ public class GHMyself extends GHUser {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
}.withPageSize(pageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ public class GHOrganization extends GHPerson {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHTeam> listTeams() throws IOException {
|
public PagedIterable<GHTeam> listTeams() throws IOException {
|
||||||
return new PagedIterable<GHTeam>() {
|
return new PagedIterable<GHTeam>() {
|
||||||
public PagedIterator<GHTeam> iterator() {
|
public PagedIterator<GHTeam> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHTeam>(root.retrieve().asIterator(String.format("/orgs/%s/teams", login), GHTeam[].class)) {
|
return new PagedIterator<GHTeam>(root.retrieve().asIterator(String.format("/orgs/%s/teams", login), GHTeam[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHTeam[] page) {
|
protected void wrapUp(GHTeam[] page) {
|
||||||
for (GHTeam c : page)
|
for (GHTeam c : page)
|
||||||
@@ -150,9 +150,9 @@ public class GHOrganization extends GHPerson {
|
|||||||
|
|
||||||
private PagedIterable<GHUser> listMembers(final String suffix, final String filter) throws IOException {
|
private PagedIterable<GHUser> listMembers(final String suffix, final String filter) throws IOException {
|
||||||
return new PagedIterable<GHUser>() {
|
return new PagedIterable<GHUser>() {
|
||||||
public PagedIterator<GHUser> iterator() {
|
public PagedIterator<GHUser> _iterator(int pageSize) {
|
||||||
String filterParams = (filter == null) ? "" : ("?filter=" + filter);
|
String filterParams = (filter == null) ? "" : ("?filter=" + filter);
|
||||||
return new PagedIterator<GHUser>(root.retrieve().asIterator(String.format("/orgs/%s/%s%s", login, suffix, filterParams), GHUser[].class)) {
|
return new PagedIterator<GHUser>(root.retrieve().asIterator(String.format("/orgs/%s/%s%s", login, suffix, filterParams), GHUser[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHUser[] users) {
|
protected void wrapUp(GHUser[] users) {
|
||||||
GHUser.wrap(users, root);
|
GHUser.wrap(users, root);
|
||||||
@@ -175,7 +175,7 @@ public class GHOrganization extends GHPerson {
|
|||||||
* Creates a new team and assigns the repositories.
|
* Creates a new team and assigns the repositories.
|
||||||
*/
|
*/
|
||||||
public GHTeam createTeam(String name, Permission p, Collection<GHRepository> repositories) throws IOException {
|
public GHTeam createTeam(String name, Permission p, Collection<GHRepository> repositories) throws IOException {
|
||||||
Requester post = new Requester(root).with("name", name).with("permission", p.name().toLowerCase(Locale.ENGLISH));
|
Requester post = new Requester(root).with("name", name).with("permission", p);
|
||||||
List<String> repo_names = new ArrayList<String>();
|
List<String> repo_names = new ArrayList<String>();
|
||||||
for (GHRepository r : repositories) {
|
for (GHRepository r : repositories) {
|
||||||
repo_names.add(r.getName());
|
repo_names.add(r.getName());
|
||||||
@@ -222,8 +222,8 @@ public class GHOrganization extends GHPerson {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHEventInfo> listEvents() throws IOException {
|
public PagedIterable<GHEventInfo> listEvents() throws IOException {
|
||||||
return new PagedIterable<GHEventInfo>() {
|
return new PagedIterable<GHEventInfo>() {
|
||||||
public PagedIterator<GHEventInfo> iterator() {
|
public PagedIterator<GHEventInfo> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHEventInfo>(root.retrieve().asIterator(String.format("/orgs/%s/events", login), GHEventInfo[].class)) {
|
return new PagedIterator<GHEventInfo>(root.retrieve().asIterator(String.format("/orgs/%s/events", login), GHEventInfo[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHEventInfo[] page) {
|
protected void wrapUp(GHEventInfo[] page) {
|
||||||
for (GHEventInfo c : page)
|
for (GHEventInfo c : page)
|
||||||
@@ -244,8 +244,8 @@ public class GHOrganization extends GHPerson {
|
|||||||
@Override
|
@Override
|
||||||
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
|
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
|
||||||
return new PagedIterable<GHRepository>() {
|
return new PagedIterable<GHRepository>() {
|
||||||
public PagedIterator<GHRepository> iterator() {
|
public PagedIterator<GHRepository> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/orgs/" + login + "/repos?per_page=" + pageSize, GHRepository[].class)) {
|
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/orgs/" + login + "/repos?per_page=" + pageSize, GHRepository[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHRepository[] page) {
|
protected void wrapUp(GHRepository[] page) {
|
||||||
for (GHRepository c : page)
|
for (GHRepository c : page)
|
||||||
|
|||||||
@@ -76,8 +76,8 @@ public abstract class GHPerson extends GHObject {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
|
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
|
||||||
return new PagedIterable<GHRepository>() {
|
return new PagedIterable<GHRepository>() {
|
||||||
public PagedIterator<GHRepository> iterator() {
|
public PagedIterator<GHRepository> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/users/" + login + "/repos?per_page=" + pageSize, GHRepository[].class)) {
|
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/users/" + login + "/repos?per_page=" + pageSize, GHRepository[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHRepository[] page) {
|
protected void wrapUp(GHRepository[] page) {
|
||||||
for (GHRepository c : page)
|
for (GHRepository c : page)
|
||||||
@@ -104,7 +104,7 @@ public abstract class GHPerson extends GHObject {
|
|||||||
public synchronized Iterable<List<GHRepository>> iterateRepositories(final int pageSize) {
|
public synchronized Iterable<List<GHRepository>> iterateRepositories(final int pageSize) {
|
||||||
return new Iterable<List<GHRepository>>() {
|
return new Iterable<List<GHRepository>>() {
|
||||||
public Iterator<List<GHRepository>> iterator() {
|
public Iterator<List<GHRepository>> iterator() {
|
||||||
final Iterator<GHRepository[]> pager = root.retrieve().asIterator("/users/" + login + "/repos?per_page="+pageSize,GHRepository[].class);
|
final Iterator<GHRepository[]> pager = root.retrieve().asIterator("/users/" + login + "/repos?per_page="+pageSize,GHRepository[].class, pageSize);
|
||||||
|
|
||||||
return new Iterator<List<GHRepository>>() {
|
return new Iterator<List<GHRepository>>() {
|
||||||
public boolean hasNext() {
|
public boolean hasNext() {
|
||||||
|
|||||||
@@ -210,9 +210,9 @@ public class GHPullRequest extends GHIssue {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHPullRequestFileDetail> listFiles() {
|
public PagedIterable<GHPullRequestFileDetail> listFiles() {
|
||||||
return new PagedIterable<GHPullRequestFileDetail>() {
|
return new PagedIterable<GHPullRequestFileDetail>() {
|
||||||
public PagedIterator<GHPullRequestFileDetail> iterator() {
|
public PagedIterator<GHPullRequestFileDetail> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHPullRequestFileDetail>(root.retrieve().asIterator(String.format("%s/files", getApiURL()),
|
return new PagedIterator<GHPullRequestFileDetail>(root.retrieve().asIterator(String.format("%s/files", getApiURL()),
|
||||||
GHPullRequestFileDetail[].class)) {
|
GHPullRequestFileDetail[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHPullRequestFileDetail[] page) {
|
protected void wrapUp(GHPullRequestFileDetail[] page) {
|
||||||
}
|
}
|
||||||
@@ -226,9 +226,9 @@ public class GHPullRequest extends GHIssue {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHPullRequestReviewComment> listReviewComments() throws IOException {
|
public PagedIterable<GHPullRequestReviewComment> listReviewComments() throws IOException {
|
||||||
return new PagedIterable<GHPullRequestReviewComment>() {
|
return new PagedIterable<GHPullRequestReviewComment>() {
|
||||||
public PagedIterator<GHPullRequestReviewComment> iterator() {
|
public PagedIterator<GHPullRequestReviewComment> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHPullRequestReviewComment>(root.retrieve().asIterator(getApiRoute() + "/comments",
|
return new PagedIterator<GHPullRequestReviewComment>(root.retrieve().asIterator(getApiRoute() + "/comments",
|
||||||
GHPullRequestReviewComment[].class)) {
|
GHPullRequestReviewComment[].class, pageSize)) {
|
||||||
protected void wrapUp(GHPullRequestReviewComment[] page) {
|
protected void wrapUp(GHPullRequestReviewComment[] page) {
|
||||||
for (GHPullRequestReviewComment c : page)
|
for (GHPullRequestReviewComment c : page)
|
||||||
c.wrapUp(GHPullRequest.this);
|
c.wrapUp(GHPullRequest.this);
|
||||||
@@ -243,10 +243,10 @@ public class GHPullRequest extends GHIssue {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHPullRequestCommitDetail> listCommits() {
|
public PagedIterable<GHPullRequestCommitDetail> listCommits() {
|
||||||
return new PagedIterable<GHPullRequestCommitDetail>() {
|
return new PagedIterable<GHPullRequestCommitDetail>() {
|
||||||
public PagedIterator<GHPullRequestCommitDetail> iterator() {
|
public PagedIterator<GHPullRequestCommitDetail> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHPullRequestCommitDetail>(root.retrieve().asIterator(
|
return new PagedIterator<GHPullRequestCommitDetail>(root.retrieve().asIterator(
|
||||||
String.format("%s/commits", getApiURL()),
|
String.format("%s/commits", getApiURL()),
|
||||||
GHPullRequestCommitDetail[].class)) {
|
GHPullRequestCommitDetail[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHPullRequestCommitDetail[] page) {
|
protected void wrapUp(GHPullRequestCommitDetail[] page) {
|
||||||
for (GHPullRequestCommitDetail c : page)
|
for (GHPullRequestCommitDetail c : page)
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists up pull requests with some filtering and sorting.
|
||||||
|
*
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
* @see GHRepository#queryPullRequests()
|
||||||
|
*/
|
||||||
|
public class GHPullRequestQueryBuilder extends GHQueryBuilder<GHPullRequest> {
|
||||||
|
private final GHRepository repo;
|
||||||
|
|
||||||
|
/*package*/ GHPullRequestQueryBuilder(GHRepository repo) {
|
||||||
|
super(repo.root);
|
||||||
|
this.repo = repo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHPullRequestQueryBuilder state(GHIssueState state) {
|
||||||
|
req.with("state",state);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHPullRequestQueryBuilder head(String head) {
|
||||||
|
req.with("head",head);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHPullRequestQueryBuilder base(String base) {
|
||||||
|
req.with("base",base);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GHPullRequestQueryBuilder sort(Sort sort) {
|
||||||
|
req.with("sort",sort);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Sort { CREATED, UPDATED, POPULARITY, LONG_RUNNING }
|
||||||
|
|
||||||
|
public GHPullRequestQueryBuilder direction(GHDirection d) {
|
||||||
|
req.with("direction",d);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PagedIterable<GHPullRequest> list() {
|
||||||
|
return new PagedIterable<GHPullRequest>() {
|
||||||
|
public PagedIterator<GHPullRequest> _iterator(int pageSize) {
|
||||||
|
return new PagedIterator<GHPullRequest>(req.asIterator(repo.getApiTailUrl("pulls"), GHPullRequest[].class, pageSize)) {
|
||||||
|
@Override
|
||||||
|
protected void wrapUp(GHPullRequest[] page) {
|
||||||
|
for (GHPullRequest pr : page)
|
||||||
|
pr.wrapUp(repo);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
21
src/main/java/org/kohsuke/github/GHQueryBuilder.java
Normal file
21
src/main/java/org/kohsuke/github/GHQueryBuilder.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to specify filters, sort order, etc for listing items in a collection.
|
||||||
|
*
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
*/
|
||||||
|
public abstract class GHQueryBuilder<T> {
|
||||||
|
protected final GitHub root;
|
||||||
|
protected final Requester req;
|
||||||
|
|
||||||
|
/*package*/ GHQueryBuilder(GitHub root) {
|
||||||
|
this.root = root;
|
||||||
|
this.req = root.retrieve();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start listing items by using the settings built up on this object.
|
||||||
|
*/
|
||||||
|
public abstract PagedIterable<T> list();
|
||||||
|
}
|
||||||
@@ -36,7 +36,6 @@ import java.io.InterruptedIOException;
|
|||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
@@ -76,8 +75,8 @@ public class GHRepository extends GHObject {
|
|||||||
|
|
||||||
public PagedIterable<GHDeploymentStatus> getDeploymentStatuses(final int id) {
|
public PagedIterable<GHDeploymentStatus> getDeploymentStatuses(final int id) {
|
||||||
return new PagedIterable<GHDeploymentStatus>() {
|
return new PagedIterable<GHDeploymentStatus>() {
|
||||||
public PagedIterator<GHDeploymentStatus> iterator() {
|
public PagedIterator<GHDeploymentStatus> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHDeploymentStatus>(root.retrieve().asIterator(getApiTailUrl("deployments")+"/"+id+"/statuses", GHDeploymentStatus[].class)) {
|
return new PagedIterator<GHDeploymentStatus>(root.retrieve().asIterator(getApiTailUrl("deployments")+"/"+id+"/statuses", GHDeploymentStatus[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHDeploymentStatus[] page) {
|
protected void wrapUp(GHDeploymentStatus[] page) {
|
||||||
for (GHDeploymentStatus c : page)
|
for (GHDeploymentStatus c : page)
|
||||||
@@ -92,8 +91,8 @@ public class GHRepository extends GHObject {
|
|||||||
List<String> params = Arrays.asList(getParam("sha", sha), getParam("ref", ref), getParam("task", task), getParam("environment", environment));
|
List<String> params = Arrays.asList(getParam("sha", sha), getParam("ref", ref), getParam("task", task), getParam("environment", environment));
|
||||||
final String deploymentsUrl = getApiTailUrl("deployments") + "?"+ join(params,"&");
|
final String deploymentsUrl = getApiTailUrl("deployments") + "?"+ join(params,"&");
|
||||||
return new PagedIterable<GHDeployment>() {
|
return new PagedIterable<GHDeployment>() {
|
||||||
public PagedIterator<GHDeployment> iterator() {
|
public PagedIterator<GHDeployment> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHDeployment>(root.retrieve().asIterator(deploymentsUrl, GHDeployment[].class)) {
|
return new PagedIterator<GHDeployment>(root.retrieve().asIterator(deploymentsUrl, GHDeployment[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHDeployment[] page) {
|
protected void wrapUp(GHDeployment[] page) {
|
||||||
for (GHDeployment c : page)
|
for (GHDeployment c : page)
|
||||||
@@ -229,11 +228,10 @@ public class GHRepository extends GHObject {
|
|||||||
|
|
||||||
public List<GHIssue> getIssues(GHIssueState state, GHMilestone milestone) throws IOException {
|
public List<GHIssue> getIssues(GHIssueState state, GHMilestone milestone) throws IOException {
|
||||||
return Arrays.asList(GHIssue.wrap(root.retrieve()
|
return Arrays.asList(GHIssue.wrap(root.retrieve()
|
||||||
.to(getApiTailUrl(String.format("issues?state=%s&milestone=%s",
|
.with("state", state)
|
||||||
state.toString().toLowerCase(Locale.ENGLISH),
|
.with("milestone", milestone == null ? "none" : "" + milestone.getNumber())
|
||||||
milestone == null ? "none" : "" + milestone.getNumber())),
|
.to(getApiTailUrl("issues"),
|
||||||
GHIssue[].class
|
GHIssue[].class), this));
|
||||||
), this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -241,8 +239,8 @@ public class GHRepository extends GHObject {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHIssue> listIssues(final GHIssueState state) {
|
public PagedIterable<GHIssue> listIssues(final GHIssueState state) {
|
||||||
return new PagedIterable<GHIssue>() {
|
return new PagedIterable<GHIssue>() {
|
||||||
public PagedIterator<GHIssue> iterator() {
|
public PagedIterator<GHIssue> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHIssue>(root.retrieve().asIterator(getApiTailUrl("issues?state="+state.toString().toLowerCase(Locale.ENGLISH)), GHIssue[].class)) {
|
return new PagedIterator<GHIssue>(root.retrieve().with("state",state).asIterator(getApiTailUrl("issues"), GHIssue[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHIssue[] page) {
|
protected void wrapUp(GHIssue[] page) {
|
||||||
for (GHIssue c : page)
|
for (GHIssue c : page)
|
||||||
@@ -281,8 +279,8 @@ public class GHRepository extends GHObject {
|
|||||||
|
|
||||||
public PagedIterable<GHRelease> listReleases() throws IOException {
|
public PagedIterable<GHRelease> listReleases() throws IOException {
|
||||||
return new PagedIterable<GHRelease>() {
|
return new PagedIterable<GHRelease>() {
|
||||||
public PagedIterator<GHRelease> iterator() {
|
public PagedIterator<GHRelease> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHRelease>(root.retrieve().asIterator(getApiTailUrl("releases"), GHRelease[].class)) {
|
return new PagedIterator<GHRelease>(root.retrieve().asIterator(getApiTailUrl("releases"), GHRelease[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHRelease[] page) {
|
protected void wrapUp(GHRelease[] page) {
|
||||||
for (GHRelease c : page)
|
for (GHRelease c : page)
|
||||||
@@ -295,8 +293,8 @@ public class GHRepository extends GHObject {
|
|||||||
|
|
||||||
public PagedIterable<GHTag> listTags() throws IOException {
|
public PagedIterable<GHTag> listTags() throws IOException {
|
||||||
return new PagedIterable<GHTag>() {
|
return new PagedIterable<GHTag>() {
|
||||||
public PagedIterator<GHTag> iterator() {
|
public PagedIterator<GHTag> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHTag>(root.retrieve().asIterator(getApiTailUrl("tags"), GHTag[].class)) {
|
return new PagedIterator<GHTag>(root.retrieve().asIterator(getApiTailUrl("tags"), GHTag[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHTag[] page) {
|
protected void wrapUp(GHTag[] page) {
|
||||||
for (GHTag c : page)
|
for (GHTag c : page)
|
||||||
@@ -416,9 +414,9 @@ public class GHRepository extends GHObject {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHUser> listCollaborators() throws IOException {
|
public PagedIterable<GHUser> listCollaborators() throws IOException {
|
||||||
return new PagedIterable<GHUser>() {
|
return new PagedIterable<GHUser>() {
|
||||||
public PagedIterator<GHUser> iterator() {
|
public PagedIterator<GHUser> _iterator(int pageSize) {
|
||||||
|
|
||||||
return new PagedIterator<GHUser>(root.retrieve().asIterator(getApiTailUrl("collaborators"), GHUser[].class)) {
|
return new PagedIterator<GHUser>(root.retrieve().asIterator(getApiTailUrl("collaborators"), GHUser[].class, pageSize)) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHUser[] users) {
|
protected void wrapUp(GHUser[] users) {
|
||||||
@@ -539,7 +537,7 @@ public class GHRepository extends GHObject {
|
|||||||
/**
|
/**
|
||||||
* Sort orders for listing forks
|
* Sort orders for listing forks
|
||||||
*/
|
*/
|
||||||
public static enum ForkSort { NEWEST, OLDEST, STARGAZERS }
|
public enum ForkSort { NEWEST, OLDEST, STARGAZERS }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lists all the direct forks of this repository, sorted by
|
* Lists all the direct forks of this repository, sorted by
|
||||||
@@ -556,12 +554,8 @@ public class GHRepository extends GHObject {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHRepository> listForks(final ForkSort sort) {
|
public PagedIterable<GHRepository> listForks(final ForkSort sort) {
|
||||||
return new PagedIterable<GHRepository>() {
|
return new PagedIterable<GHRepository>() {
|
||||||
public PagedIterator<GHRepository> iterator() {
|
public PagedIterator<GHRepository> _iterator(int pageSize) {
|
||||||
String sortParam = "";
|
return new PagedIterator<GHRepository>(root.retrieve().with("sort",sort).asIterator(getApiTailUrl("forks"), GHRepository[].class, pageSize)) {
|
||||||
if (sort != null) {
|
|
||||||
sortParam = "?sort=" + sort.toString().toLowerCase(Locale.ENGLISH);
|
|
||||||
}
|
|
||||||
return new PagedIterator<GHRepository>(root.retrieve().asIterator(getApiTailUrl("forks" + sortParam), GHRepository[].class)) {
|
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHRepository[] page) {
|
protected void wrapUp(GHRepository[] page) {
|
||||||
for (GHRepository c : page) {
|
for (GHRepository c : page) {
|
||||||
@@ -618,24 +612,24 @@ public class GHRepository extends GHObject {
|
|||||||
* @see #listPullRequests(GHIssueState)
|
* @see #listPullRequests(GHIssueState)
|
||||||
*/
|
*/
|
||||||
public List<GHPullRequest> getPullRequests(GHIssueState state) throws IOException {
|
public List<GHPullRequest> getPullRequests(GHIssueState state) throws IOException {
|
||||||
return listPullRequests(state).asList();
|
return queryPullRequests().state(state).list().asList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves all the pull requests of a particular state.
|
* Retrieves all the pull requests of a particular state.
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
* Use {@link #queryPullRequests()}
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHPullRequest> listPullRequests(final GHIssueState state) {
|
public PagedIterable<GHPullRequest> listPullRequests(GHIssueState state) {
|
||||||
return new PagedIterable<GHPullRequest>() {
|
return queryPullRequests().state(state).list();
|
||||||
public PagedIterator<GHPullRequest> iterator() {
|
}
|
||||||
return new PagedIterator<GHPullRequest>(root.retrieve().asIterator(getApiTailUrl("pulls?state="+state.name().toLowerCase(Locale.ENGLISH)), GHPullRequest[].class)) {
|
|
||||||
@Override
|
/**
|
||||||
protected void wrapUp(GHPullRequest[] page) {
|
* Retrieves pull requests.
|
||||||
for (GHPullRequest pr : page)
|
*/
|
||||||
pr.wrapUp(GHRepository.this);
|
public GHPullRequestQueryBuilder queryPullRequests() {
|
||||||
}
|
return new GHPullRequestQueryBuilder(this);
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -715,7 +709,7 @@ public class GHRepository extends GHObject {
|
|||||||
* @throws IOException on failure communicating with GitHub
|
* @throws IOException on failure communicating with GitHub
|
||||||
*/
|
*/
|
||||||
public GHRef[] getRefs() throws IOException {
|
public GHRef[] getRefs() throws IOException {
|
||||||
return GHRef.wrap(root.retrieve().to(String.format("/repos/%s/%s/git/refs", owner.login, name), GHRef[].class),root);
|
return GHRef.wrap(root.retrieve().to(String.format("/repos/%s/%s/git/refs", owner.login, name), GHRef[].class), root);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -786,8 +780,8 @@ public class GHRepository extends GHObject {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHCommit> listCommits() {
|
public PagedIterable<GHCommit> listCommits() {
|
||||||
return new PagedIterable<GHCommit>() {
|
return new PagedIterable<GHCommit>() {
|
||||||
public PagedIterator<GHCommit> iterator() {
|
public PagedIterator<GHCommit> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHCommit>(root.retrieve().asIterator(String.format("/repos/%s/%s/commits", owner.login, name), GHCommit[].class)) {
|
return new PagedIterator<GHCommit>(root.retrieve().asIterator(String.format("/repos/%s/%s/commits", owner.login, name), GHCommit[].class, pageSize)) {
|
||||||
protected void wrapUp(GHCommit[] page) {
|
protected void wrapUp(GHCommit[] page) {
|
||||||
for (GHCommit c : page)
|
for (GHCommit c : page)
|
||||||
c.wrapUp(GHRepository.this);
|
c.wrapUp(GHRepository.this);
|
||||||
@@ -809,8 +803,8 @@ public class GHRepository extends GHObject {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHCommitComment> listCommitComments() {
|
public PagedIterable<GHCommitComment> listCommitComments() {
|
||||||
return new PagedIterable<GHCommitComment>() {
|
return new PagedIterable<GHCommitComment>() {
|
||||||
public PagedIterator<GHCommitComment> iterator() {
|
public PagedIterator<GHCommitComment> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHCommitComment>(root.retrieve().asIterator(String.format("/repos/%s/%s/comments", owner.login, name), GHCommitComment[].class)) {
|
return new PagedIterator<GHCommitComment>(root.retrieve().asIterator(String.format("/repos/%s/%s/comments", owner.login, name), GHCommitComment[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHCommitComment[] page) {
|
protected void wrapUp(GHCommitComment[] page) {
|
||||||
for (GHCommitComment c : page)
|
for (GHCommitComment c : page)
|
||||||
@@ -826,8 +820,8 @@ public class GHRepository extends GHObject {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHCommitStatus> listCommitStatuses(final String sha1) throws IOException {
|
public PagedIterable<GHCommitStatus> listCommitStatuses(final String sha1) throws IOException {
|
||||||
return new PagedIterable<GHCommitStatus>() {
|
return new PagedIterable<GHCommitStatus>() {
|
||||||
public PagedIterator<GHCommitStatus> iterator() {
|
public PagedIterator<GHCommitStatus> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHCommitStatus>(root.retrieve().asIterator(String.format("/repos/%s/%s/statuses/%s", owner.login, name, sha1), GHCommitStatus[].class)) {
|
return new PagedIterator<GHCommitStatus>(root.retrieve().asIterator(String.format("/repos/%s/%s/statuses/%s", owner.login, name, sha1), GHCommitStatus[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHCommitStatus[] page) {
|
protected void wrapUp(GHCommitStatus[] page) {
|
||||||
for (GHCommitStatus c : page)
|
for (GHCommitStatus c : page)
|
||||||
@@ -858,7 +852,7 @@ public class GHRepository extends GHObject {
|
|||||||
*/
|
*/
|
||||||
public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description, String context) throws IOException {
|
public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description, String context) throws IOException {
|
||||||
return new Requester(root)
|
return new Requester(root)
|
||||||
.with("state", state.name().toLowerCase(Locale.ENGLISH))
|
.with("state", state)
|
||||||
.with("target_url", targetUrl)
|
.with("target_url", targetUrl)
|
||||||
.with("description", description)
|
.with("description", description)
|
||||||
.with("context", context)
|
.with("context", context)
|
||||||
@@ -869,7 +863,7 @@ public class GHRepository extends GHObject {
|
|||||||
* @see #createCommitStatus(String, GHCommitState,String,String,String)
|
* @see #createCommitStatus(String, GHCommitState,String,String,String)
|
||||||
*/
|
*/
|
||||||
public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description) throws IOException {
|
public GHCommitStatus createCommitStatus(String sha1, GHCommitState state, String targetUrl, String description) throws IOException {
|
||||||
return createCommitStatus(sha1, state, targetUrl, description,null);
|
return createCommitStatus(sha1, state, targetUrl, description, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -877,8 +871,8 @@ public class GHRepository extends GHObject {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHEventInfo> listEvents() throws IOException {
|
public PagedIterable<GHEventInfo> listEvents() throws IOException {
|
||||||
return new PagedIterable<GHEventInfo>() {
|
return new PagedIterable<GHEventInfo>() {
|
||||||
public PagedIterator<GHEventInfo> iterator() {
|
public PagedIterator<GHEventInfo> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHEventInfo>(root.retrieve().asIterator(String.format("/repos/%s/%s/events", owner.login, name), GHEventInfo[].class)) {
|
return new PagedIterator<GHEventInfo>(root.retrieve().asIterator(String.format("/repos/%s/%s/events", owner.login, name), GHEventInfo[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHEventInfo[] page) {
|
protected void wrapUp(GHEventInfo[] page) {
|
||||||
for (GHEventInfo c : page)
|
for (GHEventInfo c : page)
|
||||||
@@ -896,8 +890,8 @@ public class GHRepository extends GHObject {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHLabel> listLabels() throws IOException {
|
public PagedIterable<GHLabel> listLabels() throws IOException {
|
||||||
return new PagedIterable<GHLabel>() {
|
return new PagedIterable<GHLabel>() {
|
||||||
public PagedIterator<GHLabel> iterator() {
|
public PagedIterator<GHLabel> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHLabel>(root.retrieve().asIterator(getApiTailUrl("labels"), GHLabel[].class)) {
|
return new PagedIterator<GHLabel>(root.retrieve().asIterator(getApiTailUrl("labels"), GHLabel[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHLabel[] page) {
|
protected void wrapUp(GHLabel[] page) {
|
||||||
for (GHLabel c : page)
|
for (GHLabel c : page)
|
||||||
@@ -915,7 +909,7 @@ public class GHRepository extends GHObject {
|
|||||||
public GHLabel createLabel(String name, String color) throws IOException {
|
public GHLabel createLabel(String name, String color) throws IOException {
|
||||||
return root.retrieve().method("POST")
|
return root.retrieve().method("POST")
|
||||||
.with("name",name)
|
.with("name",name)
|
||||||
.with("color",color)
|
.with("color", color)
|
||||||
.to(getApiTailUrl("labels"), GHLabel.class).wrapUp(this);
|
.to(getApiTailUrl("labels"), GHLabel.class).wrapUp(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -925,9 +919,20 @@ public class GHRepository extends GHObject {
|
|||||||
* https://developer.github.com/v3/activity/watching/
|
* https://developer.github.com/v3/activity/watching/
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHUser> listSubscribers() {
|
public PagedIterable<GHUser> listSubscribers() {
|
||||||
|
return listUsers("subscribers");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists all the users who have starred this repo.
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHUser> listStargazers() {
|
||||||
|
return listUsers("stargazers");
|
||||||
|
}
|
||||||
|
|
||||||
|
private PagedIterable<GHUser> listUsers(final String suffix) {
|
||||||
return new PagedIterable<GHUser>() {
|
return new PagedIterable<GHUser>() {
|
||||||
public PagedIterator<GHUser> iterator() {
|
public PagedIterator<GHUser> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHUser>(root.retrieve().asIterator(getApiTailUrl("subscribers"), GHUser[].class)) {
|
return new PagedIterator<GHUser>(root.retrieve().asIterator(getApiTailUrl(suffix), GHUser[].class, pageSize)) {
|
||||||
protected void wrapUp(GHUser[] page) {
|
protected void wrapUp(GHUser[] page) {
|
||||||
for (GHUser c : page)
|
for (GHUser c : page)
|
||||||
c.wrapUp(root);
|
c.wrapUp(root);
|
||||||
@@ -1078,8 +1083,8 @@ public class GHRepository extends GHObject {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHMilestone> listMilestones(final GHIssueState state) {
|
public PagedIterable<GHMilestone> listMilestones(final GHIssueState state) {
|
||||||
return new PagedIterable<GHMilestone>() {
|
return new PagedIterable<GHMilestone>() {
|
||||||
public PagedIterator<GHMilestone> iterator() {
|
public PagedIterator<GHMilestone> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHMilestone>(root.retrieve().asIterator(getApiTailUrl("milestones?state="+state.toString().toLowerCase(Locale.ENGLISH)), GHMilestone[].class)) {
|
return new PagedIterator<GHMilestone>(root.retrieve().with("state",state).asIterator(getApiTailUrl("milestones"), GHMilestone[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHMilestone[] page) {
|
protected void wrapUp(GHMilestone[] page) {
|
||||||
for (GHMilestone c : page)
|
for (GHMilestone c : page)
|
||||||
@@ -1251,8 +1256,8 @@ public class GHRepository extends GHObject {
|
|||||||
|
|
||||||
public PagedIterable<Contributor> listContributors() throws IOException {
|
public PagedIterable<Contributor> listContributors() throws IOException {
|
||||||
return new PagedIterable<Contributor>() {
|
return new PagedIterable<Contributor>() {
|
||||||
public PagedIterator<Contributor> iterator() {
|
public PagedIterator<Contributor> _iterator(int pageSize) {
|
||||||
return new PagedIterator<Contributor>(root.retrieve().asIterator(getApiTailUrl("contributors"), Contributor[].class)) {
|
return new PagedIterator<Contributor>(root.retrieve().asIterator(getApiTailUrl("contributors"), Contributor[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(Contributor[] page) {
|
protected void wrapUp(Contributor[] page) {
|
||||||
for (Contributor c : page)
|
for (Contributor c : page)
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class GHRepositorySearchBuilder extends GHSearchBuilder<GHRepository> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GHRepositorySearchBuilder sort(Sort sort) {
|
public GHRepositorySearchBuilder sort(Sort sort) {
|
||||||
req.with("sort",sort.toString().toLowerCase(Locale.ENGLISH));
|
req.with("sort",sort);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,9 +10,7 @@ import java.util.List;
|
|||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public abstract class GHSearchBuilder<T> {
|
public abstract class GHSearchBuilder<T> extends GHQueryBuilder<T> {
|
||||||
protected final GitHub root;
|
|
||||||
protected final Requester req;
|
|
||||||
protected final List<String> terms = new ArrayList<String>();
|
protected final List<String> terms = new ArrayList<String>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,15 +19,14 @@ public abstract class GHSearchBuilder<T> {
|
|||||||
private final Class<? extends SearchResult<T>> receiverType;
|
private final Class<? extends SearchResult<T>> receiverType;
|
||||||
|
|
||||||
/*package*/ GHSearchBuilder(GitHub root, Class<? extends SearchResult<T>> receiverType) {
|
/*package*/ GHSearchBuilder(GitHub root, Class<? extends SearchResult<T>> receiverType) {
|
||||||
this.root = root;
|
super(root);
|
||||||
this.req = root.retrieve();
|
|
||||||
this.receiverType = receiverType;
|
this.receiverType = receiverType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search terms.
|
* Search terms.
|
||||||
*/
|
*/
|
||||||
public GHSearchBuilder q(String term) {
|
public GHQueryBuilder<T> q(String term) {
|
||||||
terms.add(term);
|
terms.add(term);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -37,11 +34,12 @@ public abstract class GHSearchBuilder<T> {
|
|||||||
/**
|
/**
|
||||||
* Performs the search.
|
* Performs the search.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public PagedSearchIterable<T> list() {
|
public PagedSearchIterable<T> list() {
|
||||||
return new PagedSearchIterable<T>(root) {
|
return new PagedSearchIterable<T>(root) {
|
||||||
public PagedIterator<T> iterator() {
|
public PagedIterator<T> _iterator(int pageSize) {
|
||||||
req.set("q", StringUtils.join(terms, " "));
|
req.set("q", StringUtils.join(terms, " "));
|
||||||
return new PagedIterator<T>(adapt(req.asIterator(getApiUrl(), receiverType))) {
|
return new PagedIterator<T>(adapt(req.asIterator(getApiUrl(), receiverType, pageSize))) {
|
||||||
protected void wrapUp(T[] page) {
|
protected void wrapUp(T[] page) {
|
||||||
// SearchResult.getItems() should do it
|
// SearchResult.getItems() should do it
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ public class GHTeam {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHUser> listMembers() throws IOException {
|
public PagedIterable<GHUser> listMembers() throws IOException {
|
||||||
return new PagedIterable<GHUser>() {
|
return new PagedIterable<GHUser>() {
|
||||||
public PagedIterator<GHUser> iterator() {
|
public PagedIterator<GHUser> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHUser>(org.root.retrieve().asIterator(api("/members"), GHUser[].class)) {
|
return new PagedIterator<GHUser>(org.root.retrieve().asIterator(api("/members"), GHUser[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHUser[] page) {
|
protected void wrapUp(GHUser[] page) {
|
||||||
GHUser.wrap(page, org.root);
|
GHUser.wrap(page, org.root);
|
||||||
@@ -89,8 +89,8 @@ public class GHTeam {
|
|||||||
|
|
||||||
public PagedIterable<GHRepository> listRepositories() {
|
public PagedIterable<GHRepository> listRepositories() {
|
||||||
return new PagedIterable<GHRepository>() {
|
return new PagedIterable<GHRepository>() {
|
||||||
public PagedIterator<GHRepository> iterator() {
|
public PagedIterator<GHRepository> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHRepository>(org.root.retrieve().asIterator(api("/repos"), GHRepository[].class)) {
|
return new PagedIterator<GHRepository>(org.root.retrieve().asIterator(api("/repos"), GHRepository[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHRepository[] page) {
|
protected void wrapUp(GHRepository[] page) {
|
||||||
for (GHRepository r : page)
|
for (GHRepository r : page)
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ package org.kohsuke.github;
|
|||||||
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -56,8 +55,14 @@ public class GHUser extends GHPerson {
|
|||||||
*/
|
*/
|
||||||
@WithBridgeMethods(Set.class)
|
@WithBridgeMethods(Set.class)
|
||||||
public GHPersonSet<GHUser> getFollows() throws IOException {
|
public GHPersonSet<GHUser> getFollows() throws IOException {
|
||||||
GHUser[] followers = root.retrieve().to("/users/" + login + "/following", GHUser[].class);
|
return new GHPersonSet<GHUser>(listFollows().asList());
|
||||||
return new GHPersonSet<GHUser>(Arrays.asList(wrap(followers,root)));
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists the users that this user is following
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHUser> listFollows() {
|
||||||
|
return listUser("following");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,8 +70,26 @@ public class GHUser extends GHPerson {
|
|||||||
*/
|
*/
|
||||||
@WithBridgeMethods(Set.class)
|
@WithBridgeMethods(Set.class)
|
||||||
public GHPersonSet<GHUser> getFollowers() throws IOException {
|
public GHPersonSet<GHUser> getFollowers() throws IOException {
|
||||||
GHUser[] followers = root.retrieve().to("/users/" + login + "/followers", GHUser[].class);
|
return new GHPersonSet<GHUser>(listFollowers().asList());
|
||||||
return new GHPersonSet<GHUser>(Arrays.asList(wrap(followers,root)));
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists the users who are following this user.
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHUser> listFollowers() {
|
||||||
|
return listUser("followers");
|
||||||
|
}
|
||||||
|
|
||||||
|
private PagedIterable<GHUser> listUser(final String suffix) {
|
||||||
|
return new PagedIterable<GHUser>() {
|
||||||
|
public PagedIterator<GHUser> _iterator(int pageSize) {
|
||||||
|
return new PagedIterator<GHUser>(root.retrieve().asIterator(getApiTailUrl(suffix), GHUser[].class, pageSize)) {
|
||||||
|
protected void wrapUp(GHUser[] page) {
|
||||||
|
GHUser.wrap(page,root);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -75,9 +98,20 @@ public class GHUser extends GHPerson {
|
|||||||
* https://developer.github.com/v3/activity/watching/
|
* https://developer.github.com/v3/activity/watching/
|
||||||
*/
|
*/
|
||||||
public PagedIterable<GHRepository> listSubscriptions() {
|
public PagedIterable<GHRepository> listSubscriptions() {
|
||||||
|
return listRepositories("subscriptions");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lists all the repositories that this user has starred.
|
||||||
|
*/
|
||||||
|
public PagedIterable<GHRepository> listStarredRepositories() {
|
||||||
|
return listRepositories("starred");
|
||||||
|
}
|
||||||
|
|
||||||
|
private PagedIterable<GHRepository> listRepositories(final String suffix) {
|
||||||
return new PagedIterable<GHRepository>() {
|
return new PagedIterable<GHRepository>() {
|
||||||
public PagedIterator<GHRepository> iterator() {
|
public PagedIterator<GHRepository> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHRepository>(root.retrieve().asIterator(getApiTailUrl("subscriptions"), GHRepository[].class)) {
|
return new PagedIterator<GHRepository>(root.retrieve().asIterator(getApiTailUrl(suffix), GHRepository[].class, pageSize)) {
|
||||||
protected void wrapUp(GHRepository[] page) {
|
protected void wrapUp(GHRepository[] page) {
|
||||||
for (GHRepository c : page)
|
for (GHRepository c : page)
|
||||||
c.wrap(root);
|
c.wrap(root);
|
||||||
@@ -133,8 +167,8 @@ public class GHUser extends GHPerson {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHEventInfo> listEvents() throws IOException {
|
public PagedIterable<GHEventInfo> listEvents() throws IOException {
|
||||||
return new PagedIterable<GHEventInfo>() {
|
return new PagedIterable<GHEventInfo>() {
|
||||||
public PagedIterator<GHEventInfo> iterator() {
|
public PagedIterator<GHEventInfo> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHEventInfo>(root.retrieve().asIterator(String.format("/users/%s/events", login), GHEventInfo[].class)) {
|
return new PagedIterator<GHEventInfo>(root.retrieve().asIterator(String.format("/users/%s/events", login), GHEventInfo[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHEventInfo[] page) {
|
protected void wrapUp(GHEventInfo[] page) {
|
||||||
for (GHEventInfo c : page)
|
for (GHEventInfo c : page)
|
||||||
@@ -150,8 +184,8 @@ public class GHUser extends GHPerson {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHGist> listGists() throws IOException {
|
public PagedIterable<GHGist> listGists() throws IOException {
|
||||||
return new PagedIterable<GHGist>() {
|
return new PagedIterable<GHGist>() {
|
||||||
public PagedIterator<GHGist> iterator() {
|
public PagedIterator<GHGist> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHGist>(root.retrieve().asIterator(String.format("/users/%s/gists", login), GHGist[].class)) {
|
return new PagedIterator<GHGist>(root.retrieve().asIterator(String.format("/users/%s/gists", login), GHGist[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHGist[] page) {
|
protected void wrapUp(GHGist[] page) {
|
||||||
for (GHGist c : page)
|
for (GHGist c : page)
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class GHUserSearchBuilder extends GHSearchBuilder<GHUser> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GHUserSearchBuilder sort(Sort sort) {
|
public GHUserSearchBuilder sort(Sort sort) {
|
||||||
req.with("sort",sort.toString().toLowerCase(Locale.ENGLISH));
|
req.with("sort",sort);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -526,8 +526,8 @@ public class GitHub {
|
|||||||
*/
|
*/
|
||||||
public PagedIterable<GHRepository> listAllPublicRepositories(final String since) {
|
public PagedIterable<GHRepository> listAllPublicRepositories(final String since) {
|
||||||
return new PagedIterable<GHRepository>() {
|
return new PagedIterable<GHRepository>() {
|
||||||
public PagedIterator<GHRepository> iterator() {
|
public PagedIterator<GHRepository> _iterator(int pageSize) {
|
||||||
return new PagedIterator<GHRepository>(retrieve().with("since",since).asIterator("/repositories", GHRepository[].class)) {
|
return new PagedIterator<GHRepository>(retrieve().with("since",since).asIterator("/repositories", GHRepository[].class, pageSize)) {
|
||||||
@Override
|
@Override
|
||||||
protected void wrapUp(GHRepository[] page) {
|
protected void wrapUp(GHRepository[] page) {
|
||||||
for (GHRepository c : page)
|
for (GHRepository c : page)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -11,7 +12,27 @@ import java.util.Set;
|
|||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
public abstract class PagedIterable<T> implements Iterable<T> {
|
public abstract class PagedIterable<T> implements Iterable<T> {
|
||||||
public abstract PagedIterator<T> iterator();
|
/**
|
||||||
|
* Page size. 0 is default.
|
||||||
|
*/
|
||||||
|
private int size = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the pagination size.
|
||||||
|
*
|
||||||
|
* <p>
|
||||||
|
* When set to non-zero, each API call will retrieve this many entries.
|
||||||
|
*/
|
||||||
|
public PagedIterable<T> withPageSize(int size) {
|
||||||
|
this.size = size;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final PagedIterator<T> iterator() {
|
||||||
|
return _iterator(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract PagedIterator<T> _iterator(int pageSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Eagerly walk {@link Iterable} and return the result in a list.
|
* Eagerly walk {@link Iterable} and return the result in a list.
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,6 +24,11 @@ public abstract class PagedSearchIterable<T> extends PagedIterable<T> {
|
|||||||
this.root = root;
|
this.root = root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PagedSearchIterable<T> withPageSize(int size) {
|
||||||
|
return (PagedSearchIterable<T>)super.withPageSize(size);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the total number of hit, including the results that's not yet fetched.
|
* Returns the total number of hit, including the results that's not yet fetched.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -42,13 +42,12 @@ import java.net.URLEncoder;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
@@ -132,6 +131,14 @@ class Requester {
|
|||||||
return _with(key, value);
|
return _with(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Requester with(String key, Enum e) {
|
||||||
|
if (e==null) return _with(key, null);
|
||||||
|
|
||||||
|
// by convention Java constant names are upper cases, but github uses
|
||||||
|
// lower-case constants. GitHub also uses '-', which in Java we always
|
||||||
|
// replace by '_'
|
||||||
|
return with(key, e.toString().toLowerCase(Locale.ENGLISH).replace('_','-'));
|
||||||
|
}
|
||||||
|
|
||||||
public Requester with(String key, String value) {
|
public Requester with(String key, String value) {
|
||||||
return _with(key, value);
|
return _with(key, value);
|
||||||
@@ -330,104 +337,112 @@ class Requester {
|
|||||||
*
|
*
|
||||||
* Every iterator call reports a new batch.
|
* Every iterator call reports a new batch.
|
||||||
*/
|
*/
|
||||||
/*package*/ <T> Iterator<T> asIterator(final String _tailApiUrl, final Class<T> type) {
|
/*package*/ <T> Iterator<T> asIterator(String tailApiUrl, Class<T> type, int pageSize) {
|
||||||
method("GET");
|
method("GET");
|
||||||
|
|
||||||
final StringBuilder strBuilder = new StringBuilder(_tailApiUrl);
|
if (pageSize!=0)
|
||||||
|
args.add(new Entry("per_page",pageSize));
|
||||||
|
|
||||||
|
StringBuilder s = new StringBuilder(tailApiUrl);
|
||||||
if (!args.isEmpty()) {
|
if (!args.isEmpty()) {
|
||||||
boolean first=true;
|
boolean first = true;
|
||||||
try {
|
try {
|
||||||
for (Entry a : args) {
|
for (Entry a : args) {
|
||||||
strBuilder.append(first ? '?' : '&');
|
s.append(first ? '?' : '&');
|
||||||
first = false;
|
first = false;
|
||||||
strBuilder.append(URLEncoder.encode(a.key, "UTF-8"));
|
s.append(URLEncoder.encode(a.key, "UTF-8"));
|
||||||
strBuilder.append('=');
|
s.append('=');
|
||||||
strBuilder.append(URLEncoder.encode(a.value.toString(), "UTF-8"));
|
s.append(URLEncoder.encode(a.value.toString(), "UTF-8"));
|
||||||
}
|
}
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new AssertionError(e); // UTF-8 is mandatory
|
throw new AssertionError(e); // UTF-8 is mandatory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final String tailApiUrl = strBuilder.toString();
|
try {
|
||||||
|
return new PagingIterator<T>(type, root.getApiURL(s.toString()));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new Error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new Iterator<T>() {
|
class PagingIterator<T> implements Iterator<T> {
|
||||||
/**
|
|
||||||
* The next batch to be returned from {@link #next()}.
|
|
||||||
*/
|
|
||||||
T next;
|
|
||||||
/**
|
|
||||||
* URL of the next resource to be retrieved, or null if no more data is available.
|
|
||||||
*/
|
|
||||||
URL url;
|
|
||||||
|
|
||||||
{
|
private final Class<T> type;
|
||||||
try {
|
|
||||||
url = root.getApiURL(tailApiUrl);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new Error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasNext() {
|
/**
|
||||||
fetch();
|
* The next batch to be returned from {@link #next()}.
|
||||||
return next!=null;
|
*/
|
||||||
}
|
private T next;
|
||||||
|
|
||||||
public T next() {
|
/**
|
||||||
fetch();
|
* URL of the next resource to be retrieved, or null if no more data is available.
|
||||||
T r = next;
|
*/
|
||||||
if (r==null) throw new NoSuchElementException();
|
private URL url;
|
||||||
next = null;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove() {
|
PagingIterator(Class<T> type, URL url) {
|
||||||
throw new UnsupportedOperationException();
|
this.url = url;
|
||||||
}
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
private void fetch() {
|
public boolean hasNext() {
|
||||||
if (next!=null) return; // already fetched
|
fetch();
|
||||||
if (url==null) return; // no more data to fetch
|
return next!=null;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
public T next() {
|
||||||
while (true) {// loop while API rate limit is hit
|
fetch();
|
||||||
setupConnection(url);
|
T r = next;
|
||||||
try {
|
if (r==null) throw new NoSuchElementException();
|
||||||
next = parse(type,null);
|
next = null;
|
||||||
assert next!=null;
|
return r;
|
||||||
findNextURL();
|
}
|
||||||
return;
|
|
||||||
} catch (IOException e) {
|
|
||||||
handleApiError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new Error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public void remove() {
|
||||||
* Locate the next page from the pagination "Link" tag.
|
throw new UnsupportedOperationException();
|
||||||
*/
|
}
|
||||||
private void findNextURL() throws MalformedURLException {
|
|
||||||
url = null; // start defensively
|
|
||||||
String link = uc.getHeaderField("Link");
|
|
||||||
if (link==null) return;
|
|
||||||
|
|
||||||
for (String token : link.split(", ")) {
|
private void fetch() {
|
||||||
if (token.endsWith("rel=\"next\"")) {
|
if (next!=null) return; // already fetched
|
||||||
// found the next page. This should look something like
|
if (url==null) return; // no more data to fetch
|
||||||
// <https://api.github.com/repos?page=3&per_page=100>; rel="next"
|
|
||||||
int idx = token.indexOf('>');
|
try {
|
||||||
url = new URL(token.substring(1,idx));
|
while (true) {// loop while API rate limit is hit
|
||||||
|
setupConnection(url);
|
||||||
|
try {
|
||||||
|
next = parse(type,null);
|
||||||
|
assert next!=null;
|
||||||
|
findNextURL();
|
||||||
return;
|
return;
|
||||||
|
} catch (IOException e) {
|
||||||
|
handleApiError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
// no more "next" link. we are done.
|
throw new Error(e);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Locate the next page from the pagination "Link" tag.
|
||||||
|
*/
|
||||||
|
private void findNextURL() throws MalformedURLException {
|
||||||
|
url = null; // start defensively
|
||||||
|
String link = uc.getHeaderField("Link");
|
||||||
|
if (link==null) return;
|
||||||
|
|
||||||
|
for (String token : link.split(", ")) {
|
||||||
|
if (token.endsWith("rel=\"next\"")) {
|
||||||
|
// found the next page. This should look something like
|
||||||
|
// <https://api.github.com/repos?page=3&per_page=100>; rel="next"
|
||||||
|
int idx = token.indexOf('>');
|
||||||
|
url = new URL(token.substring(1,idx));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// no more "next" link. we are done.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -501,6 +516,7 @@ class Requester {
|
|||||||
|
|
||||||
if ("0".equals(uc.getHeaderField("X-RateLimit-Remaining"))) {
|
if ("0".equals(uc.getHeaderField("X-RateLimit-Remaining"))) {
|
||||||
root.rateLimitHandler.onError(e,uc);
|
root.rateLimitHandler.onError(e,uc);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
InputStream es = wrapStream(uc.getErrorStream());
|
InputStream es = wrapStream(uc.getErrorStream());
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|||||||
*
|
*
|
||||||
* @author Kohsuke Kawaguchi
|
* @author Kohsuke Kawaguchi
|
||||||
*/
|
*/
|
||||||
|
|
||||||
abstract class SearchResult<T> {
|
abstract class SearchResult<T> {
|
||||||
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization")
|
@SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "Field comes from JSON deserialization")
|
||||||
int total_count;
|
int total_count;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import org.kohsuke.github.GHRepository;
|
import org.kohsuke.github.GHRepository;
|
||||||
|
import org.kohsuke.github.GHUser;
|
||||||
import org.kohsuke.github.GitHub;
|
import org.kohsuke.github.GitHub;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -14,4 +15,11 @@ public class Foo {
|
|||||||
}
|
}
|
||||||
System.out.println(lst.size());
|
System.out.println(lst.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void testRateLimit() throws Exception {
|
||||||
|
GitHub g = GitHub.connectAnonymously();
|
||||||
|
for (GHUser u : g.getOrganization("jenkinsci").listMembers()) {
|
||||||
|
u.getFollowersCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.kohsuke.github;
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.collect.Iterators;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -13,4 +15,14 @@ public class CommitTest extends AbstractGitHubApiTestBase {
|
|||||||
GHTag t = gitHub.getRepository("stapler/stapler").listTags().iterator().next();
|
GHTag t = gitHub.getRepository("stapler/stapler").listTags().iterator().next();
|
||||||
t.getCommit().getLastStatus();
|
t.getCommit().getLastStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // issue 230
|
||||||
|
public void listFiles() throws Exception {
|
||||||
|
GHRepository repo = gitHub.getRepository("stapler/stapler");
|
||||||
|
PagedIterable<GHCommit> commits = repo.queryCommits().path("pom.xml").list();
|
||||||
|
for (GHCommit commit : Iterables.limit(commits, 10)) {
|
||||||
|
GHCommit expected = repo.getCommit( commit.getSHA1() );
|
||||||
|
assertEquals(expected.getFiles().size(), commit.getFiles().size());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public class RepositoryMockTest {
|
|||||||
|
|
||||||
|
|
||||||
when(requester.asIterator("/repos/*/*/collaborators",
|
when(requester.asIterator("/repos/*/*/collaborators",
|
||||||
GHUser[].class)).thenReturn(iterator, iterator);
|
GHUser[].class, 0)).thenReturn(iterator, iterator);
|
||||||
|
|
||||||
|
|
||||||
PagedIterable<GHUser> pagedIterable = Mockito.mock(PagedIterable.class);
|
PagedIterable<GHUser> pagedIterable = Mockito.mock(PagedIterable.class);
|
||||||
|
|||||||
30
src/test/java/org/kohsuke/github/UserTest.java
Normal file
30
src/test/java/org/kohsuke/github/UserTest.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package org.kohsuke.github;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Kohsuke Kawaguchi
|
||||||
|
*/
|
||||||
|
public class UserTest extends AbstractGitHubApiTestBase {
|
||||||
|
@Test
|
||||||
|
public void listFollowsAndFollowers() throws IOException {
|
||||||
|
GHUser u = gitHub.getUser("rtyler");
|
||||||
|
assertNotEquals(
|
||||||
|
count50(u.listFollowers()),
|
||||||
|
count50(u.listFollows()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Set<GHUser> count50(PagedIterable<GHUser> l) {
|
||||||
|
Set<GHUser> users = new HashSet<GHUser>();
|
||||||
|
PagedIterator<GHUser> itr = l.iterator();
|
||||||
|
for (int i=0; i<50 && itr.hasNext(); i++) {
|
||||||
|
users.add(itr.next());
|
||||||
|
}
|
||||||
|
assertEquals(50, users.size());
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user