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

Commit

Permalink
New variables to list approved, unapproved and needs work #192
Browse files Browse the repository at this point in the history
 * 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
  • Loading branch information
tomasbjerre committed Feb 1, 2017
1 parent 020dfc3 commit 6b8832e
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 7 deletions.
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,22 @@ Changelog of Pull Request Notifier for Bitbucket.

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

[f0755ff21dc7ae2](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/f0755ff21dc7ae2) Tomas Bjerre *2017-02-01 18:16:39*
[020dfc3bb372ca2](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/020dfc3bb372ca2) Tomas Bjerre *2017-02-01 18:17:48*

### GitHub [#192](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/192) Include status for participants
New variables to list approved, unapproved and needs work

* 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

[72607d4617b0e7d](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/72607d4617b0e7d) Tomas Bjerre *2017-02-01 19:16:26*

### No issue
doc
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,17 @@ The filter text as well as the URL support variables. These are:
| `${PULL_REQUEST_REVIEWERS_SLUG}` | Example: `admin,user` |
| `${PULL_REQUEST_REVIEWERS_EMAIL}` | Example: `[email protected],[email protected]` |
| `${PULL_REQUEST_REVIEWERS_APPROVED_COUNT}` | Number of reviewers that approved the PR. |
| `${PULL_REQUEST_REVIEWERS_APPROVED_SLUG}` | Example: admin,user. |
| `${PULL_REQUEST_REVIEWERS_APPROVED_EMAIL}` | Example: [email protected],[email protected]. |
| `${PULL_REQUEST_REVIEWERS_APPROVED_NAME}` | Example: Admin,User. |
| `${PULL_REQUEST_REVIEWERS_UNAPPROVED_COUNT}` | Number of reviewers that unapproved the PR. |
| `${PULL_REQUEST_REVIEWERS_UNAPPROVED_SLUG}` | Example: admin,user. |
| `${PULL_REQUEST_REVIEWERS_UNAPPROVED_EMAIL}` | Example: [email protected],[email protected]. |
| `${PULL_REQUEST_REVIEWERS_UNAPPROVED_NAME}` | Example: Admin,User. |
| `${PULL_REQUEST_REVIEWERS_NEEDS_WORK_COUNT}` | Number of reviewers that says the PR needs work. |
| `${PULL_REQUEST_REVIEWERS_NEEDS_WORK_SLUG}` | Example: admin,user. |
| `${PULL_REQUEST_REVIEWERS_NEEDS_WORK_EMAIL}` | Example: [email protected],[email protected]. |
| `${PULL_REQUEST_REVIEWERS_NEEDS_WORK_NAME}` | Example: Admin,User. |
| `${PULL_REQUEST_PARTICIPANTS_APPROVED_COUNT}` | Number of participants that approved the PR. |
| `${PULL_REQUEST_PARTICIPANTS_EMAIL}` | Example: `[email protected],[email protected]` |
| `${PULL_REQUEST_MERGE_COMMIT}` | Hash of merged commit (only available for merged-event). |
Expand Down
172 changes: 172 additions & 0 deletions src/main/java/se/bjurr/prnfb/service/PrnfbVariable.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package se.bjurr.prnfb.service;

import static com.atlassian.bitbucket.pull.PullRequestParticipantStatus.APPROVED;
import static com.atlassian.bitbucket.pull.PullRequestParticipantStatus.NEEDS_WORK;
import static com.atlassian.bitbucket.pull.PullRequestParticipantStatus.UNAPPROVED;
import static com.google.common.base.Joiner.on;
Expand Down Expand Up @@ -582,6 +583,177 @@ public String resolve(
transform(pullRequest.getReviewers(), (p) -> p.getUser().getEmailAddress()));
}
}),
PULL_REQUEST_REVIEWERS_NEEDS_WORK_SLUG(
new PrnfbVariableResolver() {
@Override
public String resolve(
PullRequest pullRequest,
PrnfbPullRequestAction pullRequestAction,
ApplicationUser applicationUser,
RepositoryService repositoryService,
ApplicationPropertiesService propertiesService,
PrnfbNotification prnfbNotification,
Map<PrnfbVariable, Supplier<String>> variables,
ClientKeyStore clientKeyStore,
boolean shouldAcceptAnyCertificate,
SecurityService securityService) {
Iterable<PullRequestParticipant> reviewers =
filter(pullRequest.getReviewers(), (r) -> r.getStatus() == NEEDS_WORK);
return iterableToString(transform(reviewers, (p) -> p.getUser().getSlug()));
}
}),
PULL_REQUEST_REVIEWERS_NEEDS_WORK_EMAIL(
new PrnfbVariableResolver() {
@Override
public String resolve(
PullRequest pullRequest,
PrnfbPullRequestAction pullRequestAction,
ApplicationUser applicationUser,
RepositoryService repositoryService,
ApplicationPropertiesService propertiesService,
PrnfbNotification prnfbNotification,
Map<PrnfbVariable, Supplier<String>> variables,
ClientKeyStore clientKeyStore,
boolean shouldAcceptAnyCertificate,
SecurityService securityService) {
Iterable<PullRequestParticipant> reviewers =
filter(pullRequest.getReviewers(), (r) -> r.getStatus() == NEEDS_WORK);
return iterableToString(transform(reviewers, (p) -> p.getUser().getEmailAddress()));
}
}),
PULL_REQUEST_REVIEWERS_NEEDS_WORK_NAME(
new PrnfbVariableResolver() {
@Override
public String resolve(
PullRequest pullRequest,
PrnfbPullRequestAction pullRequestAction,
ApplicationUser applicationUser,
RepositoryService repositoryService,
ApplicationPropertiesService propertiesService,
PrnfbNotification prnfbNotification,
Map<PrnfbVariable, Supplier<String>> variables,
ClientKeyStore clientKeyStore,
boolean shouldAcceptAnyCertificate,
SecurityService securityService) {
Iterable<PullRequestParticipant> reviewers =
filter(pullRequest.getReviewers(), (r) -> r.getStatus() == NEEDS_WORK);
return iterableToString(transform(reviewers, (p) -> p.getUser().getName()));
}
}),
PULL_REQUEST_REVIEWERS_UNAPPROVED_SLUG(
new PrnfbVariableResolver() {
@Override
public String resolve(
PullRequest pullRequest,
PrnfbPullRequestAction pullRequestAction,
ApplicationUser applicationUser,
RepositoryService repositoryService,
ApplicationPropertiesService propertiesService,
PrnfbNotification prnfbNotification,
Map<PrnfbVariable, Supplier<String>> variables,
ClientKeyStore clientKeyStore,
boolean shouldAcceptAnyCertificate,
SecurityService securityService) {
Iterable<PullRequestParticipant> reviewers =
filter(pullRequest.getReviewers(), (r) -> r.getStatus() == UNAPPROVED);
return iterableToString(transform(reviewers, (p) -> p.getUser().getSlug()));
}
}),
PULL_REQUEST_REVIEWERS_UNAPPROVED_EMAIL(
new PrnfbVariableResolver() {
@Override
public String resolve(
PullRequest pullRequest,
PrnfbPullRequestAction pullRequestAction,
ApplicationUser applicationUser,
RepositoryService repositoryService,
ApplicationPropertiesService propertiesService,
PrnfbNotification prnfbNotification,
Map<PrnfbVariable, Supplier<String>> variables,
ClientKeyStore clientKeyStore,
boolean shouldAcceptAnyCertificate,
SecurityService securityService) {
Iterable<PullRequestParticipant> reviewers =
filter(pullRequest.getReviewers(), (r) -> r.getStatus() == UNAPPROVED);
return iterableToString(transform(reviewers, (p) -> p.getUser().getEmailAddress()));
}
}),
PULL_REQUEST_REVIEWERS_UNAPPROVED_NAME(
new PrnfbVariableResolver() {
@Override
public String resolve(
PullRequest pullRequest,
PrnfbPullRequestAction pullRequestAction,
ApplicationUser applicationUser,
RepositoryService repositoryService,
ApplicationPropertiesService propertiesService,
PrnfbNotification prnfbNotification,
Map<PrnfbVariable, Supplier<String>> variables,
ClientKeyStore clientKeyStore,
boolean shouldAcceptAnyCertificate,
SecurityService securityService) {
Iterable<PullRequestParticipant> reviewers =
filter(pullRequest.getReviewers(), (r) -> r.getStatus() == UNAPPROVED);
return iterableToString(transform(reviewers, (p) -> p.getUser().getName()));
}
}),
PULL_REQUEST_REVIEWERS_APPROVED_SLUG(
new PrnfbVariableResolver() {
@Override
public String resolve(
PullRequest pullRequest,
PrnfbPullRequestAction pullRequestAction,
ApplicationUser applicationUser,
RepositoryService repositoryService,
ApplicationPropertiesService propertiesService,
PrnfbNotification prnfbNotification,
Map<PrnfbVariable, Supplier<String>> variables,
ClientKeyStore clientKeyStore,
boolean shouldAcceptAnyCertificate,
SecurityService securityService) {
Iterable<PullRequestParticipant> reviewers =
filter(pullRequest.getReviewers(), (r) -> r.getStatus() == APPROVED);
return iterableToString(transform(reviewers, (p) -> p.getUser().getSlug()));
}
}),
PULL_REQUEST_REVIEWERS_APPROVED_EMAIL(
new PrnfbVariableResolver() {
@Override
public String resolve(
PullRequest pullRequest,
PrnfbPullRequestAction pullRequestAction,
ApplicationUser applicationUser,
RepositoryService repositoryService,
ApplicationPropertiesService propertiesService,
PrnfbNotification prnfbNotification,
Map<PrnfbVariable, Supplier<String>> variables,
ClientKeyStore clientKeyStore,
boolean shouldAcceptAnyCertificate,
SecurityService securityService) {
Iterable<PullRequestParticipant> reviewers =
filter(pullRequest.getReviewers(), (r) -> r.getStatus() == APPROVED);
return iterableToString(transform(reviewers, (p) -> p.getUser().getEmailAddress()));
}
}),
PULL_REQUEST_REVIEWERS_APPROVED_NAME(
new PrnfbVariableResolver() {
@Override
public String resolve(
PullRequest pullRequest,
PrnfbPullRequestAction pullRequestAction,
ApplicationUser applicationUser,
RepositoryService repositoryService,
ApplicationPropertiesService propertiesService,
PrnfbNotification prnfbNotification,
Map<PrnfbVariable, Supplier<String>> variables,
ClientKeyStore clientKeyStore,
boolean shouldAcceptAnyCertificate,
SecurityService securityService) {
Iterable<PullRequestParticipant> reviewers =
filter(pullRequest.getReviewers(), (r) -> r.getStatus() == APPROVED);
return iterableToString(transform(reviewers, (p) -> p.getUser().getName()));
}
}),
PULL_REQUEST_REVIEWERS_ID(
new PrnfbVariableResolver() {
@Override
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/admin.vm
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,17 @@
<li><b>${PULL_REQUEST_REVIEWERS_SLUG}</b> Reviewers slug list.</li>
<li><b>${PULL_REQUEST_REVIEWERS_EMAIL}</b> Example: [email protected],[email protected].</li>
<li><b>${PULL_REQUEST_REVIEWERS_APPROVED_COUNT}</b> Number of reviewers that approved the PR.</li>
<li><b>${PULL_REQUEST_REVIEWERS_APPROVED_SLUG}</b> Example: admin,user.</li>
<li><b>${PULL_REQUEST_REVIEWERS_APPROVED_EMAIL}</b> Example: [email protected],[email protected].</li>
<li><b>${PULL_REQUEST_REVIEWERS_APPROVED_NAME}</b> Example: Admin,User.</li>
<li><b>${PULL_REQUEST_REVIEWERS_UNAPPROVED_COUNT}</b> Number of reviewers that unapproved the PR.</li>
<li><b>${PULL_REQUEST_REVIEWERS_UNAPPROVED_SLUG}</b> Example: admin,user.</li>
<li><b>${PULL_REQUEST_REVIEWERS_UNAPPROVED_EMAIL}</b> Example: [email protected],[email protected].</li>
<li><b>${PULL_REQUEST_REVIEWERS_UNAPPROVED_NAME}</b> Example: Admin,User.</li>
<li><b>${PULL_REQUEST_REVIEWERS_NEEDS_WORK_COUNT}</b> Number of reviewers that says the PR needs work.</li>
<li><b>${PULL_REQUEST_REVIEWERS_NEEDS_WORK_SLUG}</b> Example: admin,user.</li>
<li><b>${PULL_REQUEST_REVIEWERS_NEEDS_WORK_EMAIL}</b> Example: [email protected],[email protected].</li>
<li><b>${PULL_REQUEST_REVIEWERS_NEEDS_WORK_NAME}</b> Example: Admin,User.</li>
<li><b>${PULL_REQUEST_PARTICIPANTS_APPROVED_COUNT}</b> Number of participants that approved the PR.</li>
<li><b>${PULL_REQUEST_PARTICIPANTS_EMAIL}</b> Example: [email protected],[email protected].</li>
<li><b>${PULL_REQUEST_MERGE_COMMIT}</b> Hash of merged commit (only available for merged-event).</li>
Expand Down
13 changes: 11 additions & 2 deletions src/test/java/se/bjurr/prnfb/service/PrnfbRendererTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static se.bjurr.prnfb.service.PrnfbVariable.INJECTION_URL_VALUE;
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_AUTHOR_EMAIL;
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_COMMENT_TEXT;
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_DESCRIPTION;
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_FROM_HASH;
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_MERGE_COMMIT;
import static se.bjurr.prnfb.settings.PrnfbNotificationBuilder.prnfbNotificationBuilder;
Expand Down Expand Up @@ -119,9 +120,17 @@ public void testThatEverythingCanBeRendered() throws UnsupportedEncodingExceptio
shouldAcceptAnyCertificate,
securityService));

for (PrnfbVariable v : PrnfbVariable.values()) {
if (v != EVERYTHING_URL && v != PULL_REQUEST_DESCRIPTION) {
assertThat(actual) //
.containsOnlyOnce(v.name() + "=${" + v.name() + "}") //
.doesNotContain(EVERYTHING_URL.name()) //
.doesNotContain(PULL_REQUEST_DESCRIPTION.name());
}
}

assertThat(actual) //
.isEqualTo(
"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");
.startsWith("asd ");
}

@Test
Expand Down
Loading

0 comments on commit 6b8832e

Please sign in to comment.