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 a433bcd

Browse filesBrowse files
authored
Merge pull request hub4j#979 from seregamorph/feature/pull_request-edited
pull_request action "edited": changes
2 parents 78f533b + 0feb520 commit a433bcd
Copy full SHA for a433bcd

File tree

Expand file treeCollapse file tree

5 files changed

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

5 files changed

+1110
-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
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ public static class PullRequest extends GHEventPayload {
360360
private int number;
361361
private GHPullRequest pullRequest;
362362
private GHLabel label;
363+
private GHPullRequestChanges changes;
363364

364365
/**
365366
* Gets number.
@@ -389,6 +390,15 @@ public GHLabel getLabel() {
389390
return label;
390391
}
391392

393+
/**
394+
* Get changes (for action="edited")
395+
*
396+
* @return changes
397+
*/
398+
public GHPullRequestChanges getChanges() {
399+
return changes;
400+
}
401+
392402
@Override
393403
void wrapUp(GitHub root) {
394404
super.wrapUp(root);
+86Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package org.kohsuke.github;
2+
3+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
4+
5+
/**
6+
* Wrapper to define changed fields on pull_request action="edited"
7+
*
8+
* @see GHEventPayload.PullRequest
9+
*/
10+
@SuppressFBWarnings("UWF_UNWRITTEN_FIELD")
11+
public class GHPullRequestChanges {
12+
13+
private GHCommitPointer base;
14+
private GHFrom title;
15+
private GHFrom body;
16+
17+
/**
18+
* Old target branch for pull request.
19+
*
20+
* @return old target branch info (or null if not changed)
21+
*/
22+
public GHCommitPointer getBase() {
23+
return base;
24+
}
25+
26+
/**
27+
* Old pull request title.
28+
*
29+
* @return old pull request title (or null if not changed)
30+
*/
31+
public GHFrom getTitle() {
32+
return title;
33+
}
34+
35+
/**
36+
* Old pull request body.
37+
*
38+
* @return old pull request body (or null if not changed)
39+
*/
40+
public GHFrom getBody() {
41+
return body;
42+
}
43+
44+
/**
45+
* @see org.kohsuke.github.GHCommitPointer
46+
*/
47+
public static class GHCommitPointer {
48+
private GHFrom ref;
49+
private GHFrom sha;
50+
51+
/**
52+
* Named ref to the commit. This (from value) appears to be a "short ref" that doesn't include "refs/heads/"
53+
* portion.
54+
*
55+
* @return the ref
56+
*/
57+
public GHFrom getRef() {
58+
return ref;
59+
}
60+
61+
/**
62+
* SHA1 of the commit.
63+
*
64+
* @return sha
65+
*/
66+
public GHFrom getSha() {
67+
return sha;
68+
}
69+
}
70+
71+
/**
72+
* Wrapper for changed values.
73+
*/
74+
public static class GHFrom {
75+
private String from;
76+
77+
/**
78+
* Previous value that was changed.
79+
*
80+
* @return previous value
81+
*/
82+
public String getFrom() {
83+
return from;
84+
}
85+
}
86+
}

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

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/GHEventPayloadTest.java
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,35 @@ public void pull_request() throws Exception {
214214
assertThat(event.getSender().getLogin(), is("baxterthehacker"));
215215
}
216216

217+
@Test
218+
public void pull_request_edited_base() throws Exception {
219+
GHEventPayload.PullRequest event = GitHub.offline()
220+
.parseEventPayload(payload.asReader(), GHEventPayload.PullRequest.class);
221+
222+
assertThat(event.getAction(), is("edited"));
223+
assertThat(event.getChanges().getTitle(), nullValue());
224+
assertThat(event.getPullRequest().getTitle(), is("REST-276 - easy-random"));
225+
assertThat(event.getChanges().getBase().getRef().getFrom(), is("develop"));
226+
assertThat(event.getChanges().getBase().getSha().getFrom(), is("4b0f3b9fd582b071652ccfccd10bfc8c143cff96"));
227+
assertThat(event.getPullRequest().getBase().getRef(), is("4.3"));
228+
assertThat(event.getPullRequest().getBody(), startsWith("**JIRA Ticket URL:**"));
229+
assertThat(event.getChanges().getBody(), nullValue());
230+
}
231+
232+
@Test
233+
public void pull_request_edited_title() throws Exception {
234+
GHEventPayload.PullRequest event = GitHub.offline()
235+
.parseEventPayload(payload.asReader(), GHEventPayload.PullRequest.class);
236+
237+
assertThat(event.getAction(), is("edited"));
238+
assertThat(event.getChanges().getTitle().getFrom(), is("REST-276 - easy-random"));
239+
assertThat(event.getPullRequest().getTitle(), is("REST-276 - easy-random 4.3.0"));
240+
assertThat(event.getChanges().getBase(), nullValue());
241+
assertThat(event.getPullRequest().getBase().getRef(), is("4.3"));
242+
assertThat(event.getPullRequest().getBody(), startsWith("**JIRA Ticket URL:**"));
243+
assertThat(event.getChanges().getBody(), nullValue());
244+
}
245+
217246
@Test
218247
public void pull_request_labeled() throws Exception {
219248
GHEventPayload.PullRequest event = GitHub.offline()

0 commit comments

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