Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 559cc37

Browse filesBrowse files
committed
added pull request support
1 parent 4b58162 commit 559cc37
Copy full SHA for 559cc37

File tree

Expand file treeCollapse file tree

5 files changed

+298
-1
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+298
-1
lines changed
+71Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2010, Kohsuke Kawaguchi
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
22+
* THE SOFTWARE.
23+
*/
24+
package org.kohsuke.github;
25+
26+
/**
27+
* Identifies a commit in {@link GHPullRequest}.
28+
*
29+
* @author Kohsuke Kawaguchi
30+
*/
31+
public class GHCommitPointer {
32+
private String ref, sha, label;
33+
private GHUser user;
34+
private GHRepository repository;
35+
36+
/**
37+
* This points to the user who owns
38+
* the {@link #repository}.
39+
*/
40+
public GHUser getUser() {
41+
return user;
42+
}
43+
44+
/**
45+
* The repository that contains the commit.
46+
*/
47+
public GHRepository getRepository() {
48+
return repository;
49+
}
50+
51+
/**
52+
* Named ref to the commit.
53+
*/
54+
public String getRef() {
55+
return ref;
56+
}
57+
58+
/**
59+
* SHA1 of the commit.
60+
*/
61+
public String getSha() {
62+
return sha;
63+
}
64+
65+
/**
66+
* String that looks like "USERNAME:REF".
67+
*/
68+
public String getLabel() {
69+
return label;
70+
}
71+
}
+129Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2010, Kohsuke Kawaguchi
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
22+
* THE SOFTWARE.
23+
*/
24+
package org.kohsuke.github;
25+
26+
import java.net.URL;
27+
import java.util.Date;
28+
import java.util.Locale;
29+
30+
/**
31+
* A pull request.
32+
*
33+
* @author Kohsuke Kawaguchi
34+
*/
35+
@SuppressWarnings({"UnusedDeclaration"})
36+
public class GHPullRequest {
37+
/*package almost final*/ GitHub root;
38+
39+
private String gravatar_id, closed_at, state, body, created_at, patch_url, issue_updated_at;
40+
private int number, position, comments, votes;
41+
private GHUser issue_user, user;
42+
// labels??
43+
private GHCommitPointer base, head;
44+
private String mergeable, updated_at, html_url, title, diff_url;
45+
46+
public enum State {
47+
OPEN, CLOSED
48+
}
49+
50+
/**
51+
* The description of this pull request.
52+
*/
53+
public String getBody() {
54+
return body;
55+
}
56+
57+
/**
58+
* The URL of the patch file.
59+
* like https://github.com/jenkinsci/jenkins/pull/100.patch
60+
*/
61+
public URL getPatchUrl() {
62+
return GitHub.parseURL(patch_url);
63+
}
64+
65+
/**
66+
* ID.
67+
*/
68+
public int getNumber() {
69+
return number;
70+
}
71+
72+
/**
73+
* User who submitted a pull request.
74+
*/
75+
public GHUser getUser() {
76+
return user;
77+
}
78+
79+
/**
80+
* This points to where the change should be pulled into,
81+
* but I'm not really sure what exactly it means.
82+
*/
83+
public GHCommitPointer getBase() {
84+
return base;
85+
}
86+
87+
/**
88+
* The change that should be pulled.
89+
*/
90+
public GHCommitPointer getHead() {
91+
return head;
92+
}
93+
94+
/**
95+
* The HTML page of this pull request,
96+
* like https://github.com/jenkinsci/jenkins/pull/100
97+
*/
98+
public URL getUrl() {
99+
return GitHub.parseURL(html_url);
100+
}
101+
102+
public String getTitle() {
103+
return title;
104+
}
105+
106+
/**
107+
* The diff file,
108+
* like https://github.com/jenkinsci/jenkins/pull/100.diff
109+
*/
110+
public URL getDiffUrl() {
111+
return GitHub.parseURL(diff_url);
112+
}
113+
114+
public Date getClosedAt() {
115+
return GitHub.parseDate(closed_at);
116+
}
117+
118+
public Date getCreatedAt() {
119+
return GitHub.parseDate(created_at);
120+
}
121+
122+
public Date getUpdatedAt() {
123+
return GitHub.parseDate(updated_at);
124+
}
125+
126+
public State getState() {
127+
return State.valueOf(state.toUpperCase(Locale.ENGLISH));
128+
}
129+
}

‎src/main/java/org/kohsuke/github/GHRepository.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+23-1Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.HashSet;
4444
import java.util.Iterator;
4545
import java.util.List;
46+
import java.util.Locale;
4647
import java.util.Set;
4748

4849
import static java.util.Arrays.*;
@@ -52,6 +53,7 @@
5253
*
5354
* @author Kohsuke Kawaguchi
5455
*/
56+
@SuppressWarnings({"UnusedDeclaration"})
5557
public class GHRepository {
5658
/*package almost final*/ GitHub root;
5759

@@ -167,7 +169,7 @@ public void setEmailServiceHook(String address) throws IOException {
167169
active.setChecked(true);
168170

169171
final HtmlForm f = email.getEnclosingFormOrDie();
170-
f.submit((HtmlButton)f.getElementsByTagName("button").get(0));
172+
f.submit((HtmlButton) f.getElementsByTagName("button").get(0));
171173
}
172174

173175
/**
@@ -249,6 +251,26 @@ public void renameTo(String newName) throws IOException {
249251
throw new IllegalArgumentException("Either you don't have the privilege to rename "+owner+'/'+name+" or there's a bug in HTML scraping");
250252
}
251253

254+
/**
255+
* Retrieves a specified pull request.
256+
*/
257+
public GHPullRequest getPullRequest(int i) throws IOException {
258+
return root.retrieveWithAuth("/pulls/" + owner + '/' + name + "/" + i, JsonPullRequest.class).wrap(root);
259+
}
260+
261+
/**
262+
* Retrieves all the pull requests of a particular state.
263+
*/
264+
public List<GHPullRequest> getPullRequests(GHPullRequest.State state) throws IOException {
265+
return root.retrieveWithAuth("/pulls/"+owner+'/'+name+"/"+state.name().toLowerCase(Locale.ENGLISH),JsonPullRequests.class).wrap(root);
266+
}
267+
268+
/**
269+
* Retrieves all the pull requests.
270+
*/
271+
public List<GHPullRequest> getPullRequests() throws IOException {
272+
return root.retrieveWithAuth("/pulls/"+owner+'/'+name,JsonPullRequests.class).wrap(root);
273+
}
252274

253275
private void verifyMine() throws IOException {
254276
if (!root.login.equals(owner))
+36Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2010, Kohsuke Kawaguchi
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
22+
* THE SOFTWARE.
23+
*/
24+
package org.kohsuke.github;
25+
26+
/**
27+
* @author Kohsuke Kawaguchi
28+
*/
29+
class JsonPullRequest {
30+
public GHPullRequest pull;
31+
32+
public GHPullRequest wrap(GitHub root) {
33+
pull.root = root;
34+
return pull;
35+
}
36+
}
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2010, Kohsuke Kawaguchi
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
22+
* THE SOFTWARE.
23+
*/
24+
package org.kohsuke.github;
25+
26+
import java.util.List;
27+
28+
/**
29+
* @author Kohsuke Kawaguchi
30+
*/
31+
class JsonPullRequests {
32+
public List<GHPullRequest> pulls;
33+
34+
public List<GHPullRequest> wrap(GitHub root) {
35+
for (GHPullRequest pull : pulls)
36+
pull.root = root;
37+
return pulls;
38+
}
39+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.