diff --git a/CHANGELOG.md b/CHANGELOG.md index 685266ca..35a8abc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ Changelog of Pull Request Notifier for Bitbucket. ## Unreleased ### No issue + Adding ${PULL_REQUEST_COMMENT_ACTION} variable + + [ade89b294fd56f8](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/ade89b294fd56f8) Tomas Bjerre *2016-11-14 19:38:16* + + Format code + + [b9a273d95239927](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/b9a273d95239927) Tomas Bjerre *2016-11-14 19:24:03* + Add comment text for replies [8b13f16f92c8bbd](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/8b13f16f92c8bbd) Garret Ruh *2016-11-14 15:48:27* diff --git a/README.md b/README.md index 1f75958e..08df0521 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ The filter text as well as the URL support variables. These are: * ${PULL_REQUEST_TITLE} Example: Anything * ${PULL_REQUEST_VERSION} Example: 1 * ${PULL_REQUEST_COMMENT_TEXT} Example: A comment +* ${PULL_REQUEST_COMMENT_ACTION} Example: ADDED, DELETED, EDITED, REPLIED * ${PULL_REQUEST_ACTION} Example: OPENED * ${PULL_REQUEST_STATE} Example: DECLINED, MERGED, OPEN * ${BUTTON_TRIGGER_TITLE} Example: Trigger Notification diff --git a/src/main/java/se/bjurr/prnfb/listener/PrnfbPullRequestEventListener.java b/src/main/java/se/bjurr/prnfb/listener/PrnfbPullRequestEventListener.java index e8adb06b..50712e8c 100644 --- a/src/main/java/se/bjurr/prnfb/listener/PrnfbPullRequestEventListener.java +++ b/src/main/java/se/bjurr/prnfb/listener/PrnfbPullRequestEventListener.java @@ -9,6 +9,7 @@ import static org.slf4j.LoggerFactory.getLogger; import static se.bjurr.prnfb.http.UrlInvoker.urlInvoker; import static se.bjurr.prnfb.listener.PrnfbPullRequestAction.fromPullRequestEvent; +import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_COMMENT_ACTION; import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_COMMENT_TEXT; import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_MERGE_COMMIT; import static se.bjurr.prnfb.settings.TRIGGER_IF_MERGE.ALWAYS; @@ -20,22 +21,10 @@ import org.slf4j.Logger; -import se.bjurr.prnfb.http.ClientKeyStore; -import se.bjurr.prnfb.http.HttpResponse; -import se.bjurr.prnfb.http.Invoker; -import se.bjurr.prnfb.http.NotificationResponse; -import se.bjurr.prnfb.http.UrlInvoker; -import se.bjurr.prnfb.service.PrnfbRenderer; -import se.bjurr.prnfb.service.PrnfbRendererFactory; -import se.bjurr.prnfb.service.PrnfbVariable; -import se.bjurr.prnfb.service.SettingsService; -import se.bjurr.prnfb.settings.PrnfbHeader; -import se.bjurr.prnfb.settings.PrnfbNotification; -import se.bjurr.prnfb.settings.PrnfbSettingsData; -import se.bjurr.prnfb.settings.TRIGGER_IF_MERGE; - import com.atlassian.bitbucket.event.pull.PullRequestApprovedEvent; import com.atlassian.bitbucket.event.pull.PullRequestCommentAddedEvent; +import com.atlassian.bitbucket.event.pull.PullRequestCommentDeletedEvent; +import com.atlassian.bitbucket.event.pull.PullRequestCommentEditedEvent; import com.atlassian.bitbucket.event.pull.PullRequestCommentEvent; import com.atlassian.bitbucket.event.pull.PullRequestCommentRepliedEvent; import com.atlassian.bitbucket.event.pull.PullRequestDeclinedEvent; @@ -53,6 +42,20 @@ import com.google.common.base.Optional; import com.google.common.base.Supplier; +import se.bjurr.prnfb.http.ClientKeyStore; +import se.bjurr.prnfb.http.HttpResponse; +import se.bjurr.prnfb.http.Invoker; +import se.bjurr.prnfb.http.NotificationResponse; +import se.bjurr.prnfb.http.UrlInvoker; +import se.bjurr.prnfb.service.PrnfbRenderer; +import se.bjurr.prnfb.service.PrnfbRendererFactory; +import se.bjurr.prnfb.service.PrnfbVariable; +import se.bjurr.prnfb.service.SettingsService; +import se.bjurr.prnfb.settings.PrnfbHeader; +import se.bjurr.prnfb.settings.PrnfbNotification; +import se.bjurr.prnfb.settings.PrnfbSettingsData; +import se.bjurr.prnfb.settings.TRIGGER_IF_MERGE; + public class PrnfbPullRequestEventListener { private static final Logger LOG = getLogger(PrnfbPullRequestEventListener.class); @@ -77,9 +80,37 @@ public PrnfbPullRequestEventListener(PrnfbRendererFactory prnfbRendererFactory, this.settingsService = settingsService; } + private Invoker createInvoker() { + if (mockedInvoker != null) { + return mockedInvoker; + } + return new Invoker() { + @Override + public HttpResponse invoke(UrlInvoker urlInvoker) { + return urlInvoker.invoke(); + } + }; + } + + private void handleEvent(final PullRequestEvent pullRequestEvent) { + if (pullRequestEvent.getPullRequest().isClosed() && pullRequestEvent instanceof PullRequestCommentEvent) { + return; + } + final PrnfbSettingsData settings = settingsService.getPrnfbSettingsData(); + ClientKeyStore clientKeyStore = new ClientKeyStore(settings); + for (final PrnfbNotification notification : settingsService.getNotifications()) { + PrnfbPullRequestAction action = fromPullRequestEvent(pullRequestEvent, notification); + Map> variables = populateVariables(pullRequestEvent); + PrnfbRenderer renderer = prnfbRendererFactory.create(pullRequestEvent.getPullRequest(), action, notification, + variables, pullRequestEvent.getUser()); + notify(notification, action, pullRequestEvent.getPullRequest(), renderer, clientKeyStore, + settings.isShouldAcceptAnyCertificate()); + } + } + @VisibleForTesting public void handleEventAsync(final PullRequestEvent pullRequestEvent) { - this.executorService.execute(new Runnable() { + executorService.execute(new Runnable() { @Override public void run() { handleEvent(pullRequestEvent); @@ -87,6 +118,12 @@ public void run() { }); } + @VisibleForTesting + boolean ignoreBecauseOfConflicting(TRIGGER_IF_MERGE triggerIfCanMerge, boolean isConflicted) { + return triggerIfCanMerge == NOT_CONFLICTING && isConflicted || // + triggerIfCanMerge == CONFLICTING && !isConflicted; + } + public boolean isNotificationTriggeredByAction(PrnfbNotification notification, PrnfbPullRequestAction pullRequestAction, PrnfbRenderer renderer, PullRequest pullRequest, ClientKeyStore clientKeyStore, Boolean shouldAcceptAnyCertificate) { @@ -119,7 +156,7 @@ public boolean isNotificationTriggeredByAction(PrnfbNotification notification, if (notification.getTriggerIfCanMerge() != ALWAYS && pullRequest.isOpen()) { // Cannot perform canMerge unless PR is open - boolean isConflicted = this.pullRequestService + boolean isConflicted = pullRequestService .canMerge(pullRequest.getToRef().getRepository().getId(), pullRequest.getId()).isConflicted(); if (ignoreBecauseOfConflicting(notification.getTriggerIfCanMerge(), isConflicted)) { return FALSE; @@ -177,6 +214,16 @@ public void onEvent(PullRequestCommentAddedEvent e) { handleEventAsync(e); } + @EventListener + public void onEvent(PullRequestCommentDeletedEvent e) { + handleEventAsync(e); + } + + @EventListener + public void onEvent(PullRequestCommentEditedEvent e) { + handleEventAsync(e); + } + @EventListener public void onEvent(PullRequestCommentRepliedEvent e) { handleEventAsync(e); @@ -217,45 +264,17 @@ public void onEvent(PullRequestUpdatedEvent e) { handleEventAsync(e); } - private Invoker createInvoker() { - if (mockedInvoker != null) { - return mockedInvoker; - } - return new Invoker() { - @Override - public HttpResponse invoke(UrlInvoker urlInvoker) { - return urlInvoker.invoke(); - } - }; - } - - private void handleEvent(final PullRequestEvent pullRequestEvent) { - if (pullRequestEvent.getPullRequest().isClosed() && pullRequestEvent instanceof PullRequestCommentEvent) { - return; - } - final PrnfbSettingsData settings = this.settingsService.getPrnfbSettingsData(); - ClientKeyStore clientKeyStore = new ClientKeyStore(settings); - for (final PrnfbNotification notification : this.settingsService.getNotifications()) { - PrnfbPullRequestAction action = fromPullRequestEvent(pullRequestEvent, notification); - Map> variables = populateVariables(pullRequestEvent); - PrnfbRenderer renderer = this.prnfbRendererFactory.create(pullRequestEvent.getPullRequest(), action, notification, - variables, pullRequestEvent.getUser()); - notify(notification, action, pullRequestEvent.getPullRequest(), renderer, clientKeyStore, - settings.isShouldAcceptAnyCertificate()); - } - } - - @VisibleForTesting - boolean ignoreBecauseOfConflicting(TRIGGER_IF_MERGE triggerIfCanMerge, boolean isConflicted) { - return triggerIfCanMerge == NOT_CONFLICTING && isConflicted || // - triggerIfCanMerge == CONFLICTING && !isConflicted; - } - @VisibleForTesting Map> populateVariables(final PullRequestEvent pullRequestEvent) { Map> variables = newHashMap(); if (pullRequestEvent instanceof PullRequestCommentEvent) { - variables.put(PULL_REQUEST_COMMENT_TEXT, () -> ((PullRequestCommentEvent) pullRequestEvent).getComment().getText()); + PullRequestCommentEvent pullRequestCommentEvent = (PullRequestCommentEvent) pullRequestEvent; + variables.put(PULL_REQUEST_COMMENT_TEXT, () -> { + return pullRequestCommentEvent.getComment().getText(); + }); + variables.put(PULL_REQUEST_COMMENT_ACTION, () -> { + return pullRequestCommentEvent.getCommentAction().name(); + }); } else if (pullRequestEvent instanceof PullRequestMergedEvent) { variables.put(PULL_REQUEST_MERGE_COMMIT, new Supplier() { @Override diff --git a/src/main/java/se/bjurr/prnfb/service/PrnfbVariable.java b/src/main/java/se/bjurr/prnfb/service/PrnfbVariable.java index 160b48e4..943179bc 100644 --- a/src/main/java/se/bjurr/prnfb/service/PrnfbVariable.java +++ b/src/main/java/se/bjurr/prnfb/service/PrnfbVariable.java @@ -156,6 +156,15 @@ public String resolve(PullRequest pullRequest, PrnfbPullRequestAction prnfbPullR SecurityService securityService) { return pullRequest.getAuthor().getUser().getSlug(); } + }), PULL_REQUEST_COMMENT_ACTION(new PrnfbVariableResolver() { + @Override + public String resolve(PullRequest pullRequest, PrnfbPullRequestAction prnfbPullRequestAction, + ApplicationUser applicationUser, RepositoryService repositoryService, + ApplicationPropertiesService propertiesService, PrnfbNotification prnfbNotification, + Map> variables, ClientKeyStore clientKeyStore, boolean shouldAcceptAnyCertificate, + SecurityService securityService) { + return getOrEmpty(variables, PULL_REQUEST_COMMENT_ACTION); + } }), PULL_REQUEST_COMMENT_TEXT(new PrnfbVariableResolver() { @Override public String resolve(PullRequest pullRequest, PrnfbPullRequestAction prnfbPullRequestAction, diff --git a/src/main/resources/admin.vm b/src/main/resources/admin.vm index f5efd026..5d5ae8b0 100644 --- a/src/main/resources/admin.vm +++ b/src/main/resources/admin.vm @@ -56,6 +56,7 @@
  • ${PULL_REQUEST_URL} Example: http://localhost:7990/projects/PROJECT_1/repos/rep_1/pull-requests/1
  • ${PULL_REQUEST_VERSION} Example: 1
  • ${PULL_REQUEST_COMMENT_TEXT} Example: A comment
  • +
  • ${PULL_REQUEST_COMMENT_ACTION} Example: ADDED, DELETED, EDITED, REPLIED
  • ${BUTTON_TRIGGER_TITLE} Example: Trigger Notification
  • ${INJECTION_URL_VALUE} If injection URL configured
  • ${PULL_REQUEST_USER_DISPLAY_NAME} Example: Some User
  • diff --git a/src/test/java/se/bjurr/prnfb/listener/PrnfbPullRequestEventListenerTest.java b/src/test/java/se/bjurr/prnfb/listener/PrnfbPullRequestEventListenerTest.java index b6becf57..0698b728 100644 --- a/src/test/java/se/bjurr/prnfb/listener/PrnfbPullRequestEventListenerTest.java +++ b/src/test/java/se/bjurr/prnfb/listener/PrnfbPullRequestEventListenerTest.java @@ -1,5 +1,6 @@ package se.bjurr.prnfb.listener; +import static com.atlassian.bitbucket.comment.CommentAction.ADDED; import static com.atlassian.bitbucket.pull.PullRequestAction.OPENED; import static com.atlassian.bitbucket.pull.PullRequestState.DECLINED; import static com.google.common.collect.Iterables.transform; @@ -12,6 +13,7 @@ import static se.bjurr.prnfb.listener.PrnfbPullRequestAction.APPROVED; import static se.bjurr.prnfb.listener.PrnfbPullRequestAction.RESCOPED_FROM; import static se.bjurr.prnfb.listener.PrnfbPullRequestEventListener.setInvoker; +import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_COMMENT_ACTION; import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_COMMENT_TEXT; import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_MERGE_COMMIT; import static se.bjurr.prnfb.settings.PrnfbNotificationBuilder.prnfbNotificationBuilder; @@ -32,18 +34,6 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import se.bjurr.prnfb.http.ClientKeyStore; -import se.bjurr.prnfb.http.HttpResponse; -import se.bjurr.prnfb.http.Invoker; -import se.bjurr.prnfb.http.UrlInvoker; -import se.bjurr.prnfb.service.PrnfbRenderer; -import se.bjurr.prnfb.service.PrnfbRendererFactory; -import se.bjurr.prnfb.service.PrnfbVariable; -import se.bjurr.prnfb.service.SettingsService; -import se.bjurr.prnfb.settings.PrnfbNotification; -import se.bjurr.prnfb.settings.PrnfbSettingsData; -import se.bjurr.prnfb.settings.ValidationException; - import com.atlassian.bitbucket.comment.Comment; import com.atlassian.bitbucket.commit.MinimalCommit; import com.atlassian.bitbucket.event.pull.PullRequestCommentAddedEvent; @@ -57,6 +47,18 @@ import com.google.common.base.Function; import com.google.common.base.Supplier; +import se.bjurr.prnfb.http.ClientKeyStore; +import se.bjurr.prnfb.http.HttpResponse; +import se.bjurr.prnfb.http.Invoker; +import se.bjurr.prnfb.http.UrlInvoker; +import se.bjurr.prnfb.service.PrnfbRenderer; +import se.bjurr.prnfb.service.PrnfbRendererFactory; +import se.bjurr.prnfb.service.PrnfbVariable; +import se.bjurr.prnfb.service.SettingsService; +import se.bjurr.prnfb.settings.PrnfbNotification; +import se.bjurr.prnfb.settings.PrnfbSettingsData; +import se.bjurr.prnfb.settings.ValidationException; + public class PrnfbPullRequestEventListenerTest { private final ClientKeyStore clientKeyStore = null; @@ -84,11 +86,21 @@ public class PrnfbPullRequestEventListenerTest { @Mock private PullRequestRef toRef; + private void assertInvokedUrls(String... expectedUrls) { + Iterable urls = transform(invokedUrls, new Function() { + @Override + public String apply(UrlInvoker input) { + return input.getUrlParam(); + } + }); + assertThat(urls)// + .containsOnly(expectedUrls); + } + @Before public void before() throws ValidationException { initMocks(this); - this.sut = new PrnfbPullRequestEventListener(this.prnfbRendererFactory, this.pullRequestService, this.executorService, - this.settingsService); + sut = new PrnfbPullRequestEventListener(prnfbRendererFactory, pullRequestService, executorService, settingsService); setInvoker(new Invoker() { @Override public HttpResponse invoke(UrlInvoker urlInvoker) { @@ -99,51 +111,51 @@ public HttpResponse invoke(UrlInvoker urlInvoker) { e.printStackTrace(); } urlInvoker.setResponse(response); - PrnfbPullRequestEventListenerTest.this.invokedUrls.add(urlInvoker); + invokedUrls.add(urlInvoker); return response; } }); - when(this.pullRequest.getFromRef())// - .thenReturn(this.fromRef); - when(this.pullRequest.getFromRef().getLatestCommit())// + when(pullRequest.getFromRef())// + .thenReturn(fromRef); + when(pullRequest.getFromRef().getLatestCommit())// .thenReturn("latestCFrom"); - when(this.pullRequest.getFromRef().getId())// + when(pullRequest.getFromRef().getId())// .thenReturn("IFrom"); - when(this.pullRequest.getToRef())// - .thenReturn(this.toRef); - when(this.pullRequest.getToRef().getLatestCommit())// + when(pullRequest.getToRef())// + .thenReturn(toRef); + when(pullRequest.getToRef().getLatestCommit())// .thenReturn("latestCTo"); - when(this.pullRequest.getToRef().getId())// + when(pullRequest.getToRef().getId())// .thenReturn("ITo"); - when(this.pullRequestOpenedEvent.getPullRequest())// - .thenReturn(this.pullRequest); - when(this.pullRequestOpenedEvent.getPullRequest().isClosed())// + when(pullRequestOpenedEvent.getPullRequest())// + .thenReturn(pullRequest); + when(pullRequestOpenedEvent.getPullRequest().isClosed())// .thenReturn(false); - when(this.pullRequestOpenedEvent.getAction())// + when(pullRequestOpenedEvent.getAction())// .thenReturn(OPENED); - this.pluginSettingsData = prnfbSettingsDataBuilder()// + pluginSettingsData = prnfbSettingsDataBuilder()// .build(); - when(this.settingsService.getPrnfbSettingsData())// - .thenReturn(this.pluginSettingsData); + when(settingsService.getPrnfbSettingsData())// + .thenReturn(pluginSettingsData); - this.notification1 = prnfbNotificationBuilder()// + notification1 = prnfbNotificationBuilder()// .withUrl("http://not1.com/")// .withTrigger(PrnfbPullRequestAction.OPENED)// .build(); - this.notification2 = prnfbNotificationBuilder(this.notification1)// + notification2 = prnfbNotificationBuilder(notification1)// .withUrl("http://not2.com/")// .build(); - List notifications = newArrayList(this.notification1, this.notification2); - when(this.settingsService.getNotifications())// + List notifications = newArrayList(notification1, notification2); + when(settingsService.getNotifications())// .thenReturn(notifications); - when(this.prnfbRendererFactory.create(any(), any(), any(), any(), any()))// - .thenReturn(this.renderer); - when(this.renderer.render(any(), any(), any(), any()))// + when(prnfbRendererFactory.create(any(), any(), any(), any(), any()))// + .thenReturn(renderer); + when(renderer.render(any(), any(), any(), any()))// .thenAnswer(new Answer() { @Override public String answer(InvocationOnMock invocation) throws Throwable { @@ -154,15 +166,15 @@ public String answer(InvocationOnMock invocation) throws Throwable { @Test public void testThatCommentOnClosedPRIsIgnored() { - when(this.pullRequest.isClosed())// + when(pullRequest.isClosed())// .thenReturn(true); PullRequestCommentAddedEvent pullRequestEvent = mock(PullRequestCommentAddedEvent.class); when(pullRequestEvent.getPullRequest())// - .thenReturn(this.pullRequest); + .thenReturn(pullRequest); - this.sut.handleEventAsync(pullRequestEvent); + sut.handleEventAsync(pullRequestEvent); - assertThat(this.invokedUrls)// + assertThat(invokedUrls)// .isEmpty(); } @@ -180,8 +192,8 @@ public void testThatNotifiationIsNotTriggeredByActionIfAFilterIsNotMatching() th .build(); PrnfbPullRequestAction pullRequestAction = RESCOPED_FROM; - boolean actual = this.sut.isNotificationTriggeredByAction(notification, pullRequestAction, this.renderer, - this.pullRequest, this.clientKeyStore, this.shouldAcceptAnyCertificate); + boolean actual = sut.isNotificationTriggeredByAction(notification, pullRequestAction, renderer, pullRequest, + clientKeyStore, shouldAcceptAnyCertificate); assertThat(actual)// .isFalse(); @@ -189,18 +201,18 @@ public void testThatNotifiationIsNotTriggeredByActionIfAFilterIsNotMatching() th @Test public void testThatNotifiationIsNotTriggeredByActionIfOnlyBuildingMergingAndItIsConflicting() { - assertThat(this.sut.ignoreBecauseOfConflicting(ALWAYS, false))// + assertThat(sut.ignoreBecauseOfConflicting(ALWAYS, false))// .isFalse(); - assertThat(this.sut.ignoreBecauseOfConflicting(CONFLICTING, false))// + assertThat(sut.ignoreBecauseOfConflicting(CONFLICTING, false))// .isTrue(); - assertThat(this.sut.ignoreBecauseOfConflicting(NOT_CONFLICTING, false))// + assertThat(sut.ignoreBecauseOfConflicting(NOT_CONFLICTING, false))// .isFalse(); - assertThat(this.sut.ignoreBecauseOfConflicting(ALWAYS, true))// + assertThat(sut.ignoreBecauseOfConflicting(ALWAYS, true))// .isFalse(); - assertThat(this.sut.ignoreBecauseOfConflicting(CONFLICTING, true))// + assertThat(sut.ignoreBecauseOfConflicting(CONFLICTING, true))// .isFalse(); - assertThat(this.sut.ignoreBecauseOfConflicting(NOT_CONFLICTING, true))// + assertThat(sut.ignoreBecauseOfConflicting(NOT_CONFLICTING, true))// .isTrue(); } @@ -213,7 +225,7 @@ public void testThatNotifiationIsNotTriggeredByActionIfProjectNotSame() throws V .build(); PrnfbPullRequestAction pullRequestAction = RESCOPED_FROM; Repository repository = mock(Repository.class); - when(this.toRef.getRepository())// + when(toRef.getRepository())// .thenReturn(repository); Project project = mock(Project.class); when(repository.getProject())// @@ -221,8 +233,8 @@ public void testThatNotifiationIsNotTriggeredByActionIfProjectNotSame() throws V when(project.getKey())// .thenReturn("pk2"); - boolean actual = this.sut.isNotificationTriggeredByAction(notification, pullRequestAction, this.renderer, - this.pullRequest, this.clientKeyStore, this.shouldAcceptAnyCertificate); + boolean actual = sut.isNotificationTriggeredByAction(notification, pullRequestAction, renderer, pullRequest, + clientKeyStore, shouldAcceptAnyCertificate); assertThat(actual)// .isFalse(); @@ -237,13 +249,13 @@ public void testThatNotifiationIsNotTriggeredByActionIfRepositoryNotSame() throw .build(); PrnfbPullRequestAction pullRequestAction = RESCOPED_FROM; Repository repository = mock(Repository.class); - when(this.toRef.getRepository())// + when(toRef.getRepository())// .thenReturn(repository); when(repository.getSlug())// .thenReturn("asdasd"); - boolean actual = this.sut.isNotificationTriggeredByAction(notification, pullRequestAction, this.renderer, - this.pullRequest, this.clientKeyStore, this.shouldAcceptAnyCertificate); + boolean actual = sut.isNotificationTriggeredByAction(notification, pullRequestAction, renderer, pullRequest, + clientKeyStore, shouldAcceptAnyCertificate); assertThat(actual)// .isFalse(); @@ -258,11 +270,11 @@ public void testThatNotifiationIsNotTriggeredByActionIfThatActionIsATriggerButSt .setTriggerIgnoreState(newArrayList(DECLINED))// .build(); PrnfbPullRequestAction pullRequestAction = RESCOPED_FROM; - when(this.pullRequest.getState())// + when(pullRequest.getState())// .thenReturn(DECLINED); - boolean actual = this.sut.isNotificationTriggeredByAction(notification, pullRequestAction, this.renderer, - this.pullRequest, this.clientKeyStore, this.shouldAcceptAnyCertificate); + boolean actual = sut.isNotificationTriggeredByAction(notification, pullRequestAction, renderer, pullRequest, + clientKeyStore, shouldAcceptAnyCertificate); assertThat(actual)// .isFalse(); @@ -276,8 +288,8 @@ public void testThatNotifiationIsNotTriggeredByActionIfThatActionIsNotATrigger() .build(); PrnfbPullRequestAction pullRequestAction = APPROVED; - boolean actual = this.sut.isNotificationTriggeredByAction(notification, pullRequestAction, this.renderer, - this.pullRequest, this.clientKeyStore, this.shouldAcceptAnyCertificate); + boolean actual = sut.isNotificationTriggeredByAction(notification, pullRequestAction, renderer, pullRequest, + clientKeyStore, shouldAcceptAnyCertificate); assertThat(actual)// .isFalse(); @@ -293,8 +305,8 @@ public void testThatNotifiationIsTriggeredByActionIfAFilterIsMatching() throws V .build(); PrnfbPullRequestAction pullRequestAction = RESCOPED_FROM; - boolean actual = this.sut.isNotificationTriggeredByAction(notification, pullRequestAction, this.renderer, - this.pullRequest, this.clientKeyStore, this.shouldAcceptAnyCertificate); + boolean actual = sut.isNotificationTriggeredByAction(notification, pullRequestAction, renderer, pullRequest, + clientKeyStore, shouldAcceptAnyCertificate); assertThat(actual)// .isTrue(); @@ -309,7 +321,7 @@ public void testThatNotifiationIsTriggeredByActionIfProjectSame() throws Validat .build(); PrnfbPullRequestAction pullRequestAction = RESCOPED_FROM; Repository repository = mock(Repository.class); - when(this.toRef.getRepository())// + when(toRef.getRepository())// .thenReturn(repository); Project project = mock(Project.class); when(repository.getProject())// @@ -317,8 +329,8 @@ public void testThatNotifiationIsTriggeredByActionIfProjectSame() throws Validat when(project.getKey())// .thenReturn("pk2"); - boolean actual = this.sut.isNotificationTriggeredByAction(notification, pullRequestAction, this.renderer, - this.pullRequest, this.clientKeyStore, this.shouldAcceptAnyCertificate); + boolean actual = sut.isNotificationTriggeredByAction(notification, pullRequestAction, renderer, pullRequest, + clientKeyStore, shouldAcceptAnyCertificate); assertThat(actual)// .isTrue(); @@ -333,13 +345,13 @@ public void testThatNotifiationIsTriggeredByActionIfRepositorySame() throws Vali .build(); PrnfbPullRequestAction pullRequestAction = RESCOPED_FROM; Repository repository = mock(Repository.class); - when(this.toRef.getRepository())// + when(toRef.getRepository())// .thenReturn(repository); when(repository.getSlug())// .thenReturn("repositorySlug123"); - boolean actual = this.sut.isNotificationTriggeredByAction(notification, pullRequestAction, this.renderer, - this.pullRequest, this.clientKeyStore, this.shouldAcceptAnyCertificate); + boolean actual = sut.isNotificationTriggeredByAction(notification, pullRequestAction, renderer, pullRequest, + clientKeyStore, shouldAcceptAnyCertificate); assertThat(actual)// .isTrue(); @@ -353,8 +365,8 @@ public void testThatNotifiationIsTriggeredByActionIfThatActionIsATrigger() throw .build(); PrnfbPullRequestAction pullRequestAction = RESCOPED_FROM; - boolean actual = this.sut.isNotificationTriggeredByAction(notification, pullRequestAction, this.renderer, - this.pullRequest, this.clientKeyStore, this.shouldAcceptAnyCertificate); + boolean actual = sut.isNotificationTriggeredByAction(notification, pullRequestAction, renderer, pullRequest, + clientKeyStore, shouldAcceptAnyCertificate); assertThat(actual)// .isTrue(); @@ -368,13 +380,17 @@ public void testThatPullRequestCommentIsAddedToVariables() { .thenReturn(comment); when(pullRequestEvent.getComment().getText())// .thenReturn("The comment"); + when(pullRequestEvent.getCommentAction())// + .thenReturn(ADDED); - Map> actual = this.sut.populateVariables(pullRequestEvent); + Map> actual = sut.populateVariables(pullRequestEvent); assertThat(actual)// - .hasSize(1); + .hasSize(2); assertThat(actual.get(PULL_REQUEST_COMMENT_TEXT).get())// .isEqualTo("The comment"); + assertThat(actual.get(PULL_REQUEST_COMMENT_ACTION).get())// + .isEqualTo("ADDED"); } @Test @@ -386,7 +402,7 @@ public void testThatPullRequestMergeComitIsAddedToVariables() { when(pullRequestEvent.getCommit().getId())// .thenReturn("hash"); - Map> actual = this.sut.populateVariables(pullRequestEvent); + Map> actual = sut.populateVariables(pullRequestEvent); assertThat(actual)// .hasSize(1); @@ -397,20 +413,9 @@ public void testThatPullRequestMergeComitIsAddedToVariables() { @Test public void testThatPullRequestOpenedCanTriggerNotification() { - this.sut.handleEventAsync(this.pullRequestOpenedEvent); + sut.handleEventAsync(pullRequestOpenedEvent); assertInvokedUrls("http://not1.com/", "http://not2.com/"); } - private void assertInvokedUrls(String... expectedUrls) { - Iterable urls = transform(this.invokedUrls, new Function() { - @Override - public String apply(UrlInvoker input) { - return input.getUrlParam(); - } - }); - assertThat(urls)// - .containsOnly(expectedUrls); - } - } diff --git a/src/test/java/se/bjurr/prnfb/service/PrnfbRendererTest.java b/src/test/java/se/bjurr/prnfb/service/PrnfbRendererTest.java index c3b1536a..131aac00 100644 --- a/src/test/java/se/bjurr/prnfb/service/PrnfbRendererTest.java +++ b/src/test/java/se/bjurr/prnfb/service/PrnfbRendererTest.java @@ -21,14 +21,6 @@ import org.junit.Test; import org.mockito.Mock; -import se.bjurr.prnfb.http.ClientKeyStore; -import se.bjurr.prnfb.http.HttpResponse; -import se.bjurr.prnfb.http.Invoker; -import se.bjurr.prnfb.http.UrlInvoker; -import se.bjurr.prnfb.listener.PrnfbPullRequestAction; -import se.bjurr.prnfb.settings.PrnfbNotification; -import se.bjurr.prnfb.settings.ValidationException; - import com.atlassian.bitbucket.pull.PullRequest; import com.atlassian.bitbucket.pull.PullRequestRef; import com.atlassian.bitbucket.repository.RepositoryService; @@ -38,6 +30,14 @@ import com.google.common.base.Supplier; import com.google.common.base.Suppliers; +import se.bjurr.prnfb.http.ClientKeyStore; +import se.bjurr.prnfb.http.HttpResponse; +import se.bjurr.prnfb.http.Invoker; +import se.bjurr.prnfb.http.UrlInvoker; +import se.bjurr.prnfb.listener.PrnfbPullRequestAction; +import se.bjurr.prnfb.settings.PrnfbNotification; +import se.bjurr.prnfb.settings.ValidationException; + public class PrnfbRendererTest { @Mock @@ -62,16 +62,16 @@ public class PrnfbRendererTest { @Before public void before() throws ValidationException { initMocks(this); - this.prnfbNotification = prnfbNotificationBuilder()// + prnfbNotification = prnfbNotificationBuilder()// .withUrl("http://hej.com")// .withTrigger(APPROVED)// .build(); - this.sut = new PrnfbRenderer(this.pullRequest, this.pullRequestAction, this.applicationUser, this.repositoryService, - this.propertiesService, this.prnfbNotification, this.variables, this.securityService); + sut = new PrnfbRenderer(pullRequest, pullRequestAction, applicationUser, repositoryService, propertiesService, + prnfbNotification, variables, securityService); - when(this.pullRequest.getFromRef())// - .thenReturn(this.fromRef); - when(this.pullRequest.getFromRef().getLatestCommit())// + when(pullRequest.getFromRef())// + .thenReturn(fromRef); + when(pullRequest.getFromRef().getLatestCommit())// .thenReturn("latestCommitHash"); PrnfbVariable.setInvoker(new Invoker() { @@ -91,28 +91,27 @@ public HttpResponse invoke(UrlInvoker toInvoke) { @Test public void testThatEverythingCanBeRendered() throws UnsupportedEncodingException { - String actual = this.sut.getRenderedStringResolved("asd ${" + EVERYTHING_URL.name() + "} asd", this.forUrl, - this.sut.regexp(EVERYTHING_URL), - EVERYTHING_URL.resolve(this.pullRequest, this.pullRequestAction, this.applicationUser, this.repositoryService, - this.propertiesService, this.prnfbNotification, this.variables, this.clientKeyStore, - this.shouldAcceptAnyCertificate, this.securityService)); + String actual = sut.getRenderedStringResolved("asd ${" + EVERYTHING_URL.name() + "} asd", forUrl, + sut.regexp(EVERYTHING_URL), + EVERYTHING_URL.resolve(pullRequest, pullRequestAction, applicationUser, repositoryService, propertiesService, + prnfbNotification, variables, clientKeyStore, shouldAcceptAnyCertificate, securityService)); assertThat(actual)// .isEqualTo( - "asd BUTTON_TRIGGER_TITLE=${BUTTON_TRIGGER_TITLE}&INJECTION_URL_VALUE=${INJECTION_URL_VALUE}&PULL_REQUEST_ACTION=${PULL_REQUEST_ACTION}&PULL_REQUEST_AUTHOR_DISPLAY_NAME=${PULL_REQUEST_AUTHOR_DISPLAY_NAME}&PULL_REQUEST_AUTHOR_EMAIL=${PULL_REQUEST_AUTHOR_EMAIL}&PULL_REQUEST_AUTHOR_ID=${PULL_REQUEST_AUTHOR_ID}&PULL_REQUEST_AUTHOR_NAME=${PULL_REQUEST_AUTHOR_NAME}&PULL_REQUEST_AUTHOR_SLUG=${PULL_REQUEST_AUTHOR_SLUG}&PULL_REQUEST_COMMENT_TEXT=${PULL_REQUEST_COMMENT_TEXT}&PULL_REQUEST_FROM_BRANCH=${PULL_REQUEST_FROM_BRANCH}&PULL_REQUEST_FROM_HASH=${PULL_REQUEST_FROM_HASH}&PULL_REQUEST_FROM_HTTP_CLONE_URL=${PULL_REQUEST_FROM_HTTP_CLONE_URL}&PULL_REQUEST_FROM_ID=${PULL_REQUEST_FROM_ID}&PULL_REQUEST_FROM_REPO_ID=${PULL_REQUEST_FROM_REPO_ID}&PULL_REQUEST_FROM_REPO_NAME=${PULL_REQUEST_FROM_REPO_NAME}&PULL_REQUEST_FROM_REPO_PROJECT_ID=${PULL_REQUEST_FROM_REPO_PROJECT_ID}&PULL_REQUEST_FROM_REPO_PROJECT_KEY=${PULL_REQUEST_FROM_REPO_PROJECT_KEY}&PULL_REQUEST_FROM_REPO_SLUG=${PULL_REQUEST_FROM_REPO_SLUG}&PULL_REQUEST_FROM_SSH_CLONE_URL=${PULL_REQUEST_FROM_SSH_CLONE_URL}&PULL_REQUEST_ID=${PULL_REQUEST_ID}&PULL_REQUEST_MERGE_COMMIT=${PULL_REQUEST_MERGE_COMMIT}&PULL_REQUEST_PARTICIPANTS_APPROVED_COUNT=${PULL_REQUEST_PARTICIPANTS_APPROVED_COUNT}&PULL_REQUEST_REVIEWERS=${PULL_REQUEST_REVIEWERS}&PULL_REQUEST_REVIEWERS_APPROVED_COUNT=${PULL_REQUEST_REVIEWERS_APPROVED_COUNT}&PULL_REQUEST_REVIEWERS_ID=${PULL_REQUEST_REVIEWERS_ID}&PULL_REQUEST_REVIEWERS_SLUG=${PULL_REQUEST_REVIEWERS_SLUG}&PULL_REQUEST_STATE=${PULL_REQUEST_STATE}&PULL_REQUEST_TITLE=${PULL_REQUEST_TITLE}&PULL_REQUEST_TO_BRANCH=${PULL_REQUEST_TO_BRANCH}&PULL_REQUEST_TO_HASH=${PULL_REQUEST_TO_HASH}&PULL_REQUEST_TO_HTTP_CLONE_URL=${PULL_REQUEST_TO_HTTP_CLONE_URL}&PULL_REQUEST_TO_ID=${PULL_REQUEST_TO_ID}&PULL_REQUEST_TO_REPO_ID=${PULL_REQUEST_TO_REPO_ID}&PULL_REQUEST_TO_REPO_NAME=${PULL_REQUEST_TO_REPO_NAME}&PULL_REQUEST_TO_REPO_PROJECT_ID=${PULL_REQUEST_TO_REPO_PROJECT_ID}&PULL_REQUEST_TO_REPO_PROJECT_KEY=${PULL_REQUEST_TO_REPO_PROJECT_KEY}&PULL_REQUEST_TO_REPO_SLUG=${PULL_REQUEST_TO_REPO_SLUG}&PULL_REQUEST_TO_SSH_CLONE_URL=${PULL_REQUEST_TO_SSH_CLONE_URL}&PULL_REQUEST_URL=${PULL_REQUEST_URL}&PULL_REQUEST_USER_DISPLAY_NAME=${PULL_REQUEST_USER_DISPLAY_NAME}&PULL_REQUEST_USER_EMAIL_ADDRESS=${PULL_REQUEST_USER_EMAIL_ADDRESS}&PULL_REQUEST_USER_ID=${PULL_REQUEST_USER_ID}&PULL_REQUEST_USER_NAME=${PULL_REQUEST_USER_NAME}&PULL_REQUEST_USER_SLUG=${PULL_REQUEST_USER_SLUG}&PULL_REQUEST_VERSION=${PULL_REQUEST_VERSION} asd"); + "asd BUTTON_TRIGGER_TITLE=${BUTTON_TRIGGER_TITLE}&INJECTION_URL_VALUE=${INJECTION_URL_VALUE}&PULL_REQUEST_ACTION=${PULL_REQUEST_ACTION}&PULL_REQUEST_AUTHOR_DISPLAY_NAME=${PULL_REQUEST_AUTHOR_DISPLAY_NAME}&PULL_REQUEST_AUTHOR_EMAIL=${PULL_REQUEST_AUTHOR_EMAIL}&PULL_REQUEST_AUTHOR_ID=${PULL_REQUEST_AUTHOR_ID}&PULL_REQUEST_AUTHOR_NAME=${PULL_REQUEST_AUTHOR_NAME}&PULL_REQUEST_AUTHOR_SLUG=${PULL_REQUEST_AUTHOR_SLUG}&PULL_REQUEST_COMMENT_ACTION=${PULL_REQUEST_COMMENT_ACTION}&PULL_REQUEST_COMMENT_TEXT=${PULL_REQUEST_COMMENT_TEXT}&PULL_REQUEST_FROM_BRANCH=${PULL_REQUEST_FROM_BRANCH}&PULL_REQUEST_FROM_HASH=${PULL_REQUEST_FROM_HASH}&PULL_REQUEST_FROM_HTTP_CLONE_URL=${PULL_REQUEST_FROM_HTTP_CLONE_URL}&PULL_REQUEST_FROM_ID=${PULL_REQUEST_FROM_ID}&PULL_REQUEST_FROM_REPO_ID=${PULL_REQUEST_FROM_REPO_ID}&PULL_REQUEST_FROM_REPO_NAME=${PULL_REQUEST_FROM_REPO_NAME}&PULL_REQUEST_FROM_REPO_PROJECT_ID=${PULL_REQUEST_FROM_REPO_PROJECT_ID}&PULL_REQUEST_FROM_REPO_PROJECT_KEY=${PULL_REQUEST_FROM_REPO_PROJECT_KEY}&PULL_REQUEST_FROM_REPO_SLUG=${PULL_REQUEST_FROM_REPO_SLUG}&PULL_REQUEST_FROM_SSH_CLONE_URL=${PULL_REQUEST_FROM_SSH_CLONE_URL}&PULL_REQUEST_ID=${PULL_REQUEST_ID}&PULL_REQUEST_MERGE_COMMIT=${PULL_REQUEST_MERGE_COMMIT}&PULL_REQUEST_PARTICIPANTS_APPROVED_COUNT=${PULL_REQUEST_PARTICIPANTS_APPROVED_COUNT}&PULL_REQUEST_REVIEWERS=${PULL_REQUEST_REVIEWERS}&PULL_REQUEST_REVIEWERS_APPROVED_COUNT=${PULL_REQUEST_REVIEWERS_APPROVED_COUNT}&PULL_REQUEST_REVIEWERS_ID=${PULL_REQUEST_REVIEWERS_ID}&PULL_REQUEST_REVIEWERS_SLUG=${PULL_REQUEST_REVIEWERS_SLUG}&PULL_REQUEST_STATE=${PULL_REQUEST_STATE}&PULL_REQUEST_TITLE=${PULL_REQUEST_TITLE}&PULL_REQUEST_TO_BRANCH=${PULL_REQUEST_TO_BRANCH}&PULL_REQUEST_TO_HASH=${PULL_REQUEST_TO_HASH}&PULL_REQUEST_TO_HTTP_CLONE_URL=${PULL_REQUEST_TO_HTTP_CLONE_URL}&PULL_REQUEST_TO_ID=${PULL_REQUEST_TO_ID}&PULL_REQUEST_TO_REPO_ID=${PULL_REQUEST_TO_REPO_ID}&PULL_REQUEST_TO_REPO_NAME=${PULL_REQUEST_TO_REPO_NAME}&PULL_REQUEST_TO_REPO_PROJECT_ID=${PULL_REQUEST_TO_REPO_PROJECT_ID}&PULL_REQUEST_TO_REPO_PROJECT_KEY=${PULL_REQUEST_TO_REPO_PROJECT_KEY}&PULL_REQUEST_TO_REPO_SLUG=${PULL_REQUEST_TO_REPO_SLUG}&PULL_REQUEST_TO_SSH_CLONE_URL=${PULL_REQUEST_TO_SSH_CLONE_URL}&PULL_REQUEST_URL=${PULL_REQUEST_URL}&PULL_REQUEST_USER_DISPLAY_NAME=${PULL_REQUEST_USER_DISPLAY_NAME}&PULL_REQUEST_USER_EMAIL_ADDRESS=${PULL_REQUEST_USER_EMAIL_ADDRESS}&PULL_REQUEST_USER_ID=${PULL_REQUEST_USER_ID}&PULL_REQUEST_USER_NAME=${PULL_REQUEST_USER_NAME}&PULL_REQUEST_USER_SLUG=${PULL_REQUEST_USER_SLUG}&PULL_REQUEST_VERSION=${PULL_REQUEST_VERSION} asd"); } @Test public void testThatInjectionUrlCanBeRendered() throws ValidationException { - this.prnfbNotification = prnfbNotificationBuilder(this.prnfbNotification)// + prnfbNotification = prnfbNotificationBuilder(prnfbNotification)// .withInjectionUrl("http://getValueFrom.com/")// .withTrigger(APPROVED)// .build(); - this.sut = new PrnfbRenderer(this.pullRequest, this.pullRequestAction, this.applicationUser, this.repositoryService, - this.propertiesService, this.prnfbNotification, this.variables, this.securityService); + sut = new PrnfbRenderer(pullRequest, pullRequestAction, applicationUser, repositoryService, propertiesService, + prnfbNotification, variables, securityService); - String actual = this.sut.render("my ${" + INJECTION_URL_VALUE + "} string", this.forUrl, this.clientKeyStore, - this.shouldAcceptAnyCertificate); + String actual = sut.render("my ${" + INJECTION_URL_VALUE + "} string", forUrl, clientKeyStore, + shouldAcceptAnyCertificate); assertThat(actual)// .isEqualTo("my theResponse string"); @@ -120,34 +119,34 @@ public void testThatInjectionUrlCanBeRendered() throws ValidationException { @Test public void testThatMergeCommitCanBeRenderedIfExists() { - this.variables.put(PULL_REQUEST_MERGE_COMMIT, Suppliers.ofInstance("mergeHash")); - String actual = this.sut.render("my ${" + PULL_REQUEST_MERGE_COMMIT + "} string", this.forUrl, this.clientKeyStore, - this.shouldAcceptAnyCertificate); + variables.put(PULL_REQUEST_MERGE_COMMIT, Suppliers.ofInstance("mergeHash")); + String actual = sut.render("my ${" + PULL_REQUEST_MERGE_COMMIT + "} string", forUrl, clientKeyStore, + shouldAcceptAnyCertificate); assertThat(actual)// .isEqualTo("my mergeHash string"); } @Test public void testThatMergeCommitCanBeRenderedIfNotExists() { - String actual = this.sut.render("my ${" + PULL_REQUEST_MERGE_COMMIT + "} string", this.forUrl, this.clientKeyStore, - this.shouldAcceptAnyCertificate); + String actual = sut.render("my ${" + PULL_REQUEST_MERGE_COMMIT + "} string", forUrl, clientKeyStore, + shouldAcceptAnyCertificate); assertThat(actual)// .isEqualTo("my string"); } @Test public void testThatStringCanBeRendered() { - String actual = this.sut.render("my ${" + PULL_REQUEST_FROM_HASH + "} string", this.forUrl, this.clientKeyStore, - this.shouldAcceptAnyCertificate); + String actual = sut.render("my ${" + PULL_REQUEST_FROM_HASH + "} string", forUrl, clientKeyStore, + shouldAcceptAnyCertificate); assertThat(actual)// .isEqualTo("my latestCommitHash string"); } @Test public void testThatStringCanBeRenderedForUrl() { - this.variables.put(PULL_REQUEST_COMMENT_TEXT, Suppliers.ofInstance("the comment")); - String actual = this.sut.render("my ${" + PULL_REQUEST_COMMENT_TEXT + "} string", true, this.clientKeyStore, - this.shouldAcceptAnyCertificate); + variables.put(PULL_REQUEST_COMMENT_TEXT, Suppliers.ofInstance("the comment")); + String actual = sut.render("my ${" + PULL_REQUEST_COMMENT_TEXT + "} string", true, clientKeyStore, + shouldAcceptAnyCertificate); assertThat(actual)// .isEqualTo("my the+comment string"); } diff --git a/src/test/java/se/bjurr/prnfb/service/PrnfbVariableTest.java b/src/test/java/se/bjurr/prnfb/service/PrnfbVariableTest.java index 6543e0a9..0041d2f8 100644 --- a/src/test/java/se/bjurr/prnfb/service/PrnfbVariableTest.java +++ b/src/test/java/se/bjurr/prnfb/service/PrnfbVariableTest.java @@ -12,10 +12,6 @@ import org.junit.Test; -import se.bjurr.prnfb.http.ClientKeyStore; -import se.bjurr.prnfb.listener.PrnfbPullRequestAction; -import se.bjurr.prnfb.settings.PrnfbNotification; - import com.atlassian.bitbucket.pull.PullRequest; import com.atlassian.bitbucket.repository.RepositoryService; import com.atlassian.bitbucket.server.ApplicationPropertiesService; @@ -25,6 +21,10 @@ import com.google.common.io.Files; import com.google.common.io.Resources; +import se.bjurr.prnfb.http.ClientKeyStore; +import se.bjurr.prnfb.listener.PrnfbPullRequestAction; +import se.bjurr.prnfb.settings.PrnfbNotification; + public class PrnfbVariableTest { private ApplicationUser applicationUser; @@ -38,6 +38,14 @@ public class PrnfbVariableTest { private boolean shouldAcceptAnyCertificate; private Map> variables; + private File findReadme(File file) { + File candidate = new File(file.getAbsolutePath() + "/README.md"); + if (candidate.exists()) { + return candidate; + } + return findReadme(file.getParentFile()); + } + @Test public void testThatAdminAndReadmeContainsVariables() throws IOException, URISyntaxException { URL adminResource = Resources.getResource("admin.vm"); @@ -56,21 +64,12 @@ public void testThatAdminAndReadmeContainsVariables() throws IOException, URISyn @Test public void testThatEverythingVariableIsResolvedToEveryOtherVariable() { - String actual = EVERYTHING_URL.resolve(this.pullRequest, this.pullRequestAction, this.applicationUser, - this.repositoryService, this.propertiesService, this.prnfbNotification, this.variables, this.clientKeyStore, - this.shouldAcceptAnyCertificate, this.securityService); + String actual = EVERYTHING_URL.resolve(pullRequest, pullRequestAction, applicationUser, repositoryService, + propertiesService, prnfbNotification, variables, clientKeyStore, shouldAcceptAnyCertificate, securityService); assertThat(actual)// .isEqualTo( - "BUTTON_TRIGGER_TITLE=\\${BUTTON_TRIGGER_TITLE}&INJECTION_URL_VALUE=\\${INJECTION_URL_VALUE}&PULL_REQUEST_ACTION=\\${PULL_REQUEST_ACTION}&PULL_REQUEST_AUTHOR_DISPLAY_NAME=\\${PULL_REQUEST_AUTHOR_DISPLAY_NAME}&PULL_REQUEST_AUTHOR_EMAIL=\\${PULL_REQUEST_AUTHOR_EMAIL}&PULL_REQUEST_AUTHOR_ID=\\${PULL_REQUEST_AUTHOR_ID}&PULL_REQUEST_AUTHOR_NAME=\\${PULL_REQUEST_AUTHOR_NAME}&PULL_REQUEST_AUTHOR_SLUG=\\${PULL_REQUEST_AUTHOR_SLUG}&PULL_REQUEST_COMMENT_TEXT=\\${PULL_REQUEST_COMMENT_TEXT}&PULL_REQUEST_FROM_BRANCH=\\${PULL_REQUEST_FROM_BRANCH}&PULL_REQUEST_FROM_HASH=\\${PULL_REQUEST_FROM_HASH}&PULL_REQUEST_FROM_HTTP_CLONE_URL=\\${PULL_REQUEST_FROM_HTTP_CLONE_URL}&PULL_REQUEST_FROM_ID=\\${PULL_REQUEST_FROM_ID}&PULL_REQUEST_FROM_REPO_ID=\\${PULL_REQUEST_FROM_REPO_ID}&PULL_REQUEST_FROM_REPO_NAME=\\${PULL_REQUEST_FROM_REPO_NAME}&PULL_REQUEST_FROM_REPO_PROJECT_ID=\\${PULL_REQUEST_FROM_REPO_PROJECT_ID}&PULL_REQUEST_FROM_REPO_PROJECT_KEY=\\${PULL_REQUEST_FROM_REPO_PROJECT_KEY}&PULL_REQUEST_FROM_REPO_SLUG=\\${PULL_REQUEST_FROM_REPO_SLUG}&PULL_REQUEST_FROM_SSH_CLONE_URL=\\${PULL_REQUEST_FROM_SSH_CLONE_URL}&PULL_REQUEST_ID=\\${PULL_REQUEST_ID}&PULL_REQUEST_MERGE_COMMIT=\\${PULL_REQUEST_MERGE_COMMIT}&PULL_REQUEST_PARTICIPANTS_APPROVED_COUNT=\\${PULL_REQUEST_PARTICIPANTS_APPROVED_COUNT}&PULL_REQUEST_REVIEWERS=\\${PULL_REQUEST_REVIEWERS}&PULL_REQUEST_REVIEWERS_APPROVED_COUNT=\\${PULL_REQUEST_REVIEWERS_APPROVED_COUNT}&PULL_REQUEST_REVIEWERS_ID=\\${PULL_REQUEST_REVIEWERS_ID}&PULL_REQUEST_REVIEWERS_SLUG=\\${PULL_REQUEST_REVIEWERS_SLUG}&PULL_REQUEST_STATE=\\${PULL_REQUEST_STATE}&PULL_REQUEST_TITLE=\\${PULL_REQUEST_TITLE}&PULL_REQUEST_TO_BRANCH=\\${PULL_REQUEST_TO_BRANCH}&PULL_REQUEST_TO_HASH=\\${PULL_REQUEST_TO_HASH}&PULL_REQUEST_TO_HTTP_CLONE_URL=\\${PULL_REQUEST_TO_HTTP_CLONE_URL}&PULL_REQUEST_TO_ID=\\${PULL_REQUEST_TO_ID}&PULL_REQUEST_TO_REPO_ID=\\${PULL_REQUEST_TO_REPO_ID}&PULL_REQUEST_TO_REPO_NAME=\\${PULL_REQUEST_TO_REPO_NAME}&PULL_REQUEST_TO_REPO_PROJECT_ID=\\${PULL_REQUEST_TO_REPO_PROJECT_ID}&PULL_REQUEST_TO_REPO_PROJECT_KEY=\\${PULL_REQUEST_TO_REPO_PROJECT_KEY}&PULL_REQUEST_TO_REPO_SLUG=\\${PULL_REQUEST_TO_REPO_SLUG}&PULL_REQUEST_TO_SSH_CLONE_URL=\\${PULL_REQUEST_TO_SSH_CLONE_URL}&PULL_REQUEST_URL=\\${PULL_REQUEST_URL}&PULL_REQUEST_USER_DISPLAY_NAME=\\${PULL_REQUEST_USER_DISPLAY_NAME}&PULL_REQUEST_USER_EMAIL_ADDRESS=\\${PULL_REQUEST_USER_EMAIL_ADDRESS}&PULL_REQUEST_USER_ID=\\${PULL_REQUEST_USER_ID}&PULL_REQUEST_USER_NAME=\\${PULL_REQUEST_USER_NAME}&PULL_REQUEST_USER_SLUG=\\${PULL_REQUEST_USER_SLUG}&PULL_REQUEST_VERSION=\\${PULL_REQUEST_VERSION}")// + "BUTTON_TRIGGER_TITLE=\\${BUTTON_TRIGGER_TITLE}&INJECTION_URL_VALUE=\\${INJECTION_URL_VALUE}&PULL_REQUEST_ACTION=\\${PULL_REQUEST_ACTION}&PULL_REQUEST_AUTHOR_DISPLAY_NAME=\\${PULL_REQUEST_AUTHOR_DISPLAY_NAME}&PULL_REQUEST_AUTHOR_EMAIL=\\${PULL_REQUEST_AUTHOR_EMAIL}&PULL_REQUEST_AUTHOR_ID=\\${PULL_REQUEST_AUTHOR_ID}&PULL_REQUEST_AUTHOR_NAME=\\${PULL_REQUEST_AUTHOR_NAME}&PULL_REQUEST_AUTHOR_SLUG=\\${PULL_REQUEST_AUTHOR_SLUG}&PULL_REQUEST_COMMENT_ACTION=\\${PULL_REQUEST_COMMENT_ACTION}&PULL_REQUEST_COMMENT_TEXT=\\${PULL_REQUEST_COMMENT_TEXT}&PULL_REQUEST_FROM_BRANCH=\\${PULL_REQUEST_FROM_BRANCH}&PULL_REQUEST_FROM_HASH=\\${PULL_REQUEST_FROM_HASH}&PULL_REQUEST_FROM_HTTP_CLONE_URL=\\${PULL_REQUEST_FROM_HTTP_CLONE_URL}&PULL_REQUEST_FROM_ID=\\${PULL_REQUEST_FROM_ID}&PULL_REQUEST_FROM_REPO_ID=\\${PULL_REQUEST_FROM_REPO_ID}&PULL_REQUEST_FROM_REPO_NAME=\\${PULL_REQUEST_FROM_REPO_NAME}&PULL_REQUEST_FROM_REPO_PROJECT_ID=\\${PULL_REQUEST_FROM_REPO_PROJECT_ID}&PULL_REQUEST_FROM_REPO_PROJECT_KEY=\\${PULL_REQUEST_FROM_REPO_PROJECT_KEY}&PULL_REQUEST_FROM_REPO_SLUG=\\${PULL_REQUEST_FROM_REPO_SLUG}&PULL_REQUEST_FROM_SSH_CLONE_URL=\\${PULL_REQUEST_FROM_SSH_CLONE_URL}&PULL_REQUEST_ID=\\${PULL_REQUEST_ID}&PULL_REQUEST_MERGE_COMMIT=\\${PULL_REQUEST_MERGE_COMMIT}&PULL_REQUEST_PARTICIPANTS_APPROVED_COUNT=\\${PULL_REQUEST_PARTICIPANTS_APPROVED_COUNT}&PULL_REQUEST_REVIEWERS=\\${PULL_REQUEST_REVIEWERS}&PULL_REQUEST_REVIEWERS_APPROVED_COUNT=\\${PULL_REQUEST_REVIEWERS_APPROVED_COUNT}&PULL_REQUEST_REVIEWERS_ID=\\${PULL_REQUEST_REVIEWERS_ID}&PULL_REQUEST_REVIEWERS_SLUG=\\${PULL_REQUEST_REVIEWERS_SLUG}&PULL_REQUEST_STATE=\\${PULL_REQUEST_STATE}&PULL_REQUEST_TITLE=\\${PULL_REQUEST_TITLE}&PULL_REQUEST_TO_BRANCH=\\${PULL_REQUEST_TO_BRANCH}&PULL_REQUEST_TO_HASH=\\${PULL_REQUEST_TO_HASH}&PULL_REQUEST_TO_HTTP_CLONE_URL=\\${PULL_REQUEST_TO_HTTP_CLONE_URL}&PULL_REQUEST_TO_ID=\\${PULL_REQUEST_TO_ID}&PULL_REQUEST_TO_REPO_ID=\\${PULL_REQUEST_TO_REPO_ID}&PULL_REQUEST_TO_REPO_NAME=\\${PULL_REQUEST_TO_REPO_NAME}&PULL_REQUEST_TO_REPO_PROJECT_ID=\\${PULL_REQUEST_TO_REPO_PROJECT_ID}&PULL_REQUEST_TO_REPO_PROJECT_KEY=\\${PULL_REQUEST_TO_REPO_PROJECT_KEY}&PULL_REQUEST_TO_REPO_SLUG=\\${PULL_REQUEST_TO_REPO_SLUG}&PULL_REQUEST_TO_SSH_CLONE_URL=\\${PULL_REQUEST_TO_SSH_CLONE_URL}&PULL_REQUEST_URL=\\${PULL_REQUEST_URL}&PULL_REQUEST_USER_DISPLAY_NAME=\\${PULL_REQUEST_USER_DISPLAY_NAME}&PULL_REQUEST_USER_EMAIL_ADDRESS=\\${PULL_REQUEST_USER_EMAIL_ADDRESS}&PULL_REQUEST_USER_ID=\\${PULL_REQUEST_USER_ID}&PULL_REQUEST_USER_NAME=\\${PULL_REQUEST_USER_NAME}&PULL_REQUEST_USER_SLUG=\\${PULL_REQUEST_USER_SLUG}&PULL_REQUEST_VERSION=\\${PULL_REQUEST_VERSION}")// .doesNotContain(EVERYTHING_URL.name()); } - private File findReadme(File file) { - File candidate = new File(file.getAbsolutePath() + "/README.md"); - if (candidate.exists()) { - return candidate; - } - return findReadme(file.getParentFile()); - } - }