Skip to content

Commit

Permalink
user, push, pull event extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
seregamorph committed Sep 24, 2020
1 parent 07a392c commit b7d03f7
Show file tree
Hide file tree
Showing 4 changed files with 619 additions and 6 deletions.
24 changes: 22 additions & 2 deletions src/main/java/org/kohsuke/github/GHEventPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ public static class PullRequest extends GHEventPayload {
private int number;
private GHPullRequest pull_request;
private GHRepository repository;
private GHLabel label;

/**
* Gets action.
Expand Down Expand Up @@ -420,6 +421,15 @@ public GHRepository getRepository() {
return repository;
}

/**
* Gets label.
*
* @return the label
*/
public GHLabel getLabel() {
return label;
}

@Override
void wrapUp(GitHub root) {
super.wrapUp(root);
Expand Down Expand Up @@ -1280,6 +1290,7 @@ public static class Push extends GHEventPayload {
private List<PushCommit> commits;
private GHRepository repository;
private Pusher pusher;
private String compare;

/**
* The SHA of the HEAD commit on the repository
Expand Down Expand Up @@ -1387,6 +1398,15 @@ public void setPusher(Pusher pusher) {
this.pusher = pusher;
}

/**
* Gets compare.
*
* @return compare
*/
public String getCompare() {
return compare;
}

@Override
void wrapUp(GitHub root) {
super.wrapUp(root);
Expand Down Expand Up @@ -1440,7 +1460,7 @@ public void setEmail(String email) {
}

/**
* Commit in a push
* Commit in a push. Note: sha is an alias for id.
*/
public static class PushCommit {
private GitUser author;
Expand Down Expand Up @@ -1477,7 +1497,7 @@ public String getUrl() {
}

/**
* Gets sha.
* Gets sha (id).
*
* @return the sha
*/
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/org/kohsuke/github/GitUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
justification = "JSON API")
public class GitUser {
private String name, email, date;
private String name, email, date, username;

/**
* Gets name.
* Gets name (e.g. from git commit).
*
* @return Human readable name of the user, such as "Kohsuke Kawaguchi"
*/
Expand All @@ -27,14 +27,23 @@ public String getName() {
}

/**
* Gets email.
* Gets email (e.g. from git commit).
*
* @return E -mail address, such as "[email protected]"
* @return E-mail address, such as "[email protected]"
*/
public String getEmail() {
return email;
}

/**
* Gets username.
*
* @return GitHub username
*/
public String getUsername() {
return username;
}

/**
* Gets date.
*
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/org/kohsuke/github/GHEventPayloadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Collections;
import java.util.TimeZone;

import static java.lang.Boolean.TRUE;
import static org.hamcrest.Matchers.*;

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

@Test
public void pull_request_labeled() throws Exception {
GHEventPayload.PullRequest event = GitHub.offline()
.parseEventPayload(payload.asReader(), GHEventPayload.PullRequest.class);
assertThat(event.getAction(), is("labeled"));
assertThat(event.getNumber(), is(79));
assertThat(event.getPullRequest().getNumber(), is(79));
assertThat(event.getPullRequest().getTitle(), is("Base POJO test enhancement"));
assertThat(event.getPullRequest().getBody(),
is("This is a pretty simple change that we need to pull into develop."));
assertThat(event.getPullRequest().getUser().getLogin(), is("seregamorph"));
assertThat(event.getPullRequest().getHead().getUser().getLogin(), is("trilogy-group"));
assertThat(event.getPullRequest().getHead().getRef(), is("changes"));
assertThat(event.getPullRequest().getHead().getLabel(), is("trilogy-group:changes"));
assertThat(event.getPullRequest().getHead().getSha(), is("4b91e3a970fb967fb7be4d52e0969f8e3fb063d0"));
assertThat(event.getPullRequest().getBase().getUser().getLogin(), is("trilogy-group"));
assertThat(event.getPullRequest().getBase().getRef(), is("3.10"));
assertThat(event.getPullRequest().getBase().getLabel(), is("trilogy-group:3.10"));
assertThat(event.getPullRequest().getBase().getSha(), is("7a735f17d686c6a1fc7df5b9d395e5863868f364"));
assertThat(event.getPullRequest().isMerged(), is(false));
assertThat(event.getPullRequest().getMergeable(), is(TRUE));
assertThat(event.getPullRequest().getMergeableState(), is("draft"));
assertThat(event.getPullRequest().getMergedBy(), nullValue());
assertThat(event.getPullRequest().getCommentsCount(), is(1));
assertThat(event.getPullRequest().getReviewComments(), is(14));
assertThat(event.getPullRequest().getAdditions(), is(137));
assertThat(event.getPullRequest().getDeletions(), is(81));
assertThat(event.getPullRequest().getChangedFiles(), is(22));
assertThat(event.getRepository().getName(), is("trilogy-rest-api-framework"));
assertThat(event.getRepository().getOwner().getLogin(), is("trilogy-group"));
assertThat(event.getSender().getLogin(), is("schernov-xo"));
assertThat(event.getLabel().getUrl(),
is("https://api.github.com/repos/trilogy-group/trilogy-rest-api-framework/labels/rest%20api"));
assertThat(event.getLabel().getName(), is("rest api"));
assertThat(event.getLabel().getColor(), is("fef2c0"));
assertThat(event.getLabel().getDescription(), is("REST API pull request"));
}

@Test
public void pull_request_review() throws Exception {
GHEventPayload.PullRequestReview event = GitHub.offline()
Expand Down Expand Up @@ -272,7 +311,9 @@ public void push() throws Exception {
assertThat(event.getCommits().size(), is(1));
assertThat(event.getCommits().get(0).getSha(), is("0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c"));
assertThat(event.getCommits().get(0).getAuthor().getEmail(), is("[email protected]"));
assertThat(event.getCommits().get(0).getAuthor().getUsername(), is("baxterthehacker"));
assertThat(event.getCommits().get(0).getCommitter().getEmail(), is("[email protected]"));
assertThat(event.getCommits().get(0).getCommitter().getUsername(), is("baxterthehacker"));
assertThat(event.getCommits().get(0).getAdded().size(), is(0));
assertThat(event.getCommits().get(0).getRemoved().size(), is(0));
assertThat(event.getCommits().get(0).getModified().size(), is(1));
Expand All @@ -284,6 +325,8 @@ public void push() throws Exception {
assertThat(event.getPusher().getName(), is("baxterthehacker"));
assertThat(event.getPusher().getEmail(), is("[email protected]"));
assertThat(event.getSender().getLogin(), is("baxterthehacker"));
assertThat(event.getCompare(),
is("https://github.com/baxterthehacker/public-repo/compare/9049f1265b7d...0d1a26e67d8f"));
}

@Test
Expand Down
Loading

0 comments on commit b7d03f7

Please sign in to comment.