From c1912f15db492c7e102e66d74b2b0988f6676454 Mon Sep 17 00:00:00 2001 From: Tomas Bjerre Date: Thu, 13 Aug 2015 11:44:16 +0200 Subject: [PATCH] Only ignore events on closed pull requests if its a COMMENT-event #48 #42 --- CHANGELOG.md | 2 +- .../listener/PrnfsPullRequestEventListener.java | 3 ++- .../admin/PrnfsPullRequestEventListenerTest.java | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5d5ae6c..e500af7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ Changelog of Pull Request Notifier for Stash. ## 1.19 - +* Bugfix: Only ignore events on closed pull requests if its a COMMENT-event. ## 1.18 * Avoiding endless loop if user not 'System Admin' when editing configuration diff --git a/src/main/java/se/bjurr/prnfs/listener/PrnfsPullRequestEventListener.java b/src/main/java/se/bjurr/prnfs/listener/PrnfsPullRequestEventListener.java index 6c5869e4..3429cbec 100644 --- a/src/main/java/se/bjurr/prnfs/listener/PrnfsPullRequestEventListener.java +++ b/src/main/java/se/bjurr/prnfs/listener/PrnfsPullRequestEventListener.java @@ -26,6 +26,7 @@ import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory; import com.atlassian.stash.event.pull.PullRequestApprovedEvent; import com.atlassian.stash.event.pull.PullRequestCommentAddedEvent; +import com.atlassian.stash.event.pull.PullRequestCommentEvent; import com.atlassian.stash.event.pull.PullRequestCommentRepliedEvent; import com.atlassian.stash.event.pull.PullRequestDeclinedEvent; import com.atlassian.stash.event.pull.PullRequestEvent; @@ -126,7 +127,7 @@ public void onEvent(PullRequestUpdatedEvent e) { @VisibleForTesting public void handleEvent(final PullRequestEvent pullRequestEvent) { try { - if (pullRequestEvent.getPullRequest().isClosed()) { + if (pullRequestEvent.getPullRequest().isClosed() && pullRequestEvent instanceof PullRequestCommentEvent) { return; } final PrnfsSettings settings = getPrnfsSettings(pluginSettingsFactory.createGlobalSettings()); diff --git a/src/test/java/se/bjurr/prnfs/admin/PrnfsPullRequestEventListenerTest.java b/src/test/java/se/bjurr/prnfs/admin/PrnfsPullRequestEventListenerTest.java index 2a59eb05..be316f92 100644 --- a/src/test/java/se/bjurr/prnfs/admin/PrnfsPullRequestEventListenerTest.java +++ b/src/test/java/se/bjurr/prnfs/admin/PrnfsPullRequestEventListenerTest.java @@ -86,14 +86,26 @@ public void testThatAUrlIsOnlyInvokedForConfiguredEvents() { } @Test - public void testThatClosedPullRequestsAreIgnored() { + public void testThatClosedPullRequestsAreNotIgnoredForOpenedEvent() { 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(); + .beingClosed().withToRef(pullRequestRefBuilder()).withPullRequestAction(OPENED).build()) + .invokedOnlyUrl("http://bjurr.se/"); + } + + @Test + public void testThatClosedPullRequestsAreIgnoredForCommentEvent() { + prnfsTestBuilder() + .isLoggedInAsAdmin() + .withNotification( + notificationBuilder().withFieldValue(AdminFormValues.FIELDS.url, "http://bjurr.se/") + .withFieldValue(AdminFormValues.FIELDS.events, COMMENTED.name()).build()).store() + .trigger(pullRequestEventBuilder() // + .beingClosed().withToRef(pullRequestRefBuilder()).withPullRequestAction(COMMENTED).build()).invokedNoUrl(); } @Test