mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-10 15:49:57 +00:00
Merge branch 'pull-15'
This commit is contained in:
@@ -358,12 +358,28 @@ public class GHRepository {
|
||||
|
||||
/**
|
||||
* Retrieves all the pull requests of a particular state.
|
||||
*
|
||||
* @see #listPullRequests(GHIssueState)
|
||||
*/
|
||||
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);
|
||||
for (GHPullRequest p : r)
|
||||
p.wrapUp(this);
|
||||
return new ArrayList<GHPullRequest>(Arrays.asList(r));
|
||||
return listPullRequests(state).asList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,24 @@
|
||||
package org.kohsuke.github;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* {@link Iterable} that returns {@link PagedIterator}
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public interface PagedIterable<T> extends Iterable<T> {
|
||||
PagedIterator<T> iterator();
|
||||
public abstract class PagedIterable<T> implements Iterable<T> {
|
||||
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.GHOrganization;
|
||||
import org.kohsuke.github.GHOrganization.Permission;
|
||||
import org.kohsuke.github.GHPullRequest;
|
||||
import org.kohsuke.github.GHRepository;
|
||||
import org.kohsuke.github.GHTeam;
|
||||
import org.kohsuke.github.GHUser;
|
||||
import org.kohsuke.github.GitHub;
|
||||
import org.kohsuke.github.PagedIterable;
|
||||
import org.kohsuke.github.PagedIterator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
@@ -64,6 +66,16 @@ public class AppTest extends TestCase {
|
||||
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 {
|
||||
GitHub gh = GitHub.connect();
|
||||
GHRepository r = gh.getOrganization("jenkinsci").getRepository("jenkins");
|
||||
|
||||
Reference in New Issue
Block a user