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

Commit

Permalink
Add new variable for storing a regex match on another variable value. #…
Browse files Browse the repository at this point in the history
  • Loading branch information
agentmerlin authored and tomasbjerre committed May 7, 2019
1 parent ab5e796 commit c8cb7b1
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 8 deletions.
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,45 @@

Changelog of Pull Request Notifier for Bitbucket.

## Unreleased
### GitHub [#1](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/issues/1) Finish GUI
Add link to bitbucket debug logging doc () ()

Bitbucket makes it easy to add debug logging for specific loggers once you know what to look for.

[c5eac08e7f6dd49](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/c5eac08e7f6dd49) Dave Neeley *2019-03-29 17:13:31*

### GitHub [#316](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/pull/316) Update README_jenkins.md
Update README_jenkins.md ()

[a66210fb34fbc46](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/a66210fb34fbc46) Anton Kazakov *2019-01-20 15:37:19*

### GitHub [#325](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/pull/325) Add link to bitbucket debug logging doc
Add link to bitbucket debug logging doc () ()

Bitbucket makes it easy to add debug logging for specific loggers once you know what to look for.

[c5eac08e7f6dd49](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/c5eac08e7f6dd49) Dave Neeley *2019-03-29 17:13:31*

### GitHub [#326](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/pull/326) Add Azure Pipelines documentation
Add Azure Pipelines documentation ()

[f6836b09b4d371b](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/f6836b09b4d371b) Dave Neeley *2019-03-29 21:17:29*

### GitHub [#327](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/pull/327) Update Azure Pipelines Sample to set branch of pull request
Update Azure Pipelines Sample to set branch of pull request ()

* Trigger builds on branches

* triggerInfo is returned by later api calls, properties are not

[ab5e796b5352e5e](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/ab5e796b5352e5e) Dave Neeley *2019-03-30 05:28:11*

### No issue
Updating build script

[6528d86c783c172](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/6528d86c783c172) Tomas Bjerre *2018-11-30 18:58:02*

## 3.24
### GitHub [#308](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/pull/308) Add optional Redirect URL to button configuration
Add optional Redirect URL to button configuration ()
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ The filter text as well as the URL support variables. These are:
| `${BUTTON_TRIGGER_TITLE}` | Example: `Trigger Notification` |
| `${BUTTON_FORM_DATA}` | The form data that was submitted |
| `${INJECTION_URL_VALUE}` | Value retrieved from any URL |
| `${VARIABLE_REGEX_MATCH}` | The result of custom regex applied to a variable |
| `${PULL_REQUEST_URL}` | Example: `http://localhost:7990/projects/PROJECT_1/repos/rep_1/pull-requests/1` |
| `${PULL_REQUEST_USER_DISPLAY_NAME}` | Example: `Some User` |
| `${PULL_REQUEST_USER_EMAIL_ADDRESS}` | Example: `[email protected]` |
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/se/bjurr/prnfb/presentation/dto/NotificationDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class NotificationDTO implements Comparable<NotificationDTO>, Restricted
private List<HeaderDTO> headers;
private String injectionUrl;
private String injectionUrlRegexp;
private String variableName;
private String variableRegex;
private HTTP_METHOD method;
private String name;
private String password;
Expand Down Expand Up @@ -104,6 +106,20 @@ public boolean equals(final Object obj) {
} else if (!injectionUrlRegexp.equals(other.injectionUrlRegexp)) {
return false;
}
if (variableName == null) {
if (other.variableName != null) {
return false;
}
} else if (!variableName.equals(other.variableName)) {
return false;
}
if (variableRegex == null) {
if (other.variableRegex != null) {
return false;
}
} else if (!variableRegex.equals(other.variableRegex)) {
return false;
}
if (method != other.method) {
return false;
}
Expand Down Expand Up @@ -244,6 +260,14 @@ public String getInjectionUrlRegexp() {
return this.injectionUrlRegexp;
}

public String getVariableName() {
return this.variableName;
}

public String getVariableRegex() {
return this.variableRegex;
}

public HTTP_METHOD getMethod() {
return this.method;
}
Expand Down Expand Up @@ -324,6 +348,8 @@ public int hashCode() {
result = prime * result + (httpVersion == null ? 0 : httpVersion.hashCode());
result = prime * result + (injectionUrl == null ? 0 : injectionUrl.hashCode());
result = prime * result + (injectionUrlRegexp == null ? 0 : injectionUrlRegexp.hashCode());
result = prime * result + (variableName == null ? 0 : variableName.hashCode());
result = prime * result + (variableRegex == null ? 0 : variableRegex.hashCode());
result = prime * result + (method == null ? 0 : method.hashCode());
result = prime * result + (name == null ? 0 : name.hashCode());
result = prime * result + (password == null ? 0 : password.hashCode());
Expand Down Expand Up @@ -367,6 +393,14 @@ public void setInjectionUrlRegexp(final String injectionUrlRegexp) {
this.injectionUrlRegexp = injectionUrlRegexp;
}

public void setVariableName(final String variableName) {
this.variableName = variableName;
}

public void setVariableRegex(final String variableRegex) {
this.variableRegex = variableRegex;
}

public void setMethod(final HTTP_METHOD method) {
this.method = method;
}
Expand Down Expand Up @@ -467,6 +501,10 @@ public String toString() {
+ injectionUrl
+ ", injectionUrlRegexp="
+ injectionUrlRegexp
+ ", variableName="
+ variableName
+ ", variableRegex="
+ variableRegex
+ ", method="
+ method
+ ", name="
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/se/bjurr/prnfb/service/PrnfbVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,56 @@ public String resolve(
return on('&').join(parts);
}
}),
VARIABLE_REGEX_MATCH(
new PrnfbVariableResolver() {
@Override
public String resolve(
final PullRequest pullRequest,
final PrnfbPullRequestAction pullRequestAction,
final ApplicationUser applicationUser,
final RepositoryService repositoryService,
final ApplicationPropertiesService propertiesService,
final PrnfbNotification prnfbNotification,
final Map<PrnfbVariable, Supplier<String>> variables,
final ClientKeyStore clientKeyStore,
final boolean shouldAcceptAnyCertificate,
final SecurityService securityService) {
if (prnfbNotification == null || !prnfbNotification.getVariableName().isPresent()) {
return "";
}
final String variableName = prnfbNotification.getVariableName().get();
String variableValue = "";
for (final PrnfbVariable v : PrnfbVariable.values()) {
if (v.name().equals(variableName) && v != VARIABLE_REGEX_MATCH) {
variableValue =
v.resolve(
pullRequest,
pullRequestAction,
applicationUser,
repositoryService,
propertiesService,
prnfbNotification,
variables,
clientKeyStore,
shouldAcceptAnyCertificate,
securityService);
}
}
if (prnfbNotification.getVariableRegex().isPresent()) {
final Matcher m =
compile(prnfbNotification.getVariableRegex().get()).matcher(variableValue);
if (!m.find()) {
return "";
}
if (m.groupCount() == 0) {
return m.group();
}
return m.group(1);
} else {
return variableValue;
}
}
}),
INJECTION_URL_VALUE(
new PrnfbVariableResolver() {
@Override
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/se/bjurr/prnfb/settings/PrnfbNotification.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class PrnfbNotification implements HasUuid, Restricted {
private final List<PrnfbHeader> headers;
private final String injectionUrl;
private final String injectionUrlRegexp;
private final String variableName;
private final String variableRegex;
private final HTTP_METHOD method;
private final String name;
private final String password;
Expand Down Expand Up @@ -93,6 +95,8 @@ public PrnfbNotification(final PrnfbNotificationBuilder builder) throws Validati
this.name = firstNonNull(emptyToNull(nullToEmpty(builder.getName()).trim()), DEFAULT_NAME);
this.injectionUrl = emptyToNull(nullToEmpty(builder.getInjectionUrl()).trim());
this.injectionUrlRegexp = emptyToNull(nullToEmpty(builder.getInjectionUrlRegexp()).trim());
this.variableName = emptyToNull(nullToEmpty(builder.getVariableName()).trim());
this.variableRegex = emptyToNull(nullToEmpty(builder.getVariableRegex()).trim());
this.triggerIgnoreStateList = builder.getTriggerIgnoreStateList();
this.postContentEncoding = firstNonNull(builder.getPostContentEncoding(), NONE);
this.httpVersion = builder.getHttpVersion();
Expand Down Expand Up @@ -152,6 +156,20 @@ public boolean equals(final Object obj) {
} else if (!injectionUrlRegexp.equals(other.injectionUrlRegexp)) {
return false;
}
if (variableName == null) {
if (other.variableName != null) {
return false;
}
} else if (!variableName.equals(other.variableName)) {
return false;
}
if (variableRegex == null) {
if (other.variableRegex != null) {
return false;
}
} else if (!variableRegex.equals(other.variableRegex)) {
return false;
}
if (method != other.method) {
return false;
}
Expand Down Expand Up @@ -292,6 +310,14 @@ public Optional<String> getInjectionUrlRegexp() {
return fromNullable(this.injectionUrlRegexp);
}

public Optional<String> getVariableName() {
return fromNullable(this.variableName);
}

public Optional<String> getVariableRegex() {
return fromNullable(this.variableRegex);
}

public HTTP_METHOD getMethod() {
return this.method;
}
Expand Down Expand Up @@ -377,6 +403,8 @@ public int hashCode() {
result = prime * result + (httpVersion == null ? 0 : httpVersion.hashCode());
result = prime * result + (injectionUrl == null ? 0 : injectionUrl.hashCode());
result = prime * result + (injectionUrlRegexp == null ? 0 : injectionUrlRegexp.hashCode());
result = prime * result + (variableName == null ? 0 : variableName.hashCode());
result = prime * result + (variableRegex == null ? 0 : variableRegex.hashCode());
result = prime * result + (method == null ? 0 : method.hashCode());
result = prime * result + (name == null ? 0 : name.hashCode());
result = prime * result + (password == null ? 0 : password.hashCode());
Expand Down Expand Up @@ -412,6 +440,10 @@ public String toString() {
+ injectionUrl
+ ", injectionUrlRegexp="
+ injectionUrlRegexp
+ ", variableName="
+ variableName
+ ", variableRegex="
+ variableRegex
+ ", method="
+ method
+ ", name="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public PrnfbNotificationBuilder(
final List<PrnfbHeader> headers,
final String injectionUrl,
final String injectionUrlRegexp,
final String variableName,
final String variableRegex,
final HTTP_METHOD method,
final String name,
final String password,
Expand All @@ -49,6 +51,8 @@ public PrnfbNotificationBuilder(
this.headers = headers;
this.injectionUrl = injectionUrl;
this.injectionUrlRegexp = injectionUrlRegexp;
this.variableName = variableName;
this.variableRegex = variableRegex;
this.method = method;
this.name = name;
this.password = password;
Expand Down Expand Up @@ -96,6 +100,8 @@ public static PrnfbNotificationBuilder prnfbNotificationBuilder(final PrnfbNotif
b.name = from.getName();
b.injectionUrl = from.getInjectionUrl().orNull();
b.injectionUrlRegexp = from.getInjectionUrlRegexp().orNull();
b.variableName = from.getVariableName().orNull();
b.variableRegex = from.getVariableRegex().orNull();
b.triggerIfCanMerge = from.getTriggerIfCanMerge();
b.postContentEncoding = from.getPostContentEncoding();
b.httpVersion = from.getHttpVersion();
Expand All @@ -107,6 +113,8 @@ public static PrnfbNotificationBuilder prnfbNotificationBuilder(final PrnfbNotif
private List<PrnfbHeader> headers = newArrayList();
private String injectionUrl;
private String injectionUrlRegexp;
private String variableName;
private String variableRegex;
private HTTP_METHOD method;
private String name;
private String password;
Expand Down Expand Up @@ -160,6 +168,14 @@ public String getInjectionUrlRegexp() {
return this.injectionUrlRegexp;
}

public String getVariableName() {
return this.variableName;
}

public String getVariableRegex() {
return this.variableRegex;
}

public HTTP_METHOD getMethod() {
return this.method;
}
Expand Down Expand Up @@ -282,6 +298,16 @@ public PrnfbNotificationBuilder withInjectionUrlRegexp(final String injectionUrl
return this;
}

public PrnfbNotificationBuilder withVariableName(final String variableName) {
this.variableName = emptyToNull(variableName);
return this;
}

public PrnfbNotificationBuilder withVariableRegex(final String variableRegex) {
this.variableRegex = emptyToNull(variableRegex);
return this;
}

public PrnfbNotificationBuilder withMethod(final HTTP_METHOD method) {
this.method = firstNonNull(method, GET);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public static NotificationDTO toNotificationDto(final PrnfbNotification from) {
to.setFilterString(from.getFilterString().orNull());
to.setInjectionUrl(from.getInjectionUrl().orNull());
to.setInjectionUrlRegexp(from.getInjectionUrlRegexp().orNull());
to.setVariableName(from.getVariableName().orNull());
to.setVariableRegex(from.getVariableRegex().orNull());
to.setMethod(from.getMethod());
to.setName(from.getName());
to.setHeaders(toHeaders(from.getHeaders()));
Expand Down Expand Up @@ -65,6 +67,8 @@ public static PrnfbNotification toPrnfbNotification(final NotificationDTO from)
.setHeaders(toHeaders(from)) //
.withInjectionUrl(from.getInjectionUrl()) //
.withInjectionUrlRegexp(from.getInjectionUrlRegexp()) //
.withVariableName(from.getVariableName()) //
.withVariableRegex(from.getVariableRegex()) //
.withMethod(from.getMethod()) //
.withName(from.getName()) //
.withPassword(from.getPassword()) //
Expand Down
16 changes: 16 additions & 0 deletions src/main/resources/admin.vm
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
<li><b>${BUTTON_TRIGGER_TITLE}</b> Example: Trigger Notification</li>
<li><b>${BUTTON_FORM_DATA}</b> The form data that was submitted</li>
<li><b>${INJECTION_URL_VALUE}</b> If injection URL configured</li>
<li><b>${VARIABLE_REGEX_MATCH}</b> If variable regex is configured</li>
<li><b>${PULL_REQUEST_USER_DISPLAY_NAME}</b> Example: Some User</li>
<li><b>${PULL_REQUEST_USER_EMAIL_ADDRESS}</b> Example: [email protected]</li>
<li><b>${PULL_REQUEST_USER_ID}</b> Example: 1</li>
Expand Down Expand Up @@ -497,6 +498,21 @@
</div>
</fieldset>

<h4>Variable Regex Match</h4>
<p>Apply custom regex to a variable. Uses first capture group if one is provided.</p>
<fieldset class="group">
<div class="field-group">
<label>Variable Name </label>
<input class="text long-field" type="text" name="variableName">
<div class="description"></div>
</div>
<div class="field-group">
<label>Variable Regex </label>
<input class="text long-field" type="text" name="variableRegex">
<div class="description">Regular expression to match against the variable value.</div>
</div>
</fieldset>

<h4>Basic authentication</h4>
<p>Optional basic authentication details.</p>
<fieldset class="group">
Expand Down
Loading

0 comments on commit c8cb7b1

Please sign in to comment.