Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
[Issue-31] PULL_REQUEST_FROM_BRANCH and PULL_REQUEST_TO_BRANCH now co…
Browse files Browse the repository at this point in the history
…ntains fhe full branch name.
  • Loading branch information
christiangalsterer committed Apr 22, 2015
1 parent 8d627ed commit 8f00c46
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
10 changes: 2 additions & 8 deletions src/main/java/se/bjurr/prnfs/listener/PrnfsRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down Expand Up @@ -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");
}

Expand All @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -51,7 +52,7 @@ public PullRequestEventBuilder build() {

@Override
public String getDisplayId() {
return null;
return displayId;
}

@Override
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8f00c46

Please sign in to comment.