Skip to content

Commit

Permalink
Merge pull request #56 from endeavor85/master
Browse files Browse the repository at this point in the history
Use `PagedIterator<GHIssue>` to retrieve repository issues
  • Loading branch information
kohsuke committed Nov 27, 2013
2 parents 9cc9e06 + 4188758 commit a59810a
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 a59810a

Please sign in to comment.