Skip to content

Commit

Permalink
Merge branch 'master' of github.com:groupon/DotCi
Browse files Browse the repository at this point in the history
  • Loading branch information
suryagaddipati committed Jan 31, 2017
2 parents 3ff7dd9 + d562d02 commit 28cfbc3
Show file tree
Hide file tree
Showing 4 changed files with 901 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ private boolean shouldBuildPullRequest() {
shouldBuildPullRequestBasedOnAction();
}

//only build for webhook actions of "opened", "reopened", or "synchronize"
//only build for webhook actions of "opened", "reopened", "synchronize", or "edited" (and branch changed)
//https://developer.github.com/v3/activity/events/types/#events-api-payload-17
private boolean shouldBuildPullRequestBasedOnAction() {
return isOpenedAction() || isReOpenedAction() || isSynchronizeAction();
return isOpenedAction() || isReOpenedAction() || isSynchronizeAction() || isBranchChange();
}

private boolean isPullRequestClosed() {
Expand All @@ -116,6 +116,18 @@ private boolean isSynchronizeAction() {
return isPullRequest() && "synchronize".equals(this.payloadJson.getString("action"));
}

private boolean isBranchChange() {
if (!isEditedAction()) {
return false;
}
JSONObject changes = this.payloadJson.getJSONObject("changes");
return !changes.isNullObject() && changes.containsKey("base");
}

private boolean isEditedAction() {
return isPullRequest() && "edited".equals(this.payloadJson.getString("action"));
}

public String getPullRequestSourceBranch() {
if (!isPullRequest()) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ public void pullRequestSynchronizeShouldTriggerABuild() throws IOException {
assertTrue(payload.needsBuild(getProject()));
}

@Test
public void pullRequestChangedBranchShouldTriggerABuild() throws IOException {
final String payloadReq = readFile("pull_request_edited_branch_change.json");
final PushAndPullRequestPayload payload = new PushAndPullRequestPayload(payloadReq);
assertTrue(payload.needsBuild(getProject()));
}


@Test
public void pullRequestEditedBodyShouldNotTriggerABuild() throws IOException {
final String payloadReq = readFile("pull_request_edited_body.json");
final PushAndPullRequestPayload payload = new PushAndPullRequestPayload(payloadReq);
assertFalse(payload.needsBuild(getProject()));
}

private DynamicProject getProject() {
return Mockito.mock(DynamicProject.class);
}
Expand Down
Loading

0 comments on commit 28cfbc3

Please sign in to comment.