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

Commit 2398c58

Browse files
committed
PREVIOUS_FROM_HASH and PREVIOUS_TO_HASH #220
1 parent 1cc9dc3 commit 2398c58

File tree

4 files changed

+70
-10
lines changed

4 files changed

+70
-10
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ The filter text as well as the URL support variables. These are:
9292
| `${PULL_REQUEST_FROM_SSH_CLONE_URL}` | Example: `ssh://git@localhost:7999/project_1/rep_1` |
9393
| `${PULL_REQUEST_FROM_HTTP_CLONE_URL}` | Example: `http://admin@localhost:7990/bitbucket/scm/project_1/rep_1.git` |
9494
| `${PULL_REQUEST_FROM_HASH}` | Example: `6053a1eaa1c009dd11092d09a72f3c41af1b59ad` |
95+
| `${PULL_REQUEST_PREVIOUS_FROM_HASH}` | Example: `6053a1eaa1c009dd11092d09a72f3c41af1b59ad` |
9596
| `${PULL_REQUEST_FROM_ID}` | Example: `refs/heads/branchmodmerge` |
9697
| `${PULL_REQUEST_FROM_BRANCH}` | Example: `branchmodmerge` |
9798
| `${PULL_REQUEST_FROM_REPO_ID}` | Example: `1` |
@@ -102,6 +103,7 @@ The filter text as well as the URL support variables. These are:
102103
| `${PULL_REQUEST_TO_SSH_CLONE_URL}` | Example: `ssh://git@localhost:7999/project_1/rep_1` |
103104
| `${PULL_REQUEST_TO_HTTP_CLONE_URL}` | Example: `http://admin@localhost:7990/bitbucket/scm/project_1/rep_1.git` |
104105
| `${PULL_REQUEST_TO_HASH}` | Example: `6053a1eaa1c009dd11092d09a72f3c41af1b59ad` |
106+
| `${PULL_REQUEST_PREVIOUS_TO_HASH}` | Example: `6053a1eaa1c009dd11092d09a72f3c41af1b59ad` |
105107
| `${PULL_REQUEST_TO_ID}` | Example: `refs/heads/branchmodmerge` |
106108
| `${PULL_REQUEST_TO_BRANCH}` | Example: `branchmodmerge` |
107109
| `${PULL_REQUEST_TO_REPO_ID}` | Example: `1` |

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

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
import java.util.Set;
2323
import java.util.regex.Matcher;
2424

25+
import se.bjurr.prnfb.http.ClientKeyStore;
26+
import se.bjurr.prnfb.http.HttpResponse;
27+
import se.bjurr.prnfb.http.Invoker;
28+
import se.bjurr.prnfb.http.UrlInvoker;
29+
import se.bjurr.prnfb.listener.PrnfbPullRequestAction;
30+
import se.bjurr.prnfb.service.PrnfbRenderer.ENCODE_FOR;
31+
import se.bjurr.prnfb.settings.PrnfbNotification;
32+
2533
import com.atlassian.bitbucket.permission.Permission;
2634
import com.atlassian.bitbucket.pull.PullRequest;
2735
import com.atlassian.bitbucket.pull.PullRequestParticipant;
@@ -38,14 +46,6 @@
3846
import com.google.common.base.Predicate;
3947
import com.google.common.base.Supplier;
4048

41-
import se.bjurr.prnfb.http.ClientKeyStore;
42-
import se.bjurr.prnfb.http.HttpResponse;
43-
import se.bjurr.prnfb.http.Invoker;
44-
import se.bjurr.prnfb.http.UrlInvoker;
45-
import se.bjurr.prnfb.listener.PrnfbPullRequestAction;
46-
import se.bjurr.prnfb.service.PrnfbRenderer.ENCODE_FOR;
47-
import se.bjurr.prnfb.settings.PrnfbNotification;
48-
4949
public enum PrnfbVariable {
5050
BUTTON_TRIGGER_TITLE(
5151
new PrnfbVariableResolver() {
@@ -339,6 +339,40 @@ public String resolve(
339339
return pullRequest.getFromRef().getLatestCommit();
340340
}
341341
}),
342+
PULL_REQUEST_PREVIOUS_FROM_HASH(
343+
new PrnfbVariableResolver() {
344+
@Override
345+
public String resolve(
346+
PullRequest pullRequest,
347+
PrnfbPullRequestAction prnfbPullRequestAction,
348+
ApplicationUser applicationUser,
349+
RepositoryService repositoryService,
350+
ApplicationPropertiesService propertiesService,
351+
PrnfbNotification prnfbNotification,
352+
Map<PrnfbVariable, Supplier<String>> variables,
353+
ClientKeyStore clientKeyStore,
354+
boolean shouldAcceptAnyCertificate,
355+
SecurityService securityService) {
356+
return getOrEmpty(variables, PULL_REQUEST_PREVIOUS_FROM_HASH);
357+
}
358+
}),
359+
PULL_REQUEST_PREVIOUS_TO_HASH(
360+
new PrnfbVariableResolver() {
361+
@Override
362+
public String resolve(
363+
PullRequest pullRequest,
364+
PrnfbPullRequestAction prnfbPullRequestAction,
365+
ApplicationUser applicationUser,
366+
RepositoryService repositoryService,
367+
ApplicationPropertiesService propertiesService,
368+
PrnfbNotification prnfbNotification,
369+
Map<PrnfbVariable, Supplier<String>> variables,
370+
ClientKeyStore clientKeyStore,
371+
boolean shouldAcceptAnyCertificate,
372+
SecurityService securityService) {
373+
return getOrEmpty(variables, PULL_REQUEST_PREVIOUS_TO_HASH);
374+
}
375+
}),
342376
PULL_REQUEST_FROM_HTTP_CLONE_URL(
343377
new PrnfbVariableResolver() {
344378
@Override

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,24 @@
66
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_COMMENT_ACTION;
77
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_COMMENT_TEXT;
88
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_MERGE_COMMIT;
9+
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_PREVIOUS_FROM_HASH;
10+
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_PREVIOUS_TO_HASH;
911
import static se.bjurr.prnfb.service.PrnfbVariable.PULL_REQUEST_USER_GROUPS;
1012

1113
import java.util.HashMap;
1214
import java.util.List;
1315
import java.util.Map;
1416

17+
import se.bjurr.prnfb.settings.PrnfbButton;
18+
1519
import com.atlassian.bitbucket.event.pull.PullRequestCommentEvent;
1620
import com.atlassian.bitbucket.event.pull.PullRequestEvent;
1721
import com.atlassian.bitbucket.event.pull.PullRequestMergedEvent;
22+
import com.atlassian.bitbucket.event.pull.PullRequestRescopedEvent;
1823
import com.google.common.base.Joiner;
1924
import com.google.common.base.Supplier;
2025
import com.google.common.base.Suppliers;
2126

22-
import se.bjurr.prnfb.settings.PrnfbButton;
23-
2427
/**
2528
* {@link PrnfbVariable} is becoming a bit messy with a lot of parameters to resolve different
2629
* variables. This is intended to replace all those parameters.
@@ -105,6 +108,25 @@ public Map<PrnfbVariable, Supplier<String>> getVariables() {
105108
() -> {
106109
return pullRequestCommentEvent.getCommentAction().name();
107110
});
111+
} else if (pullRequestEvent instanceof PullRequestRescopedEvent) {
112+
PullRequestRescopedEvent pullRequestRescopedEvent =
113+
(PullRequestRescopedEvent) pullRequestEvent;
114+
variables.put(
115+
PULL_REQUEST_PREVIOUS_FROM_HASH,
116+
() -> {
117+
if (pullRequestEvent instanceof PullRequestRescopedEvent) {
118+
return pullRequestRescopedEvent.getPreviousFromHash();
119+
}
120+
return "";
121+
});
122+
variables.put(
123+
PULL_REQUEST_PREVIOUS_TO_HASH,
124+
() -> {
125+
if (pullRequestEvent instanceof PullRequestRescopedEvent) {
126+
return pullRequestRescopedEvent.getPreviousToHash();
127+
}
128+
return "";
129+
});
108130
} else if (pullRequestEvent instanceof PullRequestMergedEvent) {
109131
variables.put(
110132
PULL_REQUEST_MERGE_COMMIT,

src/main/resources/admin.vm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
<li><b>${PULL_REQUEST_FROM_SSH_CLONE_URL}</b> Example: ssh://git@localhost:7999/project_1/rep_1</li>
106106
<li><b>${PULL_REQUEST_FROM_HTTP_CLONE_URL}</b> Example: http://admin@localhost:7990/bitbucket/scm/project_1/rep_1.git</li>
107107
<li><b>${PULL_REQUEST_FROM_HASH}</b> Example: 6053a1eaa1c009dd11092d09a72f3c41af1b59ad</li>
108+
<li><b>${PULL_REQUEST_PREVIOUS_FROM_HASH}</b> Example: 6053a1eaa1c009dd11092d09a72f3c41af1b59ad</li>
108109
<li><b>${PULL_REQUEST_FROM_ID}</b> Example: refs/heads/branch_mod_merge</li>
109110
<li><b>${PULL_REQUEST_FROM_BRANCH}</b> Example: branch_mod_merge</li>
110111
<li><b>${PULL_REQUEST_FROM_REPO_ID}</b> Example: 1</li>
@@ -115,6 +116,7 @@
115116
<li><b>${PULL_REQUEST_TO_SSH_CLONE_URL}</b> Example: ssh://git@localhost:7999/project_1/rep_1</li>
116117
<li><b>${PULL_REQUEST_TO_HTTP_CLONE_URL}</b> Example: http://admin@localhost:7990/bitbucket/scm/project_1/rep_1.git</li>
117118
<li><b>${PULL_REQUEST_TO_HASH}</b> Example: d6edcbf924697ab811a867421dab60d954ccad99</li>
119+
<li><b>${PULL_REQUEST_PREVIOUS_TO_HASH}</b> Example: d6edcbf924697ab811a867421dab60d954ccad99</li>
118120
<li><b>${PULL_REQUEST_TO_ID}</b> Example: refs/heads/basic_branching</li>
119121
<li><b>${PULL_REQUEST_TO_BRANCH}</b> Example: basic_branching</li>
120122
<li><b>${PULL_REQUEST_TO_REPO_ID}</b> Example: 1</li>

0 commit comments

Comments
 (0)