Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
Comments on closed/merged issues trigger Commented event #42
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Aug 4, 2015
1 parent ee5f370 commit f43a38e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Changelog of Pull Request Notifier for Stash.

## 1.17
* Ignoring events if pull request is closed

## 1.16
* Triggering also on comment replies if COMMENTED event is checked.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ public void onEvent(PullRequestUpdatedEvent e) {
@VisibleForTesting
public void handleEvent(PullRequestEvent pullRequestEvent) {
try {
if (pullRequestEvent.getPullRequest().isClosed()) {
return;
}
final PrnfsSettings settings = getPrnfsSettings(pluginSettingsFactory.createGlobalSettings());
for (final PrnfsNotification notification : settings.getNotifications()) {
final PrnfsRenderer renderer = new PrnfsRenderer(pullRequestEvent, repositoryService, notification);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ public void testThatAUrlIsOnlyInvokedForConfiguredEvents() {
.withId(10L).withPullRequestAction(MERGED).build()).invokedNoUrl();
}

@Test
public void testThatClosedPullRequestsAreIgnored() {
prnfsTestBuilder()
.isLoggedInAsAdmin()
.withNotification(
notificationBuilder().withFieldValue(AdminFormValues.FIELDS.url, "http://bjurr.se/")
.withFieldValue(AdminFormValues.FIELDS.events, OPENED.name()).build()).store()
.trigger(pullRequestEventBuilder() //
.beingClosed().withToRef(pullRequestRefBuilder()).withPullRequestAction(OPENED).build()).invokedNoUrl();
}

@Test
public void testThatAUrlWithoutVariablesCanBeInvoked() {
prnfsTestBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class PullRequestEventBuilder {
private PullRequestParticipant author;
private String commentText;
private final PrnfsTestBuilder prnfsTestBuilder;
private boolean beingClosed;

private PullRequestEventBuilder(PrnfsTestBuilder prnfsTestBuilder) {
this.prnfsTestBuilder = prnfsTestBuilder;
Expand Down Expand Up @@ -98,6 +99,7 @@ public PullRequestEvent build() {
pullRequestEvent = event;
}
final PullRequest pullRequest = mock(PullRequest.class);
when(pullRequest.isClosed()).thenReturn(beingClosed);
when(pullRequestEvent.getAction()).thenReturn(pullRequestAction);
when(pullRequestEvent.getPullRequest()).thenReturn(pullRequest);
when(pullRequestEvent.getPullRequest().getAuthor()).thenReturn(author);
Expand All @@ -110,4 +112,9 @@ public PullRequestEvent build() {
public PrnfsTestBuilder triggerEvent() {
return prnfsTestBuilder.trigger(build());
}

public PullRequestEventBuilder beingClosed() {
beingClosed = true;
return this;
}
}

0 comments on commit f43a38e

Please sign in to comment.