-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more comprehensive API to list pull requests
This fixes issue #234
- Loading branch information
Showing
7 changed files
with
120 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.kohsuke.github; | ||
|
||
/** | ||
* Sort direction | ||
* | ||
* @author Kohsuke Kawaguchi | ||
*/ | ||
public enum GHDirection { | ||
ASC, DESC | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/org/kohsuke/github/GHPullRequestQueryBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
}; | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters