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

Commit

Permalink
PREVIOUS_FROM_HASH and PREVIOUS_TO_HASH #220
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Jun 2, 2017
1 parent 835b214 commit 085e095
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 11 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
Changelog of Pull Request Notifier for Bitbucket.

## Unreleased
### GitHub [#220](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/220) Feature: add PREVIOUS_FROM_HASH and PREVIOUS_TO_HASH to variables
PREVIOUS_FROM_HASH and PREVIOUS_TO_HASH

[92e8643f55178fe](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/92e8643f55178fe) Tomas Bjerre *2017-06-02 07:09:48*

### GitHub [#221](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/221) "You are not permitted to access this resource" after upgrade from Stash(v3) to Bitbucket(v4)
Checking if canMerge with escalated (ADMIN) permission

[465d0fb7befdbb8](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/465d0fb7befdbb8) Tomas Bjerre *2017-06-02 06:43:34*
[835b214f1b6d59c](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/835b214f1b6d59c) Tomas Bjerre *2017-06-02 06:45:05*

### No issue
Avoiding error in Eclipse
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ The filter text as well as the URL support variables. These are:
| `${PULL_REQUEST_FROM_SSH_CLONE_URL}` | Example: `ssh://git@localhost:7999/project_1/rep_1` |
| `${PULL_REQUEST_FROM_HTTP_CLONE_URL}` | Example: `http://admin@localhost:7990/bitbucket/scm/project_1/rep_1.git` |
| `${PULL_REQUEST_FROM_HASH}` | Example: `6053a1eaa1c009dd11092d09a72f3c41af1b59ad` |
| `${PULL_REQUEST_PREVIOUS_FROM_HASH}` | Example: `6053a1eaa1c009dd11092d09a72f3c41af1b59ad` |
| `${PULL_REQUEST_FROM_ID}` | Example: `refs/heads/branchmodmerge` |
| `${PULL_REQUEST_FROM_BRANCH}` | Example: `branchmodmerge` |
| `${PULL_REQUEST_FROM_REPO_ID}` | Example: `1` |
Expand All @@ -102,6 +103,7 @@ The filter text as well as the URL support variables. These are:
| `${PULL_REQUEST_TO_SSH_CLONE_URL}` | Example: `ssh://git@localhost:7999/project_1/rep_1` |
| `${PULL_REQUEST_TO_HTTP_CLONE_URL}` | Example: `http://admin@localhost:7990/bitbucket/scm/project_1/rep_1.git` |
| `${PULL_REQUEST_TO_HASH}` | Example: `6053a1eaa1c009dd11092d09a72f3c41af1b59ad` |
| `${PULL_REQUEST_PREVIOUS_TO_HASH}` | Example: `6053a1eaa1c009dd11092d09a72f3c41af1b59ad` |
| `${PULL_REQUEST_TO_ID}` | Example: `refs/heads/branchmodmerge` |
| `${PULL_REQUEST_TO_BRANCH}` | Example: `branchmodmerge` |
| `${PULL_REQUEST_TO_REPO_ID}` | Example: `1` |
Expand Down
50 changes: 42 additions & 8 deletions src/main/java/se/bjurr/prnfb/service/PrnfbVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
import java.util.Set;
import java.util.regex.Matcher;

import se.bjurr.prnfb.http.ClientKeyStore;
import se.bjurr.prnfb.http.HttpResponse;
import se.bjurr.prnfb.http.Invoker;
import se.bjurr.prnfb.http.UrlInvoker;
import se.bjurr.prnfb.listener.PrnfbPullRequestAction;
import se.bjurr.prnfb.service.PrnfbRenderer.ENCODE_FOR;
import se.bjurr.prnfb.settings.PrnfbNotification;

import com.atlassian.bitbucket.permission.Permission;
import com.atlassian.bitbucket.pull.PullRequest;
import com.atlassian.bitbucket.pull.PullRequestParticipant;
Expand All @@ -38,14 +46,6 @@
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;

import se.bjurr.prnfb.http.ClientKeyStore;
import se.bjurr.prnfb.http.HttpResponse;
import se.bjurr.prnfb.http.Invoker;
import se.bjurr.prnfb.http.UrlInvoker;
import se.bjurr.prnfb.listener.PrnfbPullRequestAction;
import se.bjurr.prnfb.service.PrnfbRenderer.ENCODE_FOR;
import se.bjurr.prnfb.settings.PrnfbNotification;

public enum PrnfbVariable {
BUTTON_TRIGGER_TITLE(
new PrnfbVariableResolver() {
Expand Down Expand Up @@ -339,6 +339,40 @@ public String resolve(
return pullRequest.getFromRef().getLatestCommit();
}
}),
PULL_REQUEST_PREVIOUS_FROM_HASH(
new PrnfbVariableResolver() {
@Override
public String resolve(
PullRequest pullRequest,
PrnfbPullRequestAction prnfbPullRequestAction,
ApplicationUser applicationUser,
RepositoryService repositoryService,
ApplicationPropertiesService propertiesService,
PrnfbNotification prnfbNotification,
Map<PrnfbVariable, Supplier<String>> variables,
ClientKeyStore clientKeyStore,
boolean shouldAcceptAnyCertificate,
SecurityService securityService) {
return getOrEmpty(variables, PULL_REQUEST_PREVIOUS_FROM_HASH);
}
}),
PULL_REQUEST_PREVIOUS_TO_HASH(
new PrnfbVariableResolver() {
@Override
public String resolve(
PullRequest pullRequest,
PrnfbPullRequestAction prnfbPullRequestAction,
ApplicationUser applicationUser,
RepositoryService repositoryService,
ApplicationPropertiesService propertiesService,
PrnfbNotification prnfbNotification,
Map<PrnfbVariable, Supplier<String>> variables,
ClientKeyStore clientKeyStore,
boolean shouldAcceptAnyCertificate,
SecurityService securityService) {
return getOrEmpty(variables, PULL_REQUEST_PREVIOUS_TO_HASH);
}
}),
PULL_REQUEST_FROM_HTTP_CLONE_URL(
new PrnfbVariableResolver() {
@Override
Expand Down
26 changes: 24 additions & 2 deletions src/main/java/se/bjurr/prnfb/service/VariablesContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_COMMENT_ACTION;
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_COMMENT_TEXT;
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_MERGE_COMMIT;
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_PREVIOUS_FROM_HASH;
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_PREVIOUS_TO_HASH;
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_USER_GROUPS;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import se.bjurr.prnfb.settings.PrnfbButton;

import com.atlassian.bitbucket.event.pull.PullRequestCommentEvent;
import com.atlassian.bitbucket.event.pull.PullRequestEvent;
import com.atlassian.bitbucket.event.pull.PullRequestMergedEvent;
import com.atlassian.bitbucket.event.pull.PullRequestRescopedEvent;
import com.google.common.base.Joiner;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;

import se.bjurr.prnfb.settings.PrnfbButton;

/**
* {@link PrnfbVariable} is becoming a bit messy with a lot of parameters to resolve different
* variables. This is intended to replace all those parameters.
Expand Down Expand Up @@ -105,6 +108,25 @@ public Map<PrnfbVariable, Supplier<String>> getVariables() {
() -> {
return pullRequestCommentEvent.getCommentAction().name();
});
} else if (pullRequestEvent instanceof PullRequestRescopedEvent) {
PullRequestRescopedEvent pullRequestRescopedEvent =
(PullRequestRescopedEvent) pullRequestEvent;
variables.put(
PULL_REQUEST_PREVIOUS_FROM_HASH,
() -> {
if (pullRequestEvent instanceof PullRequestRescopedEvent) {
return pullRequestRescopedEvent.getPreviousFromHash();
}
return "";
});
variables.put(
PULL_REQUEST_PREVIOUS_TO_HASH,
() -> {
if (pullRequestEvent instanceof PullRequestRescopedEvent) {
return pullRequestRescopedEvent.getPreviousToHash();
}
return "";
});
} else if (pullRequestEvent instanceof PullRequestMergedEvent) {
variables.put(
PULL_REQUEST_MERGE_COMMIT,
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/admin.vm
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<li><b>${PULL_REQUEST_FROM_SSH_CLONE_URL}</b> Example: ssh://git@localhost:7999/project_1/rep_1</li>
<li><b>${PULL_REQUEST_FROM_HTTP_CLONE_URL}</b> Example: http://admin@localhost:7990/bitbucket/scm/project_1/rep_1.git</li>
<li><b>${PULL_REQUEST_FROM_HASH}</b> Example: 6053a1eaa1c009dd11092d09a72f3c41af1b59ad</li>
<li><b>${PULL_REQUEST_PREVIOUS_FROM_HASH}</b> Example: 6053a1eaa1c009dd11092d09a72f3c41af1b59ad</li>
<li><b>${PULL_REQUEST_FROM_ID}</b> Example: refs/heads/branch_mod_merge</li>
<li><b>${PULL_REQUEST_FROM_BRANCH}</b> Example: branch_mod_merge</li>
<li><b>${PULL_REQUEST_FROM_REPO_ID}</b> Example: 1</li>
Expand All @@ -115,6 +116,7 @@
<li><b>${PULL_REQUEST_TO_SSH_CLONE_URL}</b> Example: ssh://git@localhost:7999/project_1/rep_1</li>
<li><b>${PULL_REQUEST_TO_HTTP_CLONE_URL}</b> Example: http://admin@localhost:7990/bitbucket/scm/project_1/rep_1.git</li>
<li><b>${PULL_REQUEST_TO_HASH}</b> Example: d6edcbf924697ab811a867421dab60d954ccad99</li>
<li><b>${PULL_REQUEST_PREVIOUS_TO_HASH}</b> Example: d6edcbf924697ab811a867421dab60d954ccad99</li>
<li><b>${PULL_REQUEST_TO_ID}</b> Example: refs/heads/basic_branching</li>
<li><b>${PULL_REQUEST_TO_BRANCH}</b> Example: basic_branching</li>
<li><b>${PULL_REQUEST_TO_REPO_ID}</b> Example: 1</li>
Expand Down

0 comments on commit 085e095

Please sign in to comment.