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

Commit 6b8832e

Browse files
committed
New variables to list approved, unapproved and needs work #192
* PULL_REQUEST_REVIEWERS_APPROVED_SLUG * PULL_REQUEST_REVIEWERS_APPROVED_EMAIL * PULL_REQUEST_REVIEWERS_APPROVED_NAME * PULL_REQUEST_REVIEWERS_UNAPPROVED_SLUG * PULL_REQUEST_REVIEWERS_UNAPPROVED_EMAIL * PULL_REQUEST_REVIEWERS_UNAPPROVED_NAME * PULL_REQUEST_REVIEWERS_NEEDS_WORK_SLUG * PULL_REQUEST_REVIEWERS_NEEDS_WORK_EMAIL * PULL_REQUEST_REVIEWERS_NEEDS_WORK_NAME
1 parent 020dfc3 commit 6b8832e

File tree

6 files changed

+225
-7
lines changed

6 files changed

+225
-7
lines changed

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,22 @@ Changelog of Pull Request Notifier for Bitbucket.
88

99
* This is what happens when reviewer clicks "needs work".
1010

11-
[f0755ff21dc7ae2](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/f0755ff21dc7ae2) Tomas Bjerre *2017-02-01 18:16:39*
11+
[020dfc3bb372ca2](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/020dfc3bb372ca2) Tomas Bjerre *2017-02-01 18:17:48*
12+
13+
### GitHub [#192](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/192) Include status for participants
14+
New variables to list approved, unapproved and needs work
15+
16+
* PULL_REQUEST_REVIEWERS_APPROVED_SLUG
17+
* PULL_REQUEST_REVIEWERS_APPROVED_EMAIL
18+
* PULL_REQUEST_REVIEWERS_APPROVED_NAME
19+
* PULL_REQUEST_REVIEWERS_UNAPPROVED_SLUG
20+
* PULL_REQUEST_REVIEWERS_UNAPPROVED_EMAIL
21+
* PULL_REQUEST_REVIEWERS_UNAPPROVED_NAME
22+
* PULL_REQUEST_REVIEWERS_NEEDS_WORK_SLUG
23+
* PULL_REQUEST_REVIEWERS_NEEDS_WORK_EMAIL
24+
* PULL_REQUEST_REVIEWERS_NEEDS_WORK_NAME
25+
26+
[72607d4617b0e7d](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/72607d4617b0e7d) Tomas Bjerre *2017-02-01 19:16:26*
1227

1328
### No issue
1429
doc

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,17 @@ The filter text as well as the URL support variables. These are:
7777
| `${PULL_REQUEST_REVIEWERS_SLUG}` | Example: `admin,user` |
7878
| `${PULL_REQUEST_REVIEWERS_EMAIL}` | Example: `admin@example.com,user@example.com` |
7979
| `${PULL_REQUEST_REVIEWERS_APPROVED_COUNT}` | Number of reviewers that approved the PR. |
80+
| `${PULL_REQUEST_REVIEWERS_APPROVED_SLUG}` | Example: admin,user. |
81+
| `${PULL_REQUEST_REVIEWERS_APPROVED_EMAIL}` | Example: admin@example.com,user@example.com. |
82+
| `${PULL_REQUEST_REVIEWERS_APPROVED_NAME}` | Example: Admin,User. |
8083
| `${PULL_REQUEST_REVIEWERS_UNAPPROVED_COUNT}` | Number of reviewers that unapproved the PR. |
84+
| `${PULL_REQUEST_REVIEWERS_UNAPPROVED_SLUG}` | Example: admin,user. |
85+
| `${PULL_REQUEST_REVIEWERS_UNAPPROVED_EMAIL}` | Example: admin@example.com,user@example.com. |
86+
| `${PULL_REQUEST_REVIEWERS_UNAPPROVED_NAME}` | Example: Admin,User. |
8187
| `${PULL_REQUEST_REVIEWERS_NEEDS_WORK_COUNT}` | Number of reviewers that says the PR needs work. |
88+
| `${PULL_REQUEST_REVIEWERS_NEEDS_WORK_SLUG}` | Example: admin,user. |
89+
| `${PULL_REQUEST_REVIEWERS_NEEDS_WORK_EMAIL}` | Example: admin@example.com,user@example.com. |
90+
| `${PULL_REQUEST_REVIEWERS_NEEDS_WORK_NAME}` | Example: Admin,User. |
8291
| `${PULL_REQUEST_PARTICIPANTS_APPROVED_COUNT}` | Number of participants that approved the PR. |
8392
| `${PULL_REQUEST_PARTICIPANTS_EMAIL}` | Example: `admin@example.com,user@example.com` |
8493
| `${PULL_REQUEST_MERGE_COMMIT}` | Hash of merged commit (only available for merged-event). |

src/main/java/se/bjurr/prnfb/service/PrnfbVariable.java

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package se.bjurr.prnfb.service;
22

3+
import static com.atlassian.bitbucket.pull.PullRequestParticipantStatus.APPROVED;
34
import static com.atlassian.bitbucket.pull.PullRequestParticipantStatus.NEEDS_WORK;
45
import static com.atlassian.bitbucket.pull.PullRequestParticipantStatus.UNAPPROVED;
56
import static com.google.common.base.Joiner.on;
@@ -582,6 +583,177 @@ public String resolve(
582583
transform(pullRequest.getReviewers(), (p) -> p.getUser().getEmailAddress()));
583584
}
584585
}),
586+
PULL_REQUEST_REVIEWERS_NEEDS_WORK_SLUG(
587+
new PrnfbVariableResolver() {
588+
@Override
589+
public String resolve(
590+
PullRequest pullRequest,
591+
PrnfbPullRequestAction pullRequestAction,
592+
ApplicationUser applicationUser,
593+
RepositoryService repositoryService,
594+
ApplicationPropertiesService propertiesService,
595+
PrnfbNotification prnfbNotification,
596+
Map<PrnfbVariable, Supplier<String>> variables,
597+
ClientKeyStore clientKeyStore,
598+
boolean shouldAcceptAnyCertificate,
599+
SecurityService securityService) {
600+
Iterable<PullRequestParticipant> reviewers =
601+
filter(pullRequest.getReviewers(), (r) -> r.getStatus() == NEEDS_WORK);
602+
return iterableToString(transform(reviewers, (p) -> p.getUser().getSlug()));
603+
}
604+
}),
605+
PULL_REQUEST_REVIEWERS_NEEDS_WORK_EMAIL(
606+
new PrnfbVariableResolver() {
607+
@Override
608+
public String resolve(
609+
PullRequest pullRequest,
610+
PrnfbPullRequestAction pullRequestAction,
611+
ApplicationUser applicationUser,
612+
RepositoryService repositoryService,
613+
ApplicationPropertiesService propertiesService,
614+
PrnfbNotification prnfbNotification,
615+
Map<PrnfbVariable, Supplier<String>> variables,
616+
ClientKeyStore clientKeyStore,
617+
boolean shouldAcceptAnyCertificate,
618+
SecurityService securityService) {
619+
Iterable<PullRequestParticipant> reviewers =
620+
filter(pullRequest.getReviewers(), (r) -> r.getStatus() == NEEDS_WORK);
621+
return iterableToString(transform(reviewers, (p) -> p.getUser().getEmailAddress()));
622+
}
623+
}),
624+
PULL_REQUEST_REVIEWERS_NEEDS_WORK_NAME(
625+
new PrnfbVariableResolver() {
626+
@Override
627+
public String resolve(
628+
PullRequest pullRequest,
629+
PrnfbPullRequestAction pullRequestAction,
630+
ApplicationUser applicationUser,
631+
RepositoryService repositoryService,
632+
ApplicationPropertiesService propertiesService,
633+
PrnfbNotification prnfbNotification,
634+
Map<PrnfbVariable, Supplier<String>> variables,
635+
ClientKeyStore clientKeyStore,
636+
boolean shouldAcceptAnyCertificate,
637+
SecurityService securityService) {
638+
Iterable<PullRequestParticipant> reviewers =
639+
filter(pullRequest.getReviewers(), (r) -> r.getStatus() == NEEDS_WORK);
640+
return iterableToString(transform(reviewers, (p) -> p.getUser().getName()));
641+
}
642+
}),
643+
PULL_REQUEST_REVIEWERS_UNAPPROVED_SLUG(
644+
new PrnfbVariableResolver() {
645+
@Override
646+
public String resolve(
647+
PullRequest pullRequest,
648+
PrnfbPullRequestAction pullRequestAction,
649+
ApplicationUser applicationUser,
650+
RepositoryService repositoryService,
651+
ApplicationPropertiesService propertiesService,
652+
PrnfbNotification prnfbNotification,
653+
Map<PrnfbVariable, Supplier<String>> variables,
654+
ClientKeyStore clientKeyStore,
655+
boolean shouldAcceptAnyCertificate,
656+
SecurityService securityService) {
657+
Iterable<PullRequestParticipant> reviewers =
658+
filter(pullRequest.getReviewers(), (r) -> r.getStatus() == UNAPPROVED);
659+
return iterableToString(transform(reviewers, (p) -> p.getUser().getSlug()));
660+
}
661+
}),
662+
PULL_REQUEST_REVIEWERS_UNAPPROVED_EMAIL(
663+
new PrnfbVariableResolver() {
664+
@Override
665+
public String resolve(
666+
PullRequest pullRequest,
667+
PrnfbPullRequestAction pullRequestAction,
668+
ApplicationUser applicationUser,
669+
RepositoryService repositoryService,
670+
ApplicationPropertiesService propertiesService,
671+
PrnfbNotification prnfbNotification,
672+
Map<PrnfbVariable, Supplier<String>> variables,
673+
ClientKeyStore clientKeyStore,
674+
boolean shouldAcceptAnyCertificate,
675+
SecurityService securityService) {
676+
Iterable<PullRequestParticipant> reviewers =
677+
filter(pullRequest.getReviewers(), (r) -> r.getStatus() == UNAPPROVED);
678+
return iterableToString(transform(reviewers, (p) -> p.getUser().getEmailAddress()));
679+
}
680+
}),
681+
PULL_REQUEST_REVIEWERS_UNAPPROVED_NAME(
682+
new PrnfbVariableResolver() {
683+
@Override
684+
public String resolve(
685+
PullRequest pullRequest,
686+
PrnfbPullRequestAction pullRequestAction,
687+
ApplicationUser applicationUser,
688+
RepositoryService repositoryService,
689+
ApplicationPropertiesService propertiesService,
690+
PrnfbNotification prnfbNotification,
691+
Map<PrnfbVariable, Supplier<String>> variables,
692+
ClientKeyStore clientKeyStore,
693+
boolean shouldAcceptAnyCertificate,
694+
SecurityService securityService) {
695+
Iterable<PullRequestParticipant> reviewers =
696+
filter(pullRequest.getReviewers(), (r) -> r.getStatus() == UNAPPROVED);
697+
return iterableToString(transform(reviewers, (p) -> p.getUser().getName()));
698+
}
699+
}),
700+
PULL_REQUEST_REVIEWERS_APPROVED_SLUG(
701+
new PrnfbVariableResolver() {
702+
@Override
703+
public String resolve(
704+
PullRequest pullRequest,
705+
PrnfbPullRequestAction pullRequestAction,
706+
ApplicationUser applicationUser,
707+
RepositoryService repositoryService,
708+
ApplicationPropertiesService propertiesService,
709+
PrnfbNotification prnfbNotification,
710+
Map<PrnfbVariable, Supplier<String>> variables,
711+
ClientKeyStore clientKeyStore,
712+
boolean shouldAcceptAnyCertificate,
713+
SecurityService securityService) {
714+
Iterable<PullRequestParticipant> reviewers =
715+
filter(pullRequest.getReviewers(), (r) -> r.getStatus() == APPROVED);
716+
return iterableToString(transform(reviewers, (p) -> p.getUser().getSlug()));
717+
}
718+
}),
719+
PULL_REQUEST_REVIEWERS_APPROVED_EMAIL(
720+
new PrnfbVariableResolver() {
721+
@Override
722+
public String resolve(
723+
PullRequest pullRequest,
724+
PrnfbPullRequestAction pullRequestAction,
725+
ApplicationUser applicationUser,
726+
RepositoryService repositoryService,
727+
ApplicationPropertiesService propertiesService,
728+
PrnfbNotification prnfbNotification,
729+
Map<PrnfbVariable, Supplier<String>> variables,
730+
ClientKeyStore clientKeyStore,
731+
boolean shouldAcceptAnyCertificate,
732+
SecurityService securityService) {
733+
Iterable<PullRequestParticipant> reviewers =
734+
filter(pullRequest.getReviewers(), (r) -> r.getStatus() == APPROVED);
735+
return iterableToString(transform(reviewers, (p) -> p.getUser().getEmailAddress()));
736+
}
737+
}),
738+
PULL_REQUEST_REVIEWERS_APPROVED_NAME(
739+
new PrnfbVariableResolver() {
740+
@Override
741+
public String resolve(
742+
PullRequest pullRequest,
743+
PrnfbPullRequestAction pullRequestAction,
744+
ApplicationUser applicationUser,
745+
RepositoryService repositoryService,
746+
ApplicationPropertiesService propertiesService,
747+
PrnfbNotification prnfbNotification,
748+
Map<PrnfbVariable, Supplier<String>> variables,
749+
ClientKeyStore clientKeyStore,
750+
boolean shouldAcceptAnyCertificate,
751+
SecurityService securityService) {
752+
Iterable<PullRequestParticipant> reviewers =
753+
filter(pullRequest.getReviewers(), (r) -> r.getStatus() == APPROVED);
754+
return iterableToString(transform(reviewers, (p) -> p.getUser().getName()));
755+
}
756+
}),
585757
PULL_REQUEST_REVIEWERS_ID(
586758
new PrnfbVariableResolver() {
587759
@Override

src/main/resources/admin.vm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,17 @@
7676
<li><b>${PULL_REQUEST_REVIEWERS_SLUG}</b> Reviewers slug list.</li>
7777
<li><b>${PULL_REQUEST_REVIEWERS_EMAIL}</b> Example: admin@example.com,user@example.com.</li>
7878
<li><b>${PULL_REQUEST_REVIEWERS_APPROVED_COUNT}</b> Number of reviewers that approved the PR.</li>
79+
<li><b>${PULL_REQUEST_REVIEWERS_APPROVED_SLUG}</b> Example: admin,user.</li>
80+
<li><b>${PULL_REQUEST_REVIEWERS_APPROVED_EMAIL}</b> Example: admin@example.com,user@example.com.</li>
81+
<li><b>${PULL_REQUEST_REVIEWERS_APPROVED_NAME}</b> Example: Admin,User.</li>
7982
<li><b>${PULL_REQUEST_REVIEWERS_UNAPPROVED_COUNT}</b> Number of reviewers that unapproved the PR.</li>
83+
<li><b>${PULL_REQUEST_REVIEWERS_UNAPPROVED_SLUG}</b> Example: admin,user.</li>
84+
<li><b>${PULL_REQUEST_REVIEWERS_UNAPPROVED_EMAIL}</b> Example: admin@example.com,user@example.com.</li>
85+
<li><b>${PULL_REQUEST_REVIEWERS_UNAPPROVED_NAME}</b> Example: Admin,User.</li>
8086
<li><b>${PULL_REQUEST_REVIEWERS_NEEDS_WORK_COUNT}</b> Number of reviewers that says the PR needs work.</li>
87+
<li><b>${PULL_REQUEST_REVIEWERS_NEEDS_WORK_SLUG}</b> Example: admin,user.</li>
88+
<li><b>${PULL_REQUEST_REVIEWERS_NEEDS_WORK_EMAIL}</b> Example: admin@example.com,user@example.com.</li>
89+
<li><b>${PULL_REQUEST_REVIEWERS_NEEDS_WORK_NAME}</b> Example: Admin,User.</li>
8190
<li><b>${PULL_REQUEST_PARTICIPANTS_APPROVED_COUNT}</b> Number of participants that approved the PR.</li>
8291
<li><b>${PULL_REQUEST_PARTICIPANTS_EMAIL}</b> Example: admin@example.com,user@example.com.</li>
8392
<li><b>${PULL_REQUEST_MERGE_COMMIT}</b> Hash of merged commit (only available for merged-event).</li>

src/test/java/se/bjurr/prnfb/service/PrnfbRendererTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import static se.bjurr.prnfb.service.PrnfbVariable.INJECTION_URL_VALUE;
1111
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_AUTHOR_EMAIL;
1212
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_COMMENT_TEXT;
13+
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_DESCRIPTION;
1314
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_FROM_HASH;
1415
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_MERGE_COMMIT;
1516
import static se.bjurr.prnfb.settings.PrnfbNotificationBuilder.prnfbNotificationBuilder;
@@ -119,9 +120,17 @@ public void testThatEverythingCanBeRendered() throws UnsupportedEncodingExceptio
119120
shouldAcceptAnyCertificate,
120121
securityService));
121122

123+
for (PrnfbVariable v : PrnfbVariable.values()) {
124+
if (v != EVERYTHING_URL && v != PULL_REQUEST_DESCRIPTION) {
125+
assertThat(actual) //
126+
.containsOnlyOnce(v.name() + "=${" + v.name() + "}") //
127+
.doesNotContain(EVERYTHING_URL.name()) //
128+
.doesNotContain(PULL_REQUEST_DESCRIPTION.name());
129+
}
130+
}
131+
122132
assertThat(actual) //
123-
.isEqualTo(
124-
"asd BUTTON_FORM_DATA=${BUTTON_FORM_DATA}&BUTTON_TRIGGER_TITLE=${BUTTON_TRIGGER_TITLE}&INJECTION_URL_VALUE=${INJECTION_URL_VALUE}&PULL_REQUEST_ACTION=${PULL_REQUEST_ACTION}&PULL_REQUEST_AUTHOR_DISPLAY_NAME=${PULL_REQUEST_AUTHOR_DISPLAY_NAME}&PULL_REQUEST_AUTHOR_EMAIL=${PULL_REQUEST_AUTHOR_EMAIL}&PULL_REQUEST_AUTHOR_ID=${PULL_REQUEST_AUTHOR_ID}&PULL_REQUEST_AUTHOR_NAME=${PULL_REQUEST_AUTHOR_NAME}&PULL_REQUEST_AUTHOR_SLUG=${PULL_REQUEST_AUTHOR_SLUG}&PULL_REQUEST_COMMENT_ACTION=${PULL_REQUEST_COMMENT_ACTION}&PULL_REQUEST_COMMENT_TEXT=${PULL_REQUEST_COMMENT_TEXT}&PULL_REQUEST_FROM_BRANCH=${PULL_REQUEST_FROM_BRANCH}&PULL_REQUEST_FROM_HASH=${PULL_REQUEST_FROM_HASH}&PULL_REQUEST_FROM_HTTP_CLONE_URL=${PULL_REQUEST_FROM_HTTP_CLONE_URL}&PULL_REQUEST_FROM_ID=${PULL_REQUEST_FROM_ID}&PULL_REQUEST_FROM_REPO_ID=${PULL_REQUEST_FROM_REPO_ID}&PULL_REQUEST_FROM_REPO_NAME=${PULL_REQUEST_FROM_REPO_NAME}&PULL_REQUEST_FROM_REPO_PROJECT_ID=${PULL_REQUEST_FROM_REPO_PROJECT_ID}&PULL_REQUEST_FROM_REPO_PROJECT_KEY=${PULL_REQUEST_FROM_REPO_PROJECT_KEY}&PULL_REQUEST_FROM_REPO_SLUG=${PULL_REQUEST_FROM_REPO_SLUG}&PULL_REQUEST_FROM_SSH_CLONE_URL=${PULL_REQUEST_FROM_SSH_CLONE_URL}&PULL_REQUEST_ID=${PULL_REQUEST_ID}&PULL_REQUEST_MERGE_COMMIT=${PULL_REQUEST_MERGE_COMMIT}&PULL_REQUEST_PARTICIPANTS_APPROVED_COUNT=${PULL_REQUEST_PARTICIPANTS_APPROVED_COUNT}&PULL_REQUEST_PARTICIPANTS_EMAIL=${PULL_REQUEST_PARTICIPANTS_EMAIL}&PULL_REQUEST_REVIEWERS=${PULL_REQUEST_REVIEWERS}&PULL_REQUEST_REVIEWERS_APPROVED_COUNT=${PULL_REQUEST_REVIEWERS_APPROVED_COUNT}&PULL_REQUEST_REVIEWERS_EMAIL=${PULL_REQUEST_REVIEWERS_EMAIL}&PULL_REQUEST_REVIEWERS_ID=${PULL_REQUEST_REVIEWERS_ID}&PULL_REQUEST_REVIEWERS_NEEDS_WORK_COUNT=${PULL_REQUEST_REVIEWERS_NEEDS_WORK_COUNT}&PULL_REQUEST_REVIEWERS_SLUG=${PULL_REQUEST_REVIEWERS_SLUG}&PULL_REQUEST_REVIEWERS_UNAPPROVED_COUNT=${PULL_REQUEST_REVIEWERS_UNAPPROVED_COUNT}&PULL_REQUEST_STATE=${PULL_REQUEST_STATE}&PULL_REQUEST_TITLE=${PULL_REQUEST_TITLE}&PULL_REQUEST_TO_BRANCH=${PULL_REQUEST_TO_BRANCH}&PULL_REQUEST_TO_HASH=${PULL_REQUEST_TO_HASH}&PULL_REQUEST_TO_HTTP_CLONE_URL=${PULL_REQUEST_TO_HTTP_CLONE_URL}&PULL_REQUEST_TO_ID=${PULL_REQUEST_TO_ID}&PULL_REQUEST_TO_REPO_ID=${PULL_REQUEST_TO_REPO_ID}&PULL_REQUEST_TO_REPO_NAME=${PULL_REQUEST_TO_REPO_NAME}&PULL_REQUEST_TO_REPO_PROJECT_ID=${PULL_REQUEST_TO_REPO_PROJECT_ID}&PULL_REQUEST_TO_REPO_PROJECT_KEY=${PULL_REQUEST_TO_REPO_PROJECT_KEY}&PULL_REQUEST_TO_REPO_SLUG=${PULL_REQUEST_TO_REPO_SLUG}&PULL_REQUEST_TO_SSH_CLONE_URL=${PULL_REQUEST_TO_SSH_CLONE_URL}&PULL_REQUEST_URL=${PULL_REQUEST_URL}&PULL_REQUEST_USER_DISPLAY_NAME=${PULL_REQUEST_USER_DISPLAY_NAME}&PULL_REQUEST_USER_EMAIL_ADDRESS=${PULL_REQUEST_USER_EMAIL_ADDRESS}&PULL_REQUEST_USER_ID=${PULL_REQUEST_USER_ID}&PULL_REQUEST_USER_NAME=${PULL_REQUEST_USER_NAME}&PULL_REQUEST_USER_SLUG=${PULL_REQUEST_USER_SLUG}&PULL_REQUEST_VERSION=${PULL_REQUEST_VERSION} asd");
133+
.startsWith("asd ");
125134
}
126135

127136
@Test

0 commit comments

Comments
 (0)