Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull_request action "edited": changes #979

Merged
merged 6 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base changed - covered with UT
title changed - covered with UT
body changed - cover on demand

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;
}
}
}
27 changes: 27 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,33 @@ 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().getBody(), startsWith("**JIRA Ticket URL:**"));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

body not changed - hence "changes" does not contain it

assertThat(event.getChanges().getBody(), nullValue());
bitwiseman marked this conversation as resolved.
Show resolved Hide resolved
}

@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().getBody(), startsWith("**JIRA Ticket URL:**"));
assertThat(event.getChanges().getBody(), nullValue());
bitwiseman marked this conversation as resolved.
Show resolved Hide resolved
}

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