Skip to content

Commit bfefeae

Browse files
committed
Merged pull request hub4j#45 with some changes
2 parents d82af9f + ebf953c commit bfefeae

File tree

3 files changed

+171
-3
lines changed

3 files changed

+171
-3
lines changed

src/main/java/org/kohsuke/github/GHPerson.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,25 @@ public synchronized Map<String,GHRepository> getRepositories() throws IOExceptio
5555
}
5656

5757
/**
58-
* Lists up all the repositories.
58+
* Lists up all the repositories using a 30 items page size.
5959
*
6060
* Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned.
6161
*/
6262
public PagedIterable<GHRepository> listRepositories() {
63+
return listRepositories(30);
64+
}
65+
66+
/**
67+
* Lists up all the repositories using the specified page size.
68+
*
69+
* @param pageSize size for each page of items returned by GitHub. Maximum page size is 100.
70+
*
71+
* Unlike {@link #getRepositories()}, this does not wait until all the repositories are returned.
72+
*/
73+
public PagedIterable<GHRepository> listRepositories(final int pageSize) {
6374
return new PagedIterable<GHRepository>() {
6475
public PagedIterator<GHRepository> iterator() {
65-
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/users/" + login + "/repos", GHRepository[].class)) {
76+
return new PagedIterator<GHRepository>(root.retrieve().asIterator("/users/" + login + "/repos?per_page=" + pageSize, GHRepository[].class)) {
6677
@Override
6778
protected void wrapUp(GHRepository[] page) {
6879
for (GHRepository c : page)
@@ -224,5 +235,4 @@ public int getFollowersCount() throws IOException {
224235
populate();
225236
return followers;
226237
}
227-
228238
}

src/main/java/org/kohsuke/github/GHPullRequest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.net.URL;
2828
import java.util.Collection;
2929
import java.util.Date;
30+
import java.util.Locale;
3031

3132
/**
3233
* A pull request.
@@ -186,4 +187,22 @@ private void populate() throws IOException {
186187

187188
root.retrieve().to(url, this);
188189
}
190+
191+
/**
192+
* Retrieves all the commits associated to this pull request.
193+
*/
194+
public PagedIterable<GHPullRequestCommitDetail> listCommits() {
195+
return new PagedIterable<GHPullRequestCommitDetail>() {
196+
public PagedIterator<GHPullRequestCommitDetail> iterator() {
197+
return new PagedIterator<GHPullRequestCommitDetail>(root.retrieve().asIterator(
198+
String.format("%s/commits", getApiURL().getPath()),
199+
GHPullRequestCommitDetail[].class)) {
200+
@Override
201+
protected void wrapUp(GHPullRequestCommitDetail[] page) {
202+
}
203+
};
204+
}
205+
};
206+
}
207+
189208
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2013, Luca Milanesio
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package org.kohsuke.github;
25+
26+
import java.net.URL;
27+
import java.util.Date;
28+
29+
/**
30+
* Commit detail inside a {@link GHPullRequest}.
31+
*
32+
* @author Luca Milanesio
33+
*/
34+
public class GHPullRequestCommitDetail {
35+
36+
public static class Authorship {
37+
String name;
38+
String email;
39+
String date;
40+
41+
public String getName() {
42+
return name;
43+
}
44+
45+
public String getEmail() {
46+
return email;
47+
}
48+
49+
public Date getDate() {
50+
return GitHub.parseDate(date);
51+
}
52+
}
53+
54+
public static class Tree {
55+
String sha;
56+
String url;
57+
58+
public String getSha() {
59+
return sha;
60+
}
61+
62+
public URL getUrl() {
63+
return GitHub.parseURL(url);
64+
}
65+
}
66+
67+
public static class Commit {
68+
Authorship author;
69+
Authorship committer;
70+
String message;
71+
Tree tree;
72+
String url;
73+
int comment_count;
74+
75+
public Authorship getAuthor() {
76+
return author;
77+
}
78+
79+
public Authorship getCommitter() {
80+
return committer;
81+
}
82+
83+
public String getMessage() {
84+
return message;
85+
}
86+
87+
public URL getUrl() {
88+
return GitHub.parseURL(url);
89+
}
90+
91+
public int getComment_count() {
92+
return comment_count;
93+
}
94+
}
95+
96+
public static class CommitPointer {
97+
String sha;
98+
String url;
99+
String html_url;
100+
101+
public URL getUrl() {
102+
return GitHub.parseURL(url);
103+
}
104+
105+
public URL getHtml_url() {
106+
return GitHub.parseURL(html_url);
107+
}
108+
109+
public String getSha() {
110+
return sha;
111+
}
112+
}
113+
114+
String sha;
115+
Commit commit;
116+
String url;
117+
String html_url;
118+
String comments_url;
119+
CommitPointer[] parents;
120+
121+
public String getSha() {
122+
return sha;
123+
}
124+
public Commit getCommit() {
125+
return commit;
126+
}
127+
public URL getApiUrl() {
128+
return GitHub.parseURL(url);
129+
}
130+
public URL getUrl() {
131+
return GitHub.parseURL(html_url);
132+
}
133+
public URL getCommentsUrl() {
134+
return GitHub.parseURL(comments_url);
135+
}
136+
public CommitPointer[] getParents() {
137+
return parents;
138+
}
139+
}

0 commit comments

Comments
 (0)