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

Commit f016b29

Browse files
committed
Updating CHANGELOG.md
* And correcting test case assertion for reviewers variables.
1 parent 91e0c43 commit f016b29

File tree

3 files changed

+18
-38
lines changed

3 files changed

+18
-38
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
Changelog of Pull Request Notifier for Bitbucket.
44

5+
## 2.14
6+
* Bugfix: Fixing IndexOutOfBoundsException if no reviewers and using reviewers variable
7+
58
## 2.13
69
* Allowing SSL certificates to be ignored.
710
* Adding settings to configure custom keystore.

src/main/java/se/bjurr/prnfb/listener/PrnfbRenderer.java

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package se.bjurr.prnfb.listener;
22

33
import static com.google.common.base.Charsets.UTF_8;
4+
import static com.google.common.base.Joiner.on;
45
import static com.google.common.base.Throwables.propagate;
56
import static com.google.common.collect.Iterables.filter;
7+
import static com.google.common.collect.Iterables.transform;
68
import static com.google.common.collect.Lists.newArrayList;
9+
import static com.google.common.collect.Ordering.usingToString;
710
import static java.net.URLEncoder.encode;
811
import static java.util.logging.Logger.getLogger;
912
import static java.util.regex.Pattern.compile;
@@ -447,51 +450,25 @@ public String resolve(PullRequest pullRequest, PrnfbPullRequestAction pullReques
447450
ApplicationUser applicationUser, RepositoryService repositoryService,
448451
ApplicationPropertiesService propertiesService, PrnfbNotification prnfbNotification,
449452
Map<PrnfbVariable, Supplier<String>> variables, ClientKeyStore clientKeyStore, boolean shouldAcceptAnyCertificate) {
450-
List<PullRequestParticipant> slist = newArrayList(pullRequest.getReviewers());
451-
452-
if (slist.isEmpty()) {
453-
return "";
454-
}
455-
StringBuilder sb = new StringBuilder();
456-
for (PullRequestParticipant each : slist) {
457-
sb.append("," + each.getUser().getDisplayName());
458-
}
459-
return sb.substring(1);
453+
return iterableToString(transform(pullRequest.getReviewers(), (p) -> p.getUser().getDisplayName()));
460454
}
461455
}), PULL_REQUEST_REVIEWERS_ID(new Resolver() {
462456
@Override
463457
public String resolve(PullRequest pullRequest, PrnfbPullRequestAction pullRequestAction,
464458
ApplicationUser applicationUser, RepositoryService repositoryService,
465459
ApplicationPropertiesService propertiesService, PrnfbNotification prnfbNotification,
466460
Map<PrnfbVariable, Supplier<String>> variables, ClientKeyStore clientKeyStore, boolean shouldAcceptAnyCertificate) {
467-
List<PullRequestParticipant> slist = newArrayList(pullRequest.getReviewers());
468-
469-
if (slist.isEmpty()) {
470-
return "";
471-
}
472-
StringBuilder sb = new StringBuilder();
473-
for (PullRequestParticipant each : slist) {
474-
sb.append("," + each.getUser().getId());
475-
}
476-
return sb.substring(1);
461+
return iterableToString(transform(pullRequest.getReviewers(), (p) -> Integer.toString(p.getUser().getId())));
477462
}
478463
}), PULL_REQUEST_REVIEWERS_SLUG(new Resolver() {
479464
@Override
480465
public String resolve(PullRequest pullRequest, PrnfbPullRequestAction pullRequestAction,
481466
ApplicationUser applicationUser, RepositoryService repositoryService,
482467
ApplicationPropertiesService propertiesService, PrnfbNotification prnfbNotification,
483468
Map<PrnfbVariable, Supplier<String>> variables, ClientKeyStore clientKeyStore, boolean shouldAcceptAnyCertificate) {
484-
List<PullRequestParticipant> slist = newArrayList(pullRequest.getReviewers());
485-
486-
if (slist.isEmpty()) {
487-
return "";
488-
}
489-
StringBuilder sb = new StringBuilder();
490-
for (PullRequestParticipant each : slist) {
491-
sb.append("," + each.getUser().getSlug());
492-
}
493-
return sb.substring(1);
469+
return iterableToString(transform(pullRequest.getReviewers(), (p) -> p.getUser().getSlug()));
494470
}
471+
495472
}), PULL_REQUEST_REVIEWERS_APPROVED_COUNT(new Resolver() {
496473
@Override
497474
public String resolve(PullRequest pullRequest, PrnfbPullRequestAction pullRequestAction,
@@ -517,6 +494,11 @@ public boolean apply(PullRequestParticipant input) {
517494
}
518495
};
519496

497+
private static String iterableToString(Iterable<String> slist) {
498+
List<String> sorted = usingToString().sortedCopy(slist);
499+
return on(',').join(sorted);
500+
}
501+
520502
private Resolver resolver;
521503

522504
private static String cloneUrlFromRepository(REPO_PROTOCOL protocol, Repository repository,

src/test/java/se/bjurr/prnfb/admin/PrnfbPullRequestEventListenerTest.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,6 @@ public void testThatAdminFormFieldsAreUsedInAdminGUI() throws IOException {
108108
public void testThatAUrlCanHaveSeveralVariables() throws Exception {
109109
prnfbTestBuilder()
110110
.isLoggedInAsAdmin()
111-
.withPullRequest(//
112-
pullRequestEventBuilder()//
113-
.withParticipantReviewer(REVIEWER, false, "First Last", "firstlast", 1)//
114-
.withParticipantReviewer(REVIEWER, false, "First2 Last2", "firstlast2", 5)//
115-
.withParticipant(PARTICIPANT)//
116-
.build()//
117-
.getPullRequest())
118111
.withNotification( //
119112
notificationBuilder() //
120113
.withFieldValue(
@@ -144,11 +137,13 @@ public void testThatAUrlCanHaveSeveralVariables() throws Exception {
144137
.withParticipantReviewer(AUTHOR, TRUE) //
145138
.withParticipantReviewer(AUTHOR, TRUE) //
146139
.withParticipantReviewer(AUTHOR, FALSE) //
140+
.withParticipantReviewer(REVIEWER, false, "First Last", "firstlast", 1)//
141+
.withParticipantReviewer(REVIEWER, false, "First2 Last2", "firstlast2", 5)//
147142
.build() //
148143
) //
149144
.invokedUrl(
150145
0,
151-
"http://bjurr.se/?PULL_REQUEST_FROM_HASH=cde456&PULL_REQUEST_TO_HASH=asd123&PULL_REQUEST_FROM_REPO_SLUG=fromslug&PULL_REQUEST_TO_REPO_SLUG=toslug&revapp=2&partapp=3&reviewers=name%2Cname%2Cname&reviewersid=1%2C1%2C1&reviewersslug=username%2Cusername%2Cusername") //
146+
"http://bjurr.se/?PULL_REQUEST_FROM_HASH=cde456&PULL_REQUEST_TO_HASH=asd123&PULL_REQUEST_FROM_REPO_SLUG=fromslug&PULL_REQUEST_TO_REPO_SLUG=toslug&revapp=2&partapp=3&reviewers=First+Last%2CFirst2+Last2%2Cname%2Cname%2Cname&reviewersid=1%2C1%2C1%2C1%2C5&reviewersslug=firstlast%2Cfirstlast2%2Cusername%2Cusername%2Cusername") //
152147
.invokedMethod(GET);
153148
}
154149

0 commit comments

Comments
 (0)