From a13c5e7435ea7937d2f82e0e6f40b756ec1c5ae8 Mon Sep 17 00:00:00 2001 From: Jo Shields Date: Wed, 22 Apr 2015 16:55:25 +0100 Subject: [PATCH] Add option to not send the "hello!" message to non-whitelisted pull request submissions This is helpful where you have multiple Jenkins jobs, all looking at the same repository - rather than spamming the user with multiple "Hello!" messages, you can pick one job to spam the user loudly, whilst letting all your other jobs silently obey the build/whitelist/etc comments --- src/main/java/org/jenkinsci/plugins/ghprb/Ghprb.java | 4 ++++ .../java/org/jenkinsci/plugins/ghprb/GhprbPullRequest.java | 2 +- .../java/org/jenkinsci/plugins/ghprb/GhprbTrigger.java | 7 +++++++ .../org/jenkinsci/plugins/ghprb/GhprbTrigger/config.groovy | 3 +++ .../jenkinsci/plugins/ghprb/GhprbTrigger/config.jelly.tmp | 3 +++ 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jenkinsci/plugins/ghprb/Ghprb.java b/src/main/java/org/jenkinsci/plugins/ghprb/Ghprb.java index 1f7f2a6de..d33860e69 100644 --- a/src/main/java/org/jenkinsci/plugins/ghprb/Ghprb.java +++ b/src/main/java/org/jenkinsci/plugins/ghprb/Ghprb.java @@ -182,6 +182,10 @@ public boolean isTriggerPhrase(String comment) { public boolean ifOnlyTriggerPhrase() { return trigger.getOnlyTriggerPhrase(); } + + public boolean suppressTestingRequest() { + return trigger.getSuppressTestingRequest(); + } public boolean isWhitelisted(GHUser user) { return trigger.getPermitAll() diff --git a/src/main/java/org/jenkinsci/plugins/ghprb/GhprbPullRequest.java b/src/main/java/org/jenkinsci/plugins/ghprb/GhprbPullRequest.java index 77db13e7d..d5c6cc1d1 100644 --- a/src/main/java/org/jenkinsci/plugins/ghprb/GhprbPullRequest.java +++ b/src/main/java/org/jenkinsci/plugins/ghprb/GhprbPullRequest.java @@ -79,7 +79,7 @@ public class GhprbPullRequest { if (helper.isWhitelisted(author)) { accepted = true; shouldRun = true; - } else { + } else if (!helper.suppressTestingRequest()) { logger.log(Level.INFO, "Author of #{0} {1} on {2} not in whitelist!", new Object[] { id, author.getLogin(), reponame }); repo.addComment(id, GhprbTrigger.getDscp().getRequestForTestingPhrase()); } diff --git a/src/main/java/org/jenkinsci/plugins/ghprb/GhprbTrigger.java b/src/main/java/org/jenkinsci/plugins/ghprb/GhprbTrigger.java index e4a1629bb..5bccfd9a3 100644 --- a/src/main/java/org/jenkinsci/plugins/ghprb/GhprbTrigger.java +++ b/src/main/java/org/jenkinsci/plugins/ghprb/GhprbTrigger.java @@ -60,6 +60,7 @@ public class GhprbTrigger extends GhprbTriggerBackwardsCompatible { private final String triggerPhrase; private final String buildDescTemplate; private final Boolean onlyTriggerPhrase; + private final Boolean suppressTestingRequest; private final Boolean useGitHubHooks; private final Boolean permitAll; private String whitelist; @@ -104,6 +105,7 @@ public GhprbTrigger(String adminlist, String triggerPhrase, Boolean onlyTriggerPhrase, Boolean useGitHubHooks, + Boolean suppressTestingRequest, Boolean permitAll, Boolean autoCloseFailedPullRequests, Boolean displayBuildErrorsOnDownstreamBuilds, @@ -124,6 +126,7 @@ public GhprbTrigger(String adminlist, this.cron = cron; this.triggerPhrase = triggerPhrase; this.onlyTriggerPhrase = onlyTriggerPhrase; + this.suppressTestingRequest = suppressTestingRequest; this.useGitHubHooks = useGitHubHooks; this.permitAll = permitAll; this.autoCloseFailedPullRequests = autoCloseFailedPullRequests; @@ -401,6 +404,10 @@ public String getTriggerPhrase() { public Boolean getOnlyTriggerPhrase() { return onlyTriggerPhrase != null && onlyTriggerPhrase; } + + public Boolean getSuppressTestingRequest() { + return suppressTestingRequest != null && suppressTestingRequest; + } public Boolean getUseGitHubHooks() { return useGitHubHooks != null && useGitHubHooks; diff --git a/src/main/resources/org/jenkinsci/plugins/ghprb/GhprbTrigger/config.groovy b/src/main/resources/org/jenkinsci/plugins/ghprb/GhprbTrigger/config.groovy index 983bd87ad..8354c33b3 100644 --- a/src/main/resources/org/jenkinsci/plugins/ghprb/GhprbTrigger/config.groovy +++ b/src/main/resources/org/jenkinsci/plugins/ghprb/GhprbTrigger/config.groovy @@ -18,6 +18,9 @@ f.advanced() { f.entry(field: "onlyTriggerPhrase", title: "Only use trigger phrase for build triggering") { f.checkbox() } + f.entry(field: "suppressTestingRequest", title: "Don't send request for approval message for non-whitelisted builders") { + f.checkbox() + } f.entry(field: "autoCloseFailedPullRequests", title: _("Close failed pull request automatically?")) { f.checkbox(default: descriptor.autoCloseFailedPullRequests) } diff --git a/src/main/resources/org/jenkinsci/plugins/ghprb/GhprbTrigger/config.jelly.tmp b/src/main/resources/org/jenkinsci/plugins/ghprb/GhprbTrigger/config.jelly.tmp index 37e864744..3d1e0ab8e 100644 --- a/src/main/resources/org/jenkinsci/plugins/ghprb/GhprbTrigger/config.jelly.tmp +++ b/src/main/resources/org/jenkinsci/plugins/ghprb/GhprbTrigger/config.jelly.tmp @@ -21,6 +21,9 @@ + + +