From 8f00c461d72c96e2ce74eb3c1a477c8c222e2872 Mon Sep 17 00:00:00 2001 From: Christian Galsterer Date: Wed, 22 Apr 2015 19:50:41 +0200 Subject: [PATCH] [Issue-31] PULL_REQUEST_FROM_BRANCH and PULL_REQUEST_TO_BRANCH now contains fhe full branch name. --- .../java/se/bjurr/prnfs/listener/PrnfsRenderer.java | 10 ++-------- .../prnfs/admin/PrnfsPullRequestEventListenerTest.java | 6 +++--- .../bjurr/prnfs/admin/utils/PullRequestRefBuilder.java | 8 +++++++- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/se/bjurr/prnfs/listener/PrnfsRenderer.java b/src/main/java/se/bjurr/prnfs/listener/PrnfsRenderer.java index 0854eda..73d5667 100644 --- a/src/main/java/se/bjurr/prnfs/listener/PrnfsRenderer.java +++ b/src/main/java/se/bjurr/prnfs/listener/PrnfsRenderer.java @@ -34,7 +34,7 @@ public String resolve(PullRequestEvent pullRequestEvent, RepositoryService repos }), PULL_REQUEST_FROM_BRANCH(new Resolver() { @Override public String resolve(PullRequestEvent pullRequestEvent, RepositoryService repositoryService) { - return branchNameFromId(pullRequestEvent.getPullRequest().getFromRef()); + return pullRequestEvent.getPullRequest().getFromRef().getDisplayId(); } }), PULL_REQUEST_FROM_REPO_ID(new Resolver() { @Override @@ -126,7 +126,7 @@ public String resolve(PullRequestEvent pullRequestEvent, RepositoryService repos }), PULL_REQUEST_TO_BRANCH(new Resolver() { @Override public String resolve(PullRequestEvent pullRequestEvent, RepositoryService repositoryService) { - return branchNameFromId(pullRequestEvent.getPullRequest().getToRef()); + return pullRequestEvent.getPullRequest().getToRef().getDisplayId(); } }), PULL_REQUEST_TO_REPO_ID(new Resolver() { @Override @@ -176,12 +176,6 @@ public String resolve(PullRequestEvent pullRequestEvent, RepositoryService repos private Resolver resolver; - private static String branchNameFromId(PullRequestRef pullRequestRef) { - String branchId = pullRequestRef.getId(); - int lastSlash = branchId.lastIndexOf('/'); - return branchId.substring(lastSlash + 1); - } - private static String cloneUrlFromRepository(REPO_PROTOCOL protocol, Repository repository, RepositoryService repositoryService) { RepositoryCloneLinksRequest request = new RepositoryCloneLinksRequest.Builder().protocol(protocol.name()) diff --git a/src/test/java/se/bjurr/prnfs/admin/PrnfsPullRequestEventListenerTest.java b/src/test/java/se/bjurr/prnfs/admin/PrnfsPullRequestEventListenerTest.java index 59a728d..11fcde7 100644 --- a/src/test/java/se/bjurr/prnfs/admin/PrnfsPullRequestEventListenerTest.java +++ b/src/test/java/se/bjurr/prnfs/admin/PrnfsPullRequestEventListenerTest.java @@ -112,7 +112,7 @@ public void testThatAUrlWithVariablesFromCanBeInvoked() { refBuilder.withHash("10").withId("10").withProjectId(10).withProjectKey("10").withRepositoryId(10) .withRepositoryName("10").withRepositorySlug("10").withCloneUrl(PrnfsRenderer.REPO_PROTOCOL.http, "10") - .withCloneUrl(PrnfsRenderer.REPO_PROTOCOL.ssh, "10").build() // + .withCloneUrl(PrnfsRenderer.REPO_PROTOCOL.ssh, "10").withDisplayId("10").build() // .withId(10L).withPullRequestAction(OPENED).triggerEvent().invokedUrl(0, "http://bjurr.se/10"); } } @@ -155,7 +155,7 @@ public void testThatAUrlWithVariableFromBranchCanBeInvokedWhenBranchIdContainsSl "http://bjurr.se/${" + PrnfsVariable.PULL_REQUEST_FROM_BRANCH.name() + "}") .withFieldValue(AdminFormValues.FIELDS.events, OPENED.name()).build()).store() .trigger(pullRequestEventBuilder() // - .withFromRef(pullRequestRefBuilder().withId("refs/heads/branchmodmerge")) // + .withFromRef(pullRequestRefBuilder().withId("refs/heads/branchmodmerge").withDisplayId("branchmodmerge")) // .withId(10L).withPullRequestAction(OPENED).build()).invokedUrl(0, "http://bjurr.se/branchmodmerge"); } @@ -169,7 +169,7 @@ public void testThatAUrlWithVariableFromBranchCanBeInvokedWhenBranchIdContainsOn "http://bjurr.se/${" + PrnfsVariable.PULL_REQUEST_FROM_BRANCH.name() + "}") .withFieldValue(AdminFormValues.FIELDS.events, OPENED.name()).build()).store() .trigger(pullRequestEventBuilder() // - .withFromRef(pullRequestRefBuilder().withId("branchmodmerge")) // + .withFromRef(pullRequestRefBuilder().withId("branchmodmerge").withDisplayId("branchmodmerge")) // .withId(10L).withPullRequestAction(OPENED).build()).invokedUrl(0, "http://bjurr.se/branchmodmerge"); } diff --git a/src/test/java/se/bjurr/prnfs/admin/utils/PullRequestRefBuilder.java b/src/test/java/se/bjurr/prnfs/admin/utils/PullRequestRefBuilder.java index 10ac127..a388d68 100644 --- a/src/test/java/se/bjurr/prnfs/admin/utils/PullRequestRefBuilder.java +++ b/src/test/java/se/bjurr/prnfs/admin/utils/PullRequestRefBuilder.java @@ -30,6 +30,7 @@ public static PullRequestRefBuilder pullRequestRefBuilder() { private String projectKey; private Integer repositoryId; private String repositoryName; + private String displayId; private String slug; private PullRequestEventBuilder pullRequestEventBuilder; @@ -51,7 +52,7 @@ public PullRequestEventBuilder build() { @Override public String getDisplayId() { - return null; + return displayId; } @Override @@ -218,6 +219,11 @@ public PullRequestRefBuilder withCloneUrl(PrnfsRenderer.REPO_PROTOCOL protocol, return this; } + public PullRequestRefBuilder withDisplayId(String displayId) { + this.displayId = displayId; + return this; + } + private void mockCloneUrl(REPO_PROTOCOL protocol, RepositoryService repositoryService, final String url) { NamedLink e = new NamedLink() { @Override