11package se .bjurr .prnfb .listener ;
22
33import static com .google .common .base .Charsets .UTF_8 ;
4+ import static com .google .common .base .Joiner .on ;
45import static com .google .common .base .Throwables .propagate ;
56import static com .google .common .collect .Iterables .filter ;
7+ import static com .google .common .collect .Iterables .transform ;
68import static com .google .common .collect .Lists .newArrayList ;
9+ import static com .google .common .collect .Ordering .usingToString ;
710import static java .net .URLEncoder .encode ;
811import static java .util .logging .Logger .getLogger ;
912import 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 ,
0 commit comments