Skip to content

Commit

Permalink
Merge pull request #979 from seregamorph/feature/pull_request-edited
Browse files Browse the repository at this point in the history
pull_request action "edited": changes
  • Loading branch information
bitwiseman committed Nov 24, 2020
2 parents 78f533b + 0feb520 commit a433bcd
Show file tree
Hide file tree
Showing 5 changed files with 1,110 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/org/kohsuke/github/GHEventPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ public static class PullRequest extends GHEventPayload {
private int number;
private GHPullRequest pullRequest;
private GHLabel label;
private GHPullRequestChanges changes;

/**
* Gets number.
Expand Down Expand Up @@ -389,6 +390,15 @@ public GHLabel getLabel() {
return label;
}

/**
* Get changes (for action="edited")
*
* @return changes
*/
public GHPullRequestChanges getChanges() {
return changes;
}

@Override
void wrapUp(GitHub root) {
super.wrapUp(root);
Expand Down
86 changes: 86 additions & 0 deletions src/main/java/org/kohsuke/github/GHPullRequestChanges.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.kohsuke.github;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Wrapper to define changed fields on pull_request action="edited"
*
* @see GHEventPayload.PullRequest
*/
@SuppressFBWarnings("UWF_UNWRITTEN_FIELD")
public class GHPullRequestChanges {

private GHCommitPointer base;
private GHFrom title;
private GHFrom body;

/**
* Old target branch for pull request.
*
* @return old target branch info (or null if not changed)
*/
public GHCommitPointer getBase() {
return base;
}

/**
* Old pull request title.
*
* @return old pull request title (or null if not changed)
*/
public GHFrom getTitle() {
return title;
}

/**
* Old pull request body.
*
* @return old pull request body (or null if not changed)
*/
public GHFrom getBody() {
return body;
}

/**
* @see org.kohsuke.github.GHCommitPointer
*/
public static class GHCommitPointer {
private GHFrom ref;
private GHFrom sha;

/**
* Named ref to the commit. This (from value) appears to be a "short ref" that doesn't include "refs/heads/"
* portion.
*
* @return the ref
*/
public GHFrom getRef() {
return ref;
}

/**
* SHA1 of the commit.
*
* @return sha
*/
public GHFrom getSha() {
return sha;
}
}

/**
* Wrapper for changed values.
*/
public static class GHFrom {
private String from;

/**
* Previous value that was changed.
*
* @return previous value
*/
public String getFrom() {
return from;
}
}
}
29 changes: 29 additions & 0 deletions src/test/java/org/kohsuke/github/GHEventPayloadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,35 @@ public void pull_request() throws Exception {
assertThat(event.getSender().getLogin(), is("baxterthehacker"));
}

@Test
public void pull_request_edited_base() throws Exception {
GHEventPayload.PullRequest event = GitHub.offline()
.parseEventPayload(payload.asReader(), GHEventPayload.PullRequest.class);

assertThat(event.getAction(), is("edited"));
assertThat(event.getChanges().getTitle(), nullValue());
assertThat(event.getPullRequest().getTitle(), is("REST-276 - easy-random"));
assertThat(event.getChanges().getBase().getRef().getFrom(), is("develop"));
assertThat(event.getChanges().getBase().getSha().getFrom(), is("4b0f3b9fd582b071652ccfccd10bfc8c143cff96"));
assertThat(event.getPullRequest().getBase().getRef(), is("4.3"));
assertThat(event.getPullRequest().getBody(), startsWith("**JIRA Ticket URL:**"));
assertThat(event.getChanges().getBody(), nullValue());
}

@Test
public void pull_request_edited_title() throws Exception {
GHEventPayload.PullRequest event = GitHub.offline()
.parseEventPayload(payload.asReader(), GHEventPayload.PullRequest.class);

assertThat(event.getAction(), is("edited"));
assertThat(event.getChanges().getTitle().getFrom(), is("REST-276 - easy-random"));
assertThat(event.getPullRequest().getTitle(), is("REST-276 - easy-random 4.3.0"));
assertThat(event.getChanges().getBase(), nullValue());
assertThat(event.getPullRequest().getBase().getRef(), is("4.3"));
assertThat(event.getPullRequest().getBody(), startsWith("**JIRA Ticket URL:**"));
assertThat(event.getChanges().getBody(), nullValue());
}

@Test
public void pull_request_labeled() throws Exception {
GHEventPayload.PullRequest event = GitHub.offline()
Expand Down
Loading

0 comments on commit a433bcd

Please sign in to comment.