Skip to content

Commit

Permalink
Use PagedIterator<GHIssue> to retrieve repository issues. Overcomes
Browse files Browse the repository at this point in the history
default 30 item page size limit.
  • Loading branch information
endeavor85 committed Nov 24, 2013
1 parent 2144100 commit 4188758
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,24 @@ public GHIssueBuilder createIssue(String title) {
}

public List<GHIssue> getIssues(GHIssueState state) throws IOException {
return Arrays.asList(GHIssue.wrap(root.retrieve().to("/repos/" + owner.login + "/" + name + "/issues?state=" + state.toString().toLowerCase(), GHIssue[].class), this));
return listIssues(state).asList();
}

/**
* Lists up all the issues in this repository.
*/
public PagedIterable<GHIssue> listIssues(final GHIssueState state) {
return new PagedIterable<GHIssue>() {
public PagedIterator<GHIssue> iterator() {
return new PagedIterator<GHIssue>(root.retrieve().asIterator(getApiTailUrl("issues?state="+state.toString().toLowerCase(Locale.ENGLISH)), GHIssue[].class)) {
@Override
protected void wrapUp(GHIssue[] page) {
for (GHIssue c : page)
c.wrap(GHRepository.this);
}
};
}
};
}

public GHReleaseBuilder createRelease(String tag) {
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/org/kohsuke/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ public void testCreateIssue() throws IOException {
o.close();
}

public void testGetIssues() throws Exception {
List<GHIssue> closedIssues = gitHub.getUser("kohsuke").getRepository("github-api").getIssues(GHIssueState.CLOSED);
// prior to using PagedIterable GHRepository.getIssues(GHIssueState) would only retrieve 30 issues
assertTrue(closedIssues.size() > 30);
}

public void testRateLimit() throws IOException {
System.out.println(gitHub.getRateLimit());
}
Expand Down

0 comments on commit 4188758

Please sign in to comment.