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

Conversation

seregamorph
Copy link
Contributor

@seregamorph seregamorph commented Nov 18, 2020

Description

Webhook with X-GitHub-Event: pull_request and "action": "edited" has a field "changes" that is not present in GHEventPayload.PullRequest. I've found three triggers that leads to "edited" action:

  • Change PR title:
...
  "changes": {
    "title": {
      "from": "REST-276 - easy-random"
    }
  },
...

(full payload - in test data)

  • Change PR description:
...
"changes": {
    "body": {
      "from": "**JIRA Ticket URL:**\r\nhttps://jira.devfactory.com/browse/REST-276\r\n\r\n..."
    }
  },
...
  • Change target branch:
...
  "changes": {
    "base": {
      "ref": {
        "from": "develop"
      },
      "sha": {
        "from": "4b0f3b9fd582b071652ccfccd10bfc8c143cff96"
      }
    }
  },
...

So, "changes" fields contain old value that was changed, while pull_request object has latest values (see UT json payloads). Any other changes of a PR in GitHub UI leads to other types of notifications (e.g. action is assigned or ready_for_review or labeled).

@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

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

Copy link
Member

@bitwiseman bitwiseman left a comment

Choose a reason for hiding this comment

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

Minor changes to test.

assertThat(event.getChanges().getBase(), nullValue());
assertThat(event.getPullRequest().getBody(), startsWith("**JIRA Ticket URL:**"));
assertThat(event.getChanges().getBody(), nullValue());
assertThat(event.getChanges(). getChanges(), nullValue());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
assertThat(event.getChanges(). getChanges(), nullValue());

@seregamorph
Copy link
Contributor Author

@bitwiseman not sure what changes did you expect. My logic was: for three fields: title, body and base check old value (in "changes" field) and current value (in "pull_request field). There is a small test enhancement.

@bitwiseman bitwiseman merged commit a433bcd into hub4j:master Nov 24, 2020
@seregamorph seregamorph deleted the feature/pull_request-edited branch November 24, 2020 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants