From c19f72f04d33d9e6bf9c4469e594dada5c69f8de Mon Sep 17 00:00:00 2001 From: Tomas Bjerre Date: Mon, 9 Nov 2015 17:36:20 +0100 Subject: [PATCH] Fixing PULL_REQUEST_URL-bug correctly with getSlug #82 --- CHANGELOG.md | 3 +++ src/main/java/se/bjurr/prnfb/listener/PrnfbRenderer.java | 5 ++--- .../bjurr/prnfb/admin/PrnfbPullRequestEventListenerTest.java | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a544a42f..836a8d5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ Changelog of Pull Request Notifier for Bitbucket. +## 2.12 +* Fixing PULL_REQUEST_URL-bug correctly with getSlug. + ## 2.11 * Bugfix: Replacing spaces with dashes in ${PULL_REQUEST_URL}. Was evaluating to wrong URL if repo name included spaces. diff --git a/src/main/java/se/bjurr/prnfb/listener/PrnfbRenderer.java b/src/main/java/se/bjurr/prnfb/listener/PrnfbRenderer.java index a98b7c6f..d452a6c7 100644 --- a/src/main/java/se/bjurr/prnfb/listener/PrnfbRenderer.java +++ b/src/main/java/se/bjurr/prnfb/listener/PrnfbRenderer.java @@ -420,9 +420,8 @@ private static String cloneUrlFromRepository(REPO_PROTOCOL protocol, Repository } private static String getPullRequestUrl(ApplicationPropertiesService propertiesService, PullRequest pullRequest) { - return (propertiesService.getBaseUrl() + "/projects/" + pullRequest.getToRef().getRepository().getProject().getKey() - + "/repos/" + pullRequest.getToRef().getRepository().getName() + "/pull-requests/" + pullRequest.getId()) - .replaceAll(" ", "-"); + return propertiesService.getBaseUrl() + "/projects/" + pullRequest.getToRef().getRepository().getProject().getKey() + + "/repos/" + pullRequest.getToRef().getRepository().getSlug() + "/pull-requests/" + pullRequest.getId(); } PrnfbVariable(Resolver resolver) { diff --git a/src/test/java/se/bjurr/prnfb/admin/PrnfbPullRequestEventListenerTest.java b/src/test/java/se/bjurr/prnfb/admin/PrnfbPullRequestEventListenerTest.java index ce842fe4..494f8ecb 100644 --- a/src/test/java/se/bjurr/prnfb/admin/PrnfbPullRequestEventListenerTest.java +++ b/src/test/java/se/bjurr/prnfb/admin/PrnfbPullRequestEventListenerTest.java @@ -411,7 +411,7 @@ public void testThatAUrlWithVariablesExceptFromAndToCanBeInvoked() throws Except pullRequestRefBuilder() // .withProjectKey("theProject") // .withRepositoryName("the Repo Name") // - ) // + .withRepositorySlug("the-repo-name")) // .withPullRequestAction(OPENED) // .withAuthor( // prnfbParticipantBuilder() // @@ -426,7 +426,7 @@ public void testThatAUrlWithVariablesExceptFromAndToCanBeInvoked() throws Except ) // .invokedUrl( 0, - "http://bjurr.se/id=10&action=OPENED&displayName=authorDisplayName&authorEmail=authorEmail&authorId=100&authorName=authorName&authorSlug=authorSlug&pullRequestUrl=http%3A%2F%2Fbitbucket.server%2Fprojects%2FtheProject%2Frepos%2Fthe-Repo-Name%2Fpull-requests%2F10" // + "http://bjurr.se/id=10&action=OPENED&displayName=authorDisplayName&authorEmail=authorEmail&authorId=100&authorName=authorName&authorSlug=authorSlug&pullRequestUrl=http%3A%2F%2Fbitbucket.server%2Fprojects%2FtheProject%2Frepos%2Fthe-repo-name%2Fpull-requests%2F10" // ); }