Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/com/nerdwin15/stash/webhook/Notifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public class Notifier implements DisposableBean {
public static final String IGNORE_COMMITTERS = "ignoreCommitters";

/**
* Field name for the ignore committers delimiter
*/
public static final String IGNORE_COMMITTERS_DELIMITER = "ignoreCommittersDelimiter";

/**
* Field name for the branch options selection property
*/
public static final String BRANCH_OPTIONS = "branchOptions";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ public boolean shouldDeliverNotification(EventContext event) {
final Settings settings = settingsService.getSettings(
event.getRepository());
String ignoreCommitters = settings.getString(Notifier.IGNORE_COMMITTERS);
String ignoreCommittersDelimiter = settings.getString(Notifier.IGNORE_COMMITTERS_DELIMITER, " ");
if (ignoreCommitters == null || eventUserName == null)
return true;

for (String committer : ignoreCommitters.split(" ")) {
for (String committer : ignoreCommitters.split(ignoreCommittersDelimiter)) {
if (committer.equalsIgnoreCase(eventUserName)) {
logger.debug("Ignoring push event due to ignore committer {}",
committer);
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/i18n/stash-webhook-jenkins.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ stash.webhook.test.button.label=Trigger Jenkins
stash.webhook.test.button.tooltip=Manually trigger Jenkins builds.
stash.webhook.advancedConfiguration.label=Advanced Configuration
stash.webhook.ignoreCommitters.label=Committers to Ignore
stash.webhook.ignoreCommitters.description=Stash usernames of committer(s) whose pushes/merges should NOT trigger a Jenkins notification. Space delimited
stash.webhook.ignoreCommitters.description=Stash usernames of committer(s) whose pushes/merges should NOT trigger a Jenkins notification.
stash.webhook.ignoreCommittersDelimiter.label=Committers to Ignore Delimiter
stash.webhook.ignoreCommittersDelimiter.description=If left empty, Committers to Ignore will use the default Space delimiter.
stash.webhook.repo.branchOptions.label=Branch Options
stash.webhook.repo.branchOptions.description=Build from only certain branches or ignore certain branches. Space-delimited. Case-insensitive. Wildcard usage of * accepted only at end of name.
11 changes: 11 additions & 0 deletions src/main/resources/static/jenkins.soy
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@
{param errorTexts: $errors ? $errors['ignoreCommitters'] : null /}
{/call}

{call aui.form.textField}
{param id: 'ignoreCommittersDelimiter' /}
{param value: $config['ignoreCommittersDelimiter'] /}
{param labelContent}
{getText('stash.webhook.ignoreCommittersDelimiter.label')}
{/param}
{param descriptionText: getText('stash.webhook.ignoreCommitters.delimiter.description') /}
{param extraClasses: 'short' /}
{param errorTexts: $errors ? $errors['ignoreCommittersDelimiter'] : null /}
{/call}

<div class="field-group">
<label for="branchOptions">{getText('stash.webhook.repo.branchOptions.label')}</label>
<select class="select" id="branchOptions" name="branchOptions" style="max-width: 110px">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void setUp() throws Exception {
@Test
public void shouldAllowWhenIgnoredCommittersNull() throws Exception {
when(settings.getString(Notifier.IGNORE_COMMITTERS)).thenReturn(null);
when(settings.getString(Notifier.IGNORE_COMMITTERS_DELIMITER, " ")).thenReturn(" ");
assertTrue(filter.shouldDeliverNotification(eventContext));
}

Expand All @@ -64,6 +65,7 @@ public void shouldAllowWhenIgnoredCommittersNull() throws Exception {
public void shouldAllowWhenIgnoredCommittersDoesntMatch() throws Exception {
when(settings.getString(Notifier.IGNORE_COMMITTERS))
.thenReturn(username + "-notmatching");
when(settings.getString(Notifier.IGNORE_COMMITTERS_DELIMITER, " ")).thenReturn(" ");
assertTrue(filter.shouldDeliverNotification(eventContext));
}

Expand All @@ -74,6 +76,7 @@ public void shouldAllowWhenIgnoredCommittersDoesntMatch() throws Exception {
@Test
public void shouldCancelWhenIgnoredCommittersMatches() throws Exception {
when(settings.getString(Notifier.IGNORE_COMMITTERS)).thenReturn(username);
when(settings.getString(Notifier.IGNORE_COMMITTERS_DELIMITER, " ")).thenReturn(" ");
assertFalse(filter.shouldDeliverNotification(eventContext));
}

Expand All @@ -85,7 +88,20 @@ public void shouldCancelWhenIgnoredCommittersMatches() throws Exception {
public void shouldCancelWhenMatchesWithMultipleCommitters() throws Exception {
when(settings.getString(Notifier.IGNORE_COMMITTERS)).thenReturn(username
+ " anotherUser");
when(settings.getString(Notifier.IGNORE_COMMITTERS_DELIMITER, " ")).thenReturn(" ");
assertFalse(filter.shouldDeliverNotification(eventContext));
}

/**
* Validate that the filter should cancel if an ignored committer matches
* @throws Exception
*/
@Test
public void shouldCancelWhenMatchesWithMultipleCommittersAndCustomDelimiter() throws Exception {
when(settings.getString(Notifier.IGNORE_COMMITTERS)).thenReturn(username
+ ",anotherUser");
when(settings.getString(Notifier.IGNORE_COMMITTERS_DELIMITER, " ")).thenReturn(",");
assertFalse(filter.shouldDeliverNotification(eventContext));
}

}