diff --git a/src/main/java/org/kohsuke/github/GHPerson.java b/src/main/java/org/kohsuke/github/GHPerson.java index 721eeb225..92a2b90d2 100644 --- a/src/main/java/org/kohsuke/github/GHPerson.java +++ b/src/main/java/org/kohsuke/github/GHPerson.java @@ -55,14 +55,25 @@ public abstract class GHPerson { } /** - * Lists up all the repositories. + * Lists up all the repositories using a 30 items page size. * * Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned. */ public PagedIterable listRepositories() { + return listRepositories(30); + } + + /** + * Lists up all the repositories using the specified page size. + * + * @param pageSize size for each page of items returned by GitHub. Maximum page size is 100. + * + * Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned. + */ + public PagedIterable listRepositories(final int pageSize) { return new PagedIterable() { public PagedIterator iterator() { - return new PagedIterator(root.retrieve().asIterator("/users/" + login + "/repos", GHRepository[].class)) { + return new PagedIterator(root.retrieve().asIterator("/users/" + login + "/repos?per_page=" + pageSize, GHRepository[].class)) { @Override protected void wrapUp(GHRepository[] page) { for (GHRepository c : page) @@ -224,5 +235,4 @@ public abstract class GHPerson { populate(); return followers; } - } diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index 53ae5bc76..a8105eb97 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -27,6 +27,7 @@ import java.io.IOException; import java.net.URL; import java.util.Collection; import java.util.Date; +import java.util.Locale; /** * A pull request. @@ -186,4 +187,22 @@ public class GHPullRequest extends GHIssue { root.retrieve().to(url, this); } + + /** + * Retrieves all the commits associated to this pull request. + */ + public PagedIterable listCommits() { + return new PagedIterable() { + public PagedIterator iterator() { + return new PagedIterator(root.retrieve().asIterator( + String.format("%s/commits", getApiURL().getPath()), + GHPullRequestCommitDetail[].class)) { + @Override + protected void wrapUp(GHPullRequestCommitDetail[] page) { + } + }; + } + }; + } + } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestCommitDetail.java b/src/main/java/org/kohsuke/github/GHPullRequestCommitDetail.java new file mode 100644 index 000000000..8820bc3d3 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHPullRequestCommitDetail.java @@ -0,0 +1,139 @@ +/* + * The MIT License + * + * Copyright (c) 2013, Luca Milanesio + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.kohsuke.github; + +import java.net.URL; +import java.util.Date; + +/** + * Commit detail inside a {@link GHPullRequest}. + * + * @author Luca Milanesio + */ +public class GHPullRequestCommitDetail { + + public static class Authorship { + String name; + String email; + String date; + + public String getName() { + return name; + } + + public String getEmail() { + return email; + } + + public Date getDate() { + return GitHub.parseDate(date); + } + } + + public static class Tree { + String sha; + String url; + + public String getSha() { + return sha; + } + + public URL getUrl() { + return GitHub.parseURL(url); + } + } + + public static class Commit { + Authorship author; + Authorship committer; + String message; + Tree tree; + String url; + int comment_count; + + public Authorship getAuthor() { + return author; + } + + public Authorship getCommitter() { + return committer; + } + + public String getMessage() { + return message; + } + + public URL getUrl() { + return GitHub.parseURL(url); + } + + public int getComment_count() { + return comment_count; + } + } + + public static class CommitPointer { + String sha; + String url; + String html_url; + + public URL getUrl() { + return GitHub.parseURL(url); + } + + public URL getHtml_url() { + return GitHub.parseURL(html_url); + } + + public String getSha() { + return sha; + } + } + + String sha; + Commit commit; + String url; + String html_url; + String comments_url; + CommitPointer[] parents; + + public String getSha() { + return sha; + } + public Commit getCommit() { + return commit; + } + public URL getApiUrl() { + return GitHub.parseURL(url); + } + public URL getUrl() { + return GitHub.parseURL(html_url); + } + public URL getCommentsUrl() { + return GitHub.parseURL(comments_url); + } + public CommitPointer[] getParents() { + return parents; + } +}