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 1876a69

Browse filesBrowse files
committed
feat: Add head_commit to GHEventPayload.Push
When that class represents a commit being pushed to a branch, the list of commits is available and useful to know what was pushed. When it represents a tag being pushed, the list of commits can be empty. The `head_commit` comes in handy to know more about the commit. This change exposes `head_commit` using the getter `getHeadCommit()`. The test data already has the data for this to work. The test case has been updated to test for this method. Refs: hub4j#1585
1 parent a9a93ad commit 1876a69
Copy full SHA for 1876a69

File tree

Expand file treeCollapse file tree

2 files changed

+23
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+23
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHEventPayload.java
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,7 @@ public static class Push extends GHEventPayload {
10431043
private String ref;
10441044
private int size;
10451045
private List<PushCommit> commits;
1046+
private PushCommit headCommit;
10461047
private Pusher pusher;
10471048
private String compare;
10481049

@@ -1124,6 +1125,16 @@ public List<PushCommit> getCommits() {
11241125
return Collections.unmodifiableList(commits);
11251126
}
11261127

1128+
/**
1129+
* The head commit of the push.
1130+
*
1131+
* @return the commit
1132+
*/
1133+
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
1134+
public PushCommit getHeadCommit() {
1135+
return headCommit;
1136+
}
1137+
11271138
/**
11281139
* Gets pusher.
11291140
*

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

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/GHEventPayloadTest.java
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,18 @@ public void push() throws Exception {
624624
assertThat(event.getCommits().get(0).getRemoved().size(), is(0));
625625
assertThat(event.getCommits().get(0).getModified().size(), is(1));
626626
assertThat(event.getCommits().get(0).getModified().get(0), is("README.md"));
627+
628+
assertThat(event.getHeadCommit().getSha(), is("0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c"));
629+
assertThat(event.getHeadCommit().getAuthor().getEmail(), is("baxterthehacker@users.noreply.github.com"));
630+
assertThat(event.getHeadCommit().getAuthor().getUsername(), is("baxterthehacker"));
631+
assertThat(event.getHeadCommit().getCommitter().getEmail(), is("baxterthehacker@users.noreply.github.com"));
632+
assertThat(event.getHeadCommit().getCommitter().getUsername(), is("baxterthehacker"));
633+
assertThat(event.getHeadCommit().getAdded().size(), is(0));
634+
assertThat(event.getHeadCommit().getRemoved().size(), is(0));
635+
assertThat(event.getHeadCommit().getModified().size(), is(1));
636+
assertThat(event.getHeadCommit().getModified().get(0), is("README.md"));
637+
assertThat(event.getHeadCommit().getMessage(), is("Update README.md"));
638+
627639
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
628640
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
629641
assertThat(formatter.format(event.getCommits().get(0).getTimestamp()), is("2015-05-05T23:40:15Z"));

0 commit comments

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