Creates optional message for blockedKeyword This makes it possible to add information to be presented when one or more blockedKeyword(s) have a match. To use it, add the following to the project.config: [plugin "uploadvalidator"] rejectionMessage = message Change-Id: I7c99db5bc0ec488feb6c13fb650b3878cd28759a
diff --git a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/BlockedKeywordValidator.java b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/BlockedKeywordValidator.java index 41ad841..223f7c8 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/BlockedKeywordValidator.java +++ b/src/main/java/com/googlesource/gerrit/plugins/uploadvalidator/BlockedKeywordValidator.java
@@ -97,6 +97,10 @@ private static final String KEY_CHECK_BLOCKED_KEYWORD_PATTERN = KEY_CHECK_BLOCKED_KEYWORD + "Pattern"; + // This is used for a configuration option to append a custom message when blocked keywords are detected. + private static final String KEY_CHECK_BLOCKED_OPTIONAL_MESSAGE = "rejectionMessage"; + + public static AbstractModule module() { return new AbstractModule() { @Override @@ -176,8 +180,10 @@ cfg); if (!messages.isEmpty()) { + String rejectionMessage = cfg.getString(KEY_CHECK_BLOCKED_OPTIONAL_MESSAGE); + rejectionMessage = rejectionMessage == null ? "" : " " + rejectionMessage; throw new CommitValidationException( - "includes files containing blocked keywords", messages); + "includes files containing blocked keywords." + rejectionMessage, messages); } } }
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md index 9c5f967..2d2701b 100644 --- a/src/main/resources/Documentation/config.md +++ b/src/main/resources/Documentation/config.md
@@ -38,6 +38,7 @@ allowedCommitterEmailPattern = .*gerrit\\.com allowedCommitterEmailPattern = admin@gerrit\\..* rejectedCommitterEmailPattern = .*@old-name\\.com + rejectionMessage = yourMessage ``` plugin.@PLUGIN@.allowedAuthorEmailPattern @@ -451,3 +452,12 @@ other skip rules. Default: false + + +plugin.@PLUGIN@.rejectionMessage +: Additional message to be shown to user when blockedKeywords are found + + The message is appended and printed as the final part of the message that + returns found Keywords. + + Default: No message