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

Commit 1fc12a7

Browse files
committed
Adding project and repo filter to notification #25
1 parent 3e1fdda commit 1fc12a7

File tree

6 files changed

+209
-13
lines changed

6 files changed

+209
-13
lines changed

src/main/java/se/bjurr/prnfb/listener/PrnfbPullRequestEventListener.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ public boolean isNotificationTriggeredByAction(PrnfbNotification notification,
9191
if (!notification.getTriggers().contains(pullRequestAction)) {
9292
return FALSE;
9393
}
94+
95+
if (notification.getProjectKey().isPresent()) {
96+
if (!notification.getProjectKey().get().equals(pullRequest.getToRef().getRepository().getProject().getKey())) {
97+
return FALSE;
98+
}
99+
}
100+
101+
if (notification.getRepositorySlug().isPresent()) {
102+
if (!notification.getRepositorySlug().get().equals(pullRequest.getToRef().getRepository().getSlug())) {
103+
return FALSE;
104+
}
105+
}
106+
94107
if (notification.getFilterRegexp().isPresent()
95108
&& notification.getFilterString().isPresent()
96109
&& !compile(notification.getFilterRegexp().get()).matcher(

src/main/java/se/bjurr/prnfb/presentation/dto/NotificationDTO.java

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
@XmlRootElement
1818
@XmlAccessorType(FIELD)
1919
public class NotificationDTO {
20-
2120
private String filterRegexp;
2221
private String filterString;
2322
private List<HeaderDTO> headers;
@@ -27,10 +26,12 @@ public class NotificationDTO {
2726
private String name;
2827
private String password;
2928
private String postContent;
29+
private String projectKey;
3030
private String proxyPassword;
3131
private Integer proxyPort;
3232
private String proxyServer;
3333
private String proxyUser;
34+
private String repositorySlug;
3435
private TRIGGER_IF_MERGE triggerIfCanMerge;
3536
private List<PullRequestState> triggerIgnoreStateList;
3637
private List<PrnfbPullRequestAction> triggers;
@@ -109,6 +110,13 @@ public boolean equals(Object obj) {
109110
} else if (!this.postContent.equals(other.postContent)) {
110111
return false;
111112
}
113+
if (this.projectKey == null) {
114+
if (other.projectKey != null) {
115+
return false;
116+
}
117+
} else if (!this.projectKey.equals(other.projectKey)) {
118+
return false;
119+
}
112120
if (this.proxyPassword == null) {
113121
if (other.proxyPassword != null) {
114122
return false;
@@ -137,6 +145,13 @@ public boolean equals(Object obj) {
137145
} else if (!this.proxyUser.equals(other.proxyUser)) {
138146
return false;
139147
}
148+
if (this.repositorySlug == null) {
149+
if (other.repositorySlug != null) {
150+
return false;
151+
}
152+
} else if (!this.repositorySlug.equals(other.repositorySlug)) {
153+
return false;
154+
}
140155
if (this.triggerIfCanMerge != other.triggerIfCanMerge) {
141156
return false;
142157
}
@@ -214,6 +229,10 @@ public String getPostContent() {
214229
return this.postContent;
215230
}
216231

232+
public String getProjectKey() {
233+
return this.projectKey;
234+
}
235+
217236
public String getProxyPassword() {
218237
return this.proxyPassword;
219238
}
@@ -230,6 +249,10 @@ public String getProxyUser() {
230249
return this.proxyUser;
231250
}
232251

252+
public String getRepositorySlug() {
253+
return this.repositorySlug;
254+
}
255+
233256
public TRIGGER_IF_MERGE getTriggerIfCanMerge() {
234257
return this.triggerIfCanMerge;
235258
}
@@ -267,10 +290,12 @@ public int hashCode() {
267290
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
268291
result = prime * result + ((this.password == null) ? 0 : this.password.hashCode());
269292
result = prime * result + ((this.postContent == null) ? 0 : this.postContent.hashCode());
293+
result = prime * result + ((this.projectKey == null) ? 0 : this.projectKey.hashCode());
270294
result = prime * result + ((this.proxyPassword == null) ? 0 : this.proxyPassword.hashCode());
271295
result = prime * result + ((this.proxyPort == null) ? 0 : this.proxyPort.hashCode());
272296
result = prime * result + ((this.proxyServer == null) ? 0 : this.proxyServer.hashCode());
273297
result = prime * result + ((this.proxyUser == null) ? 0 : this.proxyUser.hashCode());
298+
result = prime * result + ((this.repositorySlug == null) ? 0 : this.repositorySlug.hashCode());
274299
result = prime * result + ((this.triggerIfCanMerge == null) ? 0 : this.triggerIfCanMerge.hashCode());
275300
result = prime * result + ((this.triggerIgnoreStateList == null) ? 0 : this.triggerIgnoreStateList.hashCode());
276301
result = prime * result + ((this.triggers == null) ? 0 : this.triggers.hashCode());
@@ -316,6 +341,10 @@ public void setPostContent(String postContent) {
316341
this.postContent = postContent;
317342
}
318343

344+
public void setProjectKey(String projectKey) {
345+
this.projectKey = projectKey;
346+
}
347+
319348
public void setProxyPassword(String proxyPassword) {
320349
this.proxyPassword = proxyPassword;
321350
}
@@ -332,6 +361,10 @@ public void setProxyUser(String proxyUser) {
332361
this.proxyUser = proxyUser;
333362
}
334363

364+
public void setRepositorySlug(String repositorySlug) {
365+
this.repositorySlug = repositorySlug;
366+
}
367+
335368
public void setTriggerIfCanMerge(TRIGGER_IF_MERGE triggerIfCanMerge) {
336369
this.triggerIfCanMerge = triggerIfCanMerge;
337370
}
@@ -360,11 +393,12 @@ public void setUuid(UUID uuid) {
360393
public String toString() {
361394
return "NotificationDTO [filterRegexp=" + this.filterRegexp + ", filterString=" + this.filterString + ", headers="
362395
+ this.headers + ", injectionUrl=" + this.injectionUrl + ", injectionUrlRegexp=" + this.injectionUrlRegexp
363-
+ ", method=" + this.method + ", password=" + this.password + ", name=" + this.name + ", postContent="
364-
+ this.postContent + ", proxyPassword=" + this.proxyPassword + ", proxyPort=" + this.proxyPort + ", proxyServer="
365-
+ this.proxyServer + ", proxyUser=" + this.proxyUser + ", triggerIfCanMerge=" + this.triggerIfCanMerge
366-
+ ", triggerIgnoreStateList=" + this.triggerIgnoreStateList + ", triggers=" + this.triggers + ", url=" + this.url
367-
+ ", user=" + this.user + ", uuid=" + this.uuid + "]";
396+
+ ", method=" + this.method + ", name=" + this.name + ", password=" + this.password + ", postContent="
397+
+ this.postContent + ", projectKey=" + this.projectKey + ", proxyPassword=" + this.proxyPassword + ", proxyPort="
398+
+ this.proxyPort + ", proxyServer=" + this.proxyServer + ", proxyUser=" + this.proxyUser + ", repositorySlug="
399+
+ this.repositorySlug + ", triggerIfCanMerge=" + this.triggerIfCanMerge + ", triggerIgnoreStateList="
400+
+ this.triggerIgnoreStateList + ", triggers=" + this.triggers + ", url=" + this.url + ", user=" + this.user
401+
+ ", uuid=" + this.uuid + "]";
368402
}
369403

370404
}

src/main/java/se/bjurr/prnfb/settings/PrnfbNotification.java

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ public class PrnfbNotification implements HasUuid {
3131
private final String name;
3232
private final String password;
3333
private final String postContent;
34+
private final String projectKey;
3435
private final String proxyPassword;
3536
private final Integer proxyPort;
3637
private final String proxyServer;
3738
private final String proxyUser;
39+
private final String repositorySlug;
3840
private final TRIGGER_IF_MERGE triggerIfCanMerge;
3941
private final List<PullRequestState> triggerIgnoreStateList;
4042
private final List<PrnfbPullRequestAction> triggers;
@@ -52,6 +54,8 @@ public PrnfbNotification(PrnfbNotificationBuilder builder) throws ValidationExce
5254
this.postContent = emptyToNull(nullToEmpty(builder.getPostContent()).trim());
5355
this.method = firstNonNull(builder.getMethod(), GET);
5456
this.triggerIfCanMerge = firstNonNull(builder.getTriggerIfCanMerge(), ALWAYS);
57+
this.repositorySlug = emptyToNull(builder.getRepositorySlug());
58+
this.projectKey = emptyToNull(builder.getProjectKey());
5559
try {
5660
new URL(builder.getUrl());
5761
} catch (final Exception e) {
@@ -150,6 +154,13 @@ public boolean equals(Object obj) {
150154
} else if (!this.postContent.equals(other.postContent)) {
151155
return false;
152156
}
157+
if (this.projectKey == null) {
158+
if (other.projectKey != null) {
159+
return false;
160+
}
161+
} else if (!this.projectKey.equals(other.projectKey)) {
162+
return false;
163+
}
153164
if (this.proxyPassword == null) {
154165
if (other.proxyPassword != null) {
155166
return false;
@@ -178,6 +189,13 @@ public boolean equals(Object obj) {
178189
} else if (!this.proxyUser.equals(other.proxyUser)) {
179190
return false;
180191
}
192+
if (this.repositorySlug == null) {
193+
if (other.repositorySlug != null) {
194+
return false;
195+
}
196+
} else if (!this.repositorySlug.equals(other.repositorySlug)) {
197+
return false;
198+
}
181199
if (this.triggerIfCanMerge != other.triggerIfCanMerge) {
182200
return false;
183201
}
@@ -255,6 +273,10 @@ public Optional<String> getPostContent() {
255273
return fromNullable(this.postContent);
256274
}
257275

276+
public Optional<String> getProjectKey() {
277+
return fromNullable(this.projectKey);
278+
}
279+
258280
public Optional<String> getProxyPassword() {
259281
return fromNullable(this.proxyPassword);
260282
}
@@ -271,6 +293,10 @@ public Optional<String> getProxyUser() {
271293
return fromNullable(this.proxyUser);
272294
}
273295

296+
public Optional<String> getRepositorySlug() {
297+
return fromNullable(this.repositorySlug);
298+
}
299+
274300
public TRIGGER_IF_MERGE getTriggerIfCanMerge() {
275301
return this.triggerIfCanMerge;
276302
}
@@ -309,10 +335,12 @@ public int hashCode() {
309335
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
310336
result = prime * result + ((this.password == null) ? 0 : this.password.hashCode());
311337
result = prime * result + ((this.postContent == null) ? 0 : this.postContent.hashCode());
338+
result = prime * result + ((this.projectKey == null) ? 0 : this.projectKey.hashCode());
312339
result = prime * result + ((this.proxyPassword == null) ? 0 : this.proxyPassword.hashCode());
313340
result = prime * result + ((this.proxyPort == null) ? 0 : this.proxyPort.hashCode());
314341
result = prime * result + ((this.proxyServer == null) ? 0 : this.proxyServer.hashCode());
315342
result = prime * result + ((this.proxyUser == null) ? 0 : this.proxyUser.hashCode());
343+
result = prime * result + ((this.repositorySlug == null) ? 0 : this.repositorySlug.hashCode());
316344
result = prime * result + ((this.triggerIfCanMerge == null) ? 0 : this.triggerIfCanMerge.hashCode());
317345
result = prime * result + ((this.triggerIgnoreStateList == null) ? 0 : this.triggerIgnoreStateList.hashCode());
318346
result = prime * result + ((this.triggers == null) ? 0 : this.triggers.hashCode());
@@ -324,13 +352,14 @@ public int hashCode() {
324352

325353
@Override
326354
public String toString() {
327-
return "PrnfbNotification [uuid=" + this.uuid + ", filterRegexp=" + this.filterRegexp + ", filterString="
328-
+ this.filterString + ", password=" + this.password + ", triggers=" + this.triggers + ", url=" + this.url
329-
+ ", user=" + this.user + ", method=" + this.method + ", postContent=" + this.postContent + ", headers="
330-
+ this.headers + ", proxyUser=" + this.proxyUser + ", proxyPassword=" + this.proxyPassword + ", proxyServer="
331-
+ this.proxyServer + ", proxyPort=" + this.proxyPort + ", name=" + this.name + ", injectionUrl="
332-
+ this.injectionUrl + ", injectionUrlRegexp=" + this.injectionUrlRegexp + ", triggerIfCanMerge="
333-
+ this.triggerIfCanMerge + ", triggerIgnoreStateList=" + this.triggerIgnoreStateList + "]";
355+
return "PrnfbNotification [filterRegexp=" + this.filterRegexp + ", filterString=" + this.filterString + ", headers="
356+
+ this.headers + ", injectionUrl=" + this.injectionUrl + ", injectionUrlRegexp=" + this.injectionUrlRegexp
357+
+ ", method=" + this.method + ", name=" + this.name + ", password=" + this.password + ", postContent="
358+
+ this.postContent + ", projectKey=" + this.projectKey + ", proxyPassword=" + this.proxyPassword + ", proxyPort="
359+
+ this.proxyPort + ", proxyServer=" + this.proxyServer + ", proxyUser=" + this.proxyUser + ", repositorySlug="
360+
+ this.repositorySlug + ", triggerIfCanMerge=" + this.triggerIfCanMerge + ", triggerIgnoreStateList="
361+
+ this.triggerIgnoreStateList + ", triggers=" + this.triggers + ", url=" + this.url + ", user=" + this.user
362+
+ ", uuid=" + this.uuid + "]";
334363
}
335364

336365
}

src/main/java/se/bjurr/prnfb/settings/PrnfbNotificationBuilder.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ public static PrnfbNotificationBuilder prnfbNotificationBuilder(PrnfbNotificatio
5151
private String name;
5252
private String password;
5353
private String postContent;
54+
private String projectKey;
5455
private String proxyPassword;
5556
private Integer proxyPort;
5657
private String proxyServer;
5758
private String proxyUser;
59+
private String repositorySlug;
5860
private TRIGGER_IF_MERGE triggerIfCanMerge;
5961
private List<PullRequestState> triggerIgnoreStateList = newArrayList();
6062
private List<PrnfbPullRequestAction> triggers = newArrayList();
@@ -106,6 +108,10 @@ public String getPostContent() {
106108
return this.postContent;
107109
}
108110

111+
public String getProjectKey() {
112+
return this.projectKey;
113+
}
114+
109115
public String getProxyPassword() {
110116
return this.proxyPassword;
111117
}
@@ -122,6 +128,10 @@ public String getProxyUser() {
122128
return this.proxyUser;
123129
}
124130

131+
public String getRepositorySlug() {
132+
return this.repositorySlug;
133+
}
134+
125135
public TRIGGER_IF_MERGE getTriggerIfCanMerge() {
126136
return this.triggerIfCanMerge;
127137
}
@@ -142,6 +152,10 @@ public String getUser() {
142152
return this.user;
143153
}
144154

155+
public UUID getUuid() {
156+
return this.uuid;
157+
}
158+
145159
public UUID getUUID() {
146160
return this.uuid;
147161
}
@@ -206,6 +220,11 @@ public PrnfbNotificationBuilder withPostContent(String postContent) {
206220
return this;
207221
}
208222

223+
public PrnfbNotificationBuilder withProjectKey(String projectKey) {
224+
this.projectKey = projectKey;
225+
return this;
226+
}
227+
209228
public PrnfbNotificationBuilder withProxyPassword(String s) {
210229
this.proxyPassword = checkNotNull(s);
211230
return this;
@@ -226,6 +245,11 @@ public PrnfbNotificationBuilder withProxyUser(String s) {
226245
return this;
227246
}
228247

248+
public PrnfbNotificationBuilder withRepositorySlug(String repositorySlug) {
249+
this.repositorySlug = repositorySlug;
250+
return this;
251+
}
252+
229253
public PrnfbNotificationBuilder withTrigger(PrnfbPullRequestAction trigger) {
230254
this.triggers.add(checkNotNull(trigger));
231255
return this;

src/main/java/se/bjurr/prnfb/transformer/NotificationTransformer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public static List<HeaderDTO> toHeaderDtoList(List<PrnfbHeader> headers) {
3131

3232
public static NotificationDTO toNotificationDto(PrnfbNotification from) {
3333
NotificationDTO to = new NotificationDTO();
34+
to.setProjectKey(from.getProjectKey().orNull());
35+
to.setRepositorySlug(from.getRepositorySlug().orNull());
3436
to.setFilterRegexp(from.getFilterRegexp().orNull());
3537
to.setFilterString(from.getFilterString().orNull());
3638
to.setHeaders(toHeaderDtoList(from.getHeaders()));
@@ -82,6 +84,8 @@ public static PrnfbNotification toPrnfbNotification(NotificationDTO from) throws
8284
.withUrl(from.getUrl())//
8385
.withUser(from.getUser())//
8486
.withUuid(from.getUuid())//
87+
.withRepositorySlug(from.getRepositorySlug())//
88+
.withProjectKey(from.getProjectKey())//
8589
.build();
8690
}
8791

0 commit comments

Comments
 (0)