diff --git a/src/main/java/se/bjurr/prnfs/listener/UrlInvoker.java b/src/main/java/se/bjurr/prnfs/listener/UrlInvoker.java index 1d8e0d9..9cfa717 100644 --- a/src/main/java/se/bjurr/prnfs/listener/UrlInvoker.java +++ b/src/main/java/se/bjurr/prnfs/listener/UrlInvoker.java @@ -136,10 +136,6 @@ public String getUrlParam() { return urlParam; } - public static Logger getLogger() { - return logger; - } - @VisibleForTesting public boolean shouldPostContent() { return (method.equals("POST") || method.equals("PUT")) && postContent.isPresent(); diff --git a/src/test/java/se/bjurr/prnfs/admin/PrnfsPullRequestEventListenerTest.java b/src/test/java/se/bjurr/prnfs/admin/PrnfsPullRequestEventListenerTest.java index e6df952..d37fa1c 100644 --- a/src/test/java/se/bjurr/prnfs/admin/PrnfsPullRequestEventListenerTest.java +++ b/src/test/java/se/bjurr/prnfs/admin/PrnfsPullRequestEventListenerTest.java @@ -452,6 +452,84 @@ public void testThatFilterCanIncludeRescopedFrom() { .withId(10L).withPullRequestAction(RESCOPED).build()).invokedUrl(0, "http://bjurr.se/"); } + @Test + public void testThatFilterCanBeUsedWithComments() { + prnfsTestBuilder() + .isLoggedInAsAdmin() + .withNotification( + notificationBuilder() + .withFieldValue( + AdminFormValues.FIELDS.url, + "http://bjurr.se/?comment=${" + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_COMMENT_TEXT + "}&version=${" + + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_VERSION + "}") + .withFieldValue(AdminFormValues.FIELDS.events, COMMENTED.name()) + .withFieldValue( + FIELDS.filter_string, + "${" + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_TO_ID.name() + "}:${" + + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_COMMENT_TEXT.name() + "}:") + .withFieldValue(FIELDS.filter_regexp, ".*:.*?keyword.*?:.*").build()).store().trigger(pullRequestEventBuilder() // + .withFromRef(pullRequestRefBuilder().withHash("from")) // + .withToRef(pullRequestRefBuilder().withId("123")) // + .withCommentText("keyword A nice comment").withId(10L).withPullRequestAction(COMMENTED).build()) + .invokedUrl(0, "http://bjurr.se/?comment=keyword%20A%20nice%20comment&version=0"); + } + + @Test + public void testThatFilterCanBeUsedWithCommentsAndSpecialEscapedChars() { + prnfsTestBuilder() + .isLoggedInAsAdmin() + .withNotification( + notificationBuilder() + .withFieldValue( + AdminFormValues.FIELDS.url, + "http://bjurr.se/?comment=${" + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_COMMENT_TEXT + "}&version=${" + + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_VERSION + "}") + .withFieldValue(AdminFormValues.FIELDS.events, COMMENTED.name()) + .withFieldValue( + FIELDS.filter_string, + "${" + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_TO_ID.name() + "}:${" + + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_COMMENT_TEXT.name() + "}:") + .withFieldValue(FIELDS.filter_regexp, ".*:\\skeyword\\s:.*").build()).store().trigger(pullRequestEventBuilder() // + .withFromRef(pullRequestRefBuilder().withHash("from")) // + .withToRef(pullRequestRefBuilder().withId("123")) // + .withCommentText(" keyword ").withId(10L).withPullRequestAction(COMMENTED).build()) + .invokedUrl(0, "http://bjurr.se/?comment=%20keyword%20&version=0"); + } + + @Test + public void testThatFilterCanBeUsedWithCommentsIgnore() { + prnfsTestBuilder() + .isLoggedInAsAdmin() + .withNotification( + notificationBuilder() + .withFieldValue( + AdminFormValues.FIELDS.url, + "http://bjurr.se/?comment=${" + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_COMMENT_TEXT + "}&version=${" + + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_VERSION + "}") + .withFieldValue(AdminFormValues.FIELDS.events, COMMENTED.name()) + .withFieldValue( + FIELDS.filter_string, + "${" + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_TO_ID.name() + "}:${" + + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_COMMENT_TEXT.name() + "}:") + .withFieldValue(FIELDS.filter_regexp, ".*:.*?keyword.*?:.*").build()).store().trigger(pullRequestEventBuilder() // + .withFromRef(pullRequestRefBuilder().withHash("from")) // + .withToRef(pullRequestRefBuilder().withId("123")) // + .withCommentText("notkw A nice comment").withId(10L).withPullRequestAction(COMMENTED).build()).invokedNoUrl(); + } + + @Test + public void testThatStringWithVariableCommentIsEmptyIfNotACommentEvent() { + prnfsTestBuilder() + .isLoggedInAsAdmin() + .withNotification( + notificationBuilder() + .withFieldValue(AdminFormValues.FIELDS.url, + "http://bjurr.se/?comment=${" + PrnfsRenderer.PrnfsVariable.PULL_REQUEST_COMMENT_TEXT + "}") + .withFieldValue(AdminFormValues.FIELDS.events, OPENED.name()).build()).store() + .trigger(pullRequestEventBuilder() // + .withId(10L).withPullRequestAction(OPENED).build()).invokedUrl(0, "http://bjurr.se/?comment="); + } + @Test public void testThatURLCanIncludeRescopedFrom() { prnfsTestBuilder()