Skip to content

Commit d4c5c6a

Browse files
authored
Merge pull request #944 from seregamorph/feature/push-pulls-extensions
user, push, pull event extensions
2 parents 63fda35 + 6e3f754 commit d4c5c6a

File tree

4 files changed

+624
-6
lines changed

4 files changed

+624
-6
lines changed

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ public static class PullRequest extends GHEventPayload {
382382
private int number;
383383
private GHPullRequest pull_request;
384384
private GHRepository repository;
385+
private GHLabel label;
385386

386387
/**
387388
* Gets action.
@@ -420,6 +421,15 @@ public GHRepository getRepository() {
420421
return repository;
421422
}
422423

424+
/**
425+
* Gets label.
426+
*
427+
* @return the label
428+
*/
429+
public GHLabel getLabel() {
430+
return label;
431+
}
432+
423433
@Override
424434
void wrapUp(GitHub root) {
425435
super.wrapUp(root);
@@ -1280,6 +1290,7 @@ public static class Push extends GHEventPayload {
12801290
private List<PushCommit> commits;
12811291
private GHRepository repository;
12821292
private Pusher pusher;
1293+
private String compare;
12831294

12841295
/**
12851296
* The SHA of the HEAD commit on the repository
@@ -1387,6 +1398,15 @@ public void setPusher(Pusher pusher) {
13871398
this.pusher = pusher;
13881399
}
13891400

1401+
/**
1402+
* Gets compare.
1403+
*
1404+
* @return compare
1405+
*/
1406+
public String getCompare() {
1407+
return compare;
1408+
}
1409+
13901410
@Override
13911411
void wrapUp(GitHub root) {
13921412
super.wrapUp(root);
@@ -1440,7 +1460,7 @@ public void setEmail(String email) {
14401460
}
14411461

14421462
/**
1443-
* Commit in a push
1463+
* Commit in a push. Note: sha is an alias for id.
14441464
*/
14451465
public static class PushCommit {
14461466
private GitUser author;
@@ -1477,7 +1497,7 @@ public String getUrl() {
14771497
}
14781498

14791499
/**
1480-
* Gets sha.
1500+
* Gets sha (id).
14811501
*
14821502
* @return the sha
14831503
*/

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import java.util.Date;
66

7+
import javax.annotation.CheckForNull;
8+
79
/**
810
* Represents a user in Git who authors/commits a commit.
911
* <p>
@@ -15,10 +17,10 @@
1517
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
1618
justification = "JSON API")
1719
public class GitUser {
18-
private String name, email, date;
20+
private String name, email, date, username;
1921

2022
/**
21-
* Gets name.
23+
* Gets the git user name for an author or committer on a git commit.
2224
*
2325
* @return Human readable name of the user, such as "Kohsuke Kawaguchi"
2426
*/
@@ -27,14 +29,26 @@ public String getName() {
2729
}
2830

2931
/**
30-
* Gets email.
32+
* Gets the git email for an author or committer on a git commit.
3133
*
32-
* @return E -mail address, such as "foo@example.com"
34+
* @return E-mail address, such as "foo@example.com"
3335
*/
3436
public String getEmail() {
3537
return email;
3638
}
3739

40+
/**
41+
* Gets username. Note: it presents only in events.
42+
*
43+
* @return GitHub username
44+
*/
45+
@Preview
46+
@Deprecated
47+
@CheckForNull
48+
public String getUsername() {
49+
return username;
50+
}
51+
3852
/**
3953
* Gets date.
4054
*

src/test/java/org/kohsuke/github/GHEventPayloadTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Collections;
99
import java.util.TimeZone;
1010

11+
import static java.lang.Boolean.TRUE;
1112
import static org.hamcrest.Matchers.*;
1213

1314
public class GHEventPayloadTest extends AbstractGitHubWireMockTest {
@@ -203,6 +204,44 @@ public void pull_request() throws Exception {
203204
assertThat(event.getSender().getLogin(), is("baxterthehacker"));
204205
}
205206

207+
@Test
208+
public void pull_request_labeled() throws Exception {
209+
GHEventPayload.PullRequest event = GitHub.offline()
210+
.parseEventPayload(payload.asReader(), GHEventPayload.PullRequest.class);
211+
assertThat(event.getAction(), is("labeled"));
212+
assertThat(event.getNumber(), is(79));
213+
assertThat(event.getPullRequest().getNumber(), is(79));
214+
assertThat(event.getPullRequest().getTitle(), is("Base POJO test enhancement"));
215+
assertThat(event.getPullRequest().getBody(),
216+
is("This is a pretty simple change that we need to pull into develop."));
217+
assertThat(event.getPullRequest().getUser().getLogin(), is("seregamorph"));
218+
assertThat(event.getPullRequest().getHead().getUser().getLogin(), is("trilogy-group"));
219+
assertThat(event.getPullRequest().getHead().getRef(), is("changes"));
220+
assertThat(event.getPullRequest().getHead().getLabel(), is("trilogy-group:changes"));
221+
assertThat(event.getPullRequest().getHead().getSha(), is("4b91e3a970fb967fb7be4d52e0969f8e3fb063d0"));
222+
assertThat(event.getPullRequest().getBase().getUser().getLogin(), is("trilogy-group"));
223+
assertThat(event.getPullRequest().getBase().getRef(), is("3.10"));
224+
assertThat(event.getPullRequest().getBase().getLabel(), is("trilogy-group:3.10"));
225+
assertThat(event.getPullRequest().getBase().getSha(), is("7a735f17d686c6a1fc7df5b9d395e5863868f364"));
226+
assertThat(event.getPullRequest().isMerged(), is(false));
227+
assertThat(event.getPullRequest().getMergeable(), is(TRUE));
228+
assertThat(event.getPullRequest().getMergeableState(), is("draft"));
229+
assertThat(event.getPullRequest().getMergedBy(), nullValue());
230+
assertThat(event.getPullRequest().getCommentsCount(), is(1));
231+
assertThat(event.getPullRequest().getReviewComments(), is(14));
232+
assertThat(event.getPullRequest().getAdditions(), is(137));
233+
assertThat(event.getPullRequest().getDeletions(), is(81));
234+
assertThat(event.getPullRequest().getChangedFiles(), is(22));
235+
assertThat(event.getRepository().getName(), is("trilogy-rest-api-framework"));
236+
assertThat(event.getRepository().getOwner().getLogin(), is("trilogy-group"));
237+
assertThat(event.getSender().getLogin(), is("schernov-xo"));
238+
assertThat(event.getLabel().getUrl(),
239+
is("https://api.github.com/repos/trilogy-group/trilogy-rest-api-framework/labels/rest%20api"));
240+
assertThat(event.getLabel().getName(), is("rest api"));
241+
assertThat(event.getLabel().getColor(), is("fef2c0"));
242+
assertThat(event.getLabel().getDescription(), is("REST API pull request"));
243+
}
244+
206245
@Test
207246
public void pull_request_review() throws Exception {
208247
GHEventPayload.PullRequestReview event = GitHub.offline()
@@ -274,7 +313,9 @@ public void push() throws Exception {
274313
assertThat(event.getCommits().size(), is(1));
275314
assertThat(event.getCommits().get(0).getSha(), is("0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c"));
276315
assertThat(event.getCommits().get(0).getAuthor().getEmail(), is("baxterthehacker@users.noreply.github.com"));
316+
assertThat(event.getCommits().get(0).getAuthor().getUsername(), is("baxterthehacker"));
277317
assertThat(event.getCommits().get(0).getCommitter().getEmail(), is("baxterthehacker@users.noreply.github.com"));
318+
assertThat(event.getCommits().get(0).getCommitter().getUsername(), is("baxterthehacker"));
278319
assertThat(event.getCommits().get(0).getAdded().size(), is(0));
279320
assertThat(event.getCommits().get(0).getRemoved().size(), is(0));
280321
assertThat(event.getCommits().get(0).getModified().size(), is(1));
@@ -286,6 +327,8 @@ public void push() throws Exception {
286327
assertThat(event.getPusher().getName(), is("baxterthehacker"));
287328
assertThat(event.getPusher().getEmail(), is("baxterthehacker@users.noreply.github.com"));
288329
assertThat(event.getSender().getLogin(), is("baxterthehacker"));
330+
assertThat(event.getCompare(),
331+
is("https://github.com/baxterthehacker/public-repo/compare/9049f1265b7d...0d1a26e67d8f"));
289332
}
290333

291334
@Test

0 commit comments

Comments
 (0)