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

Commit

Permalink
Adding project and repo filter to notification #25
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed May 3, 2016
1 parent 3e1fdda commit 1fc12a7
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ public boolean isNotificationTriggeredByAction(PrnfbNotification notification,
if (!notification.getTriggers().contains(pullRequestAction)) {
return FALSE;
}

if (notification.getProjectKey().isPresent()) {
if (!notification.getProjectKey().get().equals(pullRequest.getToRef().getRepository().getProject().getKey())) {
return FALSE;
}
}

if (notification.getRepositorySlug().isPresent()) {
if (!notification.getRepositorySlug().get().equals(pullRequest.getToRef().getRepository().getSlug())) {
return FALSE;
}
}

if (notification.getFilterRegexp().isPresent()
&& notification.getFilterString().isPresent()
&& !compile(notification.getFilterRegexp().get()).matcher(
Expand Down
46 changes: 40 additions & 6 deletions src/main/java/se/bjurr/prnfb/presentation/dto/NotificationDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
@XmlRootElement
@XmlAccessorType(FIELD)
public class NotificationDTO {

private String filterRegexp;
private String filterString;
private List<HeaderDTO> headers;
Expand All @@ -27,10 +26,12 @@ public class NotificationDTO {
private String name;
private String password;
private String postContent;
private String projectKey;
private String proxyPassword;
private Integer proxyPort;
private String proxyServer;
private String proxyUser;
private String repositorySlug;
private TRIGGER_IF_MERGE triggerIfCanMerge;
private List<PullRequestState> triggerIgnoreStateList;
private List<PrnfbPullRequestAction> triggers;
Expand Down Expand Up @@ -109,6 +110,13 @@ public boolean equals(Object obj) {
} else if (!this.postContent.equals(other.postContent)) {
return false;
}
if (this.projectKey == null) {
if (other.projectKey != null) {
return false;
}
} else if (!this.projectKey.equals(other.projectKey)) {
return false;
}
if (this.proxyPassword == null) {
if (other.proxyPassword != null) {
return false;
Expand Down Expand Up @@ -137,6 +145,13 @@ public boolean equals(Object obj) {
} else if (!this.proxyUser.equals(other.proxyUser)) {
return false;
}
if (this.repositorySlug == null) {
if (other.repositorySlug != null) {
return false;
}
} else if (!this.repositorySlug.equals(other.repositorySlug)) {
return false;
}
if (this.triggerIfCanMerge != other.triggerIfCanMerge) {
return false;
}
Expand Down Expand Up @@ -214,6 +229,10 @@ public String getPostContent() {
return this.postContent;
}

public String getProjectKey() {
return this.projectKey;
}

public String getProxyPassword() {
return this.proxyPassword;
}
Expand All @@ -230,6 +249,10 @@ public String getProxyUser() {
return this.proxyUser;
}

public String getRepositorySlug() {
return this.repositorySlug;
}

public TRIGGER_IF_MERGE getTriggerIfCanMerge() {
return this.triggerIfCanMerge;
}
Expand Down Expand Up @@ -267,10 +290,12 @@ public int hashCode() {
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
result = prime * result + ((this.password == null) ? 0 : this.password.hashCode());
result = prime * result + ((this.postContent == null) ? 0 : this.postContent.hashCode());
result = prime * result + ((this.projectKey == null) ? 0 : this.projectKey.hashCode());
result = prime * result + ((this.proxyPassword == null) ? 0 : this.proxyPassword.hashCode());
result = prime * result + ((this.proxyPort == null) ? 0 : this.proxyPort.hashCode());
result = prime * result + ((this.proxyServer == null) ? 0 : this.proxyServer.hashCode());
result = prime * result + ((this.proxyUser == null) ? 0 : this.proxyUser.hashCode());
result = prime * result + ((this.repositorySlug == null) ? 0 : this.repositorySlug.hashCode());
result = prime * result + ((this.triggerIfCanMerge == null) ? 0 : this.triggerIfCanMerge.hashCode());
result = prime * result + ((this.triggerIgnoreStateList == null) ? 0 : this.triggerIgnoreStateList.hashCode());
result = prime * result + ((this.triggers == null) ? 0 : this.triggers.hashCode());
Expand Down Expand Up @@ -316,6 +341,10 @@ public void setPostContent(String postContent) {
this.postContent = postContent;
}

public void setProjectKey(String projectKey) {
this.projectKey = projectKey;
}

public void setProxyPassword(String proxyPassword) {
this.proxyPassword = proxyPassword;
}
Expand All @@ -332,6 +361,10 @@ public void setProxyUser(String proxyUser) {
this.proxyUser = proxyUser;
}

public void setRepositorySlug(String repositorySlug) {
this.repositorySlug = repositorySlug;
}

public void setTriggerIfCanMerge(TRIGGER_IF_MERGE triggerIfCanMerge) {
this.triggerIfCanMerge = triggerIfCanMerge;
}
Expand Down Expand Up @@ -360,11 +393,12 @@ public void setUuid(UUID uuid) {
public String toString() {
return "NotificationDTO [filterRegexp=" + this.filterRegexp + ", filterString=" + this.filterString + ", headers="
+ this.headers + ", injectionUrl=" + this.injectionUrl + ", injectionUrlRegexp=" + this.injectionUrlRegexp
+ ", method=" + this.method + ", password=" + this.password + ", name=" + this.name + ", postContent="
+ this.postContent + ", proxyPassword=" + this.proxyPassword + ", proxyPort=" + this.proxyPort + ", proxyServer="
+ this.proxyServer + ", proxyUser=" + this.proxyUser + ", triggerIfCanMerge=" + this.triggerIfCanMerge
+ ", triggerIgnoreStateList=" + this.triggerIgnoreStateList + ", triggers=" + this.triggers + ", url=" + this.url
+ ", user=" + this.user + ", uuid=" + this.uuid + "]";
+ ", method=" + this.method + ", name=" + this.name + ", password=" + this.password + ", postContent="
+ this.postContent + ", projectKey=" + this.projectKey + ", proxyPassword=" + this.proxyPassword + ", proxyPort="
+ this.proxyPort + ", proxyServer=" + this.proxyServer + ", proxyUser=" + this.proxyUser + ", repositorySlug="
+ this.repositorySlug + ", triggerIfCanMerge=" + this.triggerIfCanMerge + ", triggerIgnoreStateList="
+ this.triggerIgnoreStateList + ", triggers=" + this.triggers + ", url=" + this.url + ", user=" + this.user
+ ", uuid=" + this.uuid + "]";
}

}
43 changes: 36 additions & 7 deletions src/main/java/se/bjurr/prnfb/settings/PrnfbNotification.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ public class PrnfbNotification implements HasUuid {
private final String name;
private final String password;
private final String postContent;
private final String projectKey;
private final String proxyPassword;
private final Integer proxyPort;
private final String proxyServer;
private final String proxyUser;
private final String repositorySlug;
private final TRIGGER_IF_MERGE triggerIfCanMerge;
private final List<PullRequestState> triggerIgnoreStateList;
private final List<PrnfbPullRequestAction> triggers;
Expand All @@ -52,6 +54,8 @@ public PrnfbNotification(PrnfbNotificationBuilder builder) throws ValidationExce
this.postContent = emptyToNull(nullToEmpty(builder.getPostContent()).trim());
this.method = firstNonNull(builder.getMethod(), GET);
this.triggerIfCanMerge = firstNonNull(builder.getTriggerIfCanMerge(), ALWAYS);
this.repositorySlug = emptyToNull(builder.getRepositorySlug());
this.projectKey = emptyToNull(builder.getProjectKey());
try {
new URL(builder.getUrl());
} catch (final Exception e) {
Expand Down Expand Up @@ -150,6 +154,13 @@ public boolean equals(Object obj) {
} else if (!this.postContent.equals(other.postContent)) {
return false;
}
if (this.projectKey == null) {
if (other.projectKey != null) {
return false;
}
} else if (!this.projectKey.equals(other.projectKey)) {
return false;
}
if (this.proxyPassword == null) {
if (other.proxyPassword != null) {
return false;
Expand Down Expand Up @@ -178,6 +189,13 @@ public boolean equals(Object obj) {
} else if (!this.proxyUser.equals(other.proxyUser)) {
return false;
}
if (this.repositorySlug == null) {
if (other.repositorySlug != null) {
return false;
}
} else if (!this.repositorySlug.equals(other.repositorySlug)) {
return false;
}
if (this.triggerIfCanMerge != other.triggerIfCanMerge) {
return false;
}
Expand Down Expand Up @@ -255,6 +273,10 @@ public Optional<String> getPostContent() {
return fromNullable(this.postContent);
}

public Optional<String> getProjectKey() {
return fromNullable(this.projectKey);
}

public Optional<String> getProxyPassword() {
return fromNullable(this.proxyPassword);
}
Expand All @@ -271,6 +293,10 @@ public Optional<String> getProxyUser() {
return fromNullable(this.proxyUser);
}

public Optional<String> getRepositorySlug() {
return fromNullable(this.repositorySlug);
}

public TRIGGER_IF_MERGE getTriggerIfCanMerge() {
return this.triggerIfCanMerge;
}
Expand Down Expand Up @@ -309,10 +335,12 @@ public int hashCode() {
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
result = prime * result + ((this.password == null) ? 0 : this.password.hashCode());
result = prime * result + ((this.postContent == null) ? 0 : this.postContent.hashCode());
result = prime * result + ((this.projectKey == null) ? 0 : this.projectKey.hashCode());
result = prime * result + ((this.proxyPassword == null) ? 0 : this.proxyPassword.hashCode());
result = prime * result + ((this.proxyPort == null) ? 0 : this.proxyPort.hashCode());
result = prime * result + ((this.proxyServer == null) ? 0 : this.proxyServer.hashCode());
result = prime * result + ((this.proxyUser == null) ? 0 : this.proxyUser.hashCode());
result = prime * result + ((this.repositorySlug == null) ? 0 : this.repositorySlug.hashCode());
result = prime * result + ((this.triggerIfCanMerge == null) ? 0 : this.triggerIfCanMerge.hashCode());
result = prime * result + ((this.triggerIgnoreStateList == null) ? 0 : this.triggerIgnoreStateList.hashCode());
result = prime * result + ((this.triggers == null) ? 0 : this.triggers.hashCode());
Expand All @@ -324,13 +352,14 @@ public int hashCode() {

@Override
public String toString() {
return "PrnfbNotification [uuid=" + this.uuid + ", filterRegexp=" + this.filterRegexp + ", filterString="
+ this.filterString + ", password=" + this.password + ", triggers=" + this.triggers + ", url=" + this.url
+ ", user=" + this.user + ", method=" + this.method + ", postContent=" + this.postContent + ", headers="
+ this.headers + ", proxyUser=" + this.proxyUser + ", proxyPassword=" + this.proxyPassword + ", proxyServer="
+ this.proxyServer + ", proxyPort=" + this.proxyPort + ", name=" + this.name + ", injectionUrl="
+ this.injectionUrl + ", injectionUrlRegexp=" + this.injectionUrlRegexp + ", triggerIfCanMerge="
+ this.triggerIfCanMerge + ", triggerIgnoreStateList=" + this.triggerIgnoreStateList + "]";
return "PrnfbNotification [filterRegexp=" + this.filterRegexp + ", filterString=" + this.filterString + ", headers="
+ this.headers + ", injectionUrl=" + this.injectionUrl + ", injectionUrlRegexp=" + this.injectionUrlRegexp
+ ", method=" + this.method + ", name=" + this.name + ", password=" + this.password + ", postContent="
+ this.postContent + ", projectKey=" + this.projectKey + ", proxyPassword=" + this.proxyPassword + ", proxyPort="
+ this.proxyPort + ", proxyServer=" + this.proxyServer + ", proxyUser=" + this.proxyUser + ", repositorySlug="
+ this.repositorySlug + ", triggerIfCanMerge=" + this.triggerIfCanMerge + ", triggerIgnoreStateList="
+ this.triggerIgnoreStateList + ", triggers=" + this.triggers + ", url=" + this.url + ", user=" + this.user
+ ", uuid=" + this.uuid + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ public static PrnfbNotificationBuilder prnfbNotificationBuilder(PrnfbNotificatio
private String name;
private String password;
private String postContent;
private String projectKey;
private String proxyPassword;
private Integer proxyPort;
private String proxyServer;
private String proxyUser;
private String repositorySlug;
private TRIGGER_IF_MERGE triggerIfCanMerge;
private List<PullRequestState> triggerIgnoreStateList = newArrayList();
private List<PrnfbPullRequestAction> triggers = newArrayList();
Expand Down Expand Up @@ -106,6 +108,10 @@ public String getPostContent() {
return this.postContent;
}

public String getProjectKey() {
return this.projectKey;
}

public String getProxyPassword() {
return this.proxyPassword;
}
Expand All @@ -122,6 +128,10 @@ public String getProxyUser() {
return this.proxyUser;
}

public String getRepositorySlug() {
return this.repositorySlug;
}

public TRIGGER_IF_MERGE getTriggerIfCanMerge() {
return this.triggerIfCanMerge;
}
Expand All @@ -142,6 +152,10 @@ public String getUser() {
return this.user;
}

public UUID getUuid() {
return this.uuid;
}

public UUID getUUID() {
return this.uuid;
}
Expand Down Expand Up @@ -206,6 +220,11 @@ public PrnfbNotificationBuilder withPostContent(String postContent) {
return this;
}

public PrnfbNotificationBuilder withProjectKey(String projectKey) {
this.projectKey = projectKey;
return this;
}

public PrnfbNotificationBuilder withProxyPassword(String s) {
this.proxyPassword = checkNotNull(s);
return this;
Expand All @@ -226,6 +245,11 @@ public PrnfbNotificationBuilder withProxyUser(String s) {
return this;
}

public PrnfbNotificationBuilder withRepositorySlug(String repositorySlug) {
this.repositorySlug = repositorySlug;
return this;
}

public PrnfbNotificationBuilder withTrigger(PrnfbPullRequestAction trigger) {
this.triggers.add(checkNotNull(trigger));
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public static List<HeaderDTO> toHeaderDtoList(List<PrnfbHeader> headers) {

public static NotificationDTO toNotificationDto(PrnfbNotification from) {
NotificationDTO to = new NotificationDTO();
to.setProjectKey(from.getProjectKey().orNull());
to.setRepositorySlug(from.getRepositorySlug().orNull());
to.setFilterRegexp(from.getFilterRegexp().orNull());
to.setFilterString(from.getFilterString().orNull());
to.setHeaders(toHeaderDtoList(from.getHeaders()));
Expand Down Expand Up @@ -82,6 +84,8 @@ public static PrnfbNotification toPrnfbNotification(NotificationDTO from) throws
.withUrl(from.getUrl())//
.withUser(from.getUser())//
.withUuid(from.getUuid())//
.withRepositorySlug(from.getRepositorySlug())//
.withProjectKey(from.getProjectKey())//
.build();
}

Expand Down
Loading

0 comments on commit 1fc12a7

Please sign in to comment.