From 7171d1eaba14619fee1203a5a477e686ea9a2ec5 Mon Sep 17 00:00:00 2001 From: Chris Kilding Date: Fri, 28 Jun 2019 13:14:52 +0100 Subject: [PATCH 1/5] Feature: Add MessageExclusion trait --- .../git/extensions/impl/MessageExclusion.java | 36 +++++++++++++++++++ .../git/traits/MessageExclusionTrait.java | 32 +++++++++++++++++ .../plugins/git/configuration-as-code.yaml | 2 ++ 3 files changed, 70 insertions(+) create mode 100644 src/main/java/jenkins/plugins/git/traits/MessageExclusionTrait.java diff --git a/src/main/java/hudson/plugins/git/extensions/impl/MessageExclusion.java b/src/main/java/hudson/plugins/git/extensions/impl/MessageExclusion.java index e5a83bc5a3..e44f80a5ef 100644 --- a/src/main/java/hudson/plugins/git/extensions/impl/MessageExclusion.java +++ b/src/main/java/hudson/plugins/git/extensions/impl/MessageExclusion.java @@ -16,6 +16,7 @@ import org.kohsuke.stapler.QueryParameter; import java.io.IOException; +import java.util.Objects; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -40,6 +41,41 @@ public class MessageExclusion extends GitSCMExtension { public String getExcludedMessage() { return excludedMessage; } + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + MessageExclusion that = (MessageExclusion) o; + + return Objects.equals(excludedMessage, that.excludedMessage); + } + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return Objects.hash(excludedMessage); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return "MessageExclusion{" + + "excludedMessage='" + excludedMessage + '\'' + + '}'; + } + @Override @SuppressFBWarnings(value="NP_BOOLEAN_RETURN_NULL", justification="null used to indicate other extensions should decide") @CheckForNull diff --git a/src/main/java/jenkins/plugins/git/traits/MessageExclusionTrait.java b/src/main/java/jenkins/plugins/git/traits/MessageExclusionTrait.java new file mode 100644 index 0000000000..3fb2939320 --- /dev/null +++ b/src/main/java/jenkins/plugins/git/traits/MessageExclusionTrait.java @@ -0,0 +1,32 @@ +package jenkins.plugins.git.traits; + +import org.kohsuke.stapler.DataBoundConstructor; + +import hudson.Extension; +import hudson.plugins.git.extensions.impl.MessageExclusion; + +public class MessageExclusionTrait extends GitSCMExtensionTrait { + /** + * Stapler constructor. + * + * @param extension the {@link MessageExclusion}. + */ + @DataBoundConstructor + public MessageExclusionTrait(MessageExclusion extension) { + super(extension); + } + + /** + * Our {@link hudson.model.Descriptor} + */ + @Extension + public static class DescriptorImpl extends GitSCMExtensionTraitDescriptor { + /** + * {@inheritDoc} + */ + @Override + public String getDisplayName() { + return "Message exclusion"; + } + } +} diff --git a/src/test/resources/jenkins/plugins/git/configuration-as-code.yaml b/src/test/resources/jenkins/plugins/git/configuration-as-code.yaml index 4e99674ac5..5ab269be4e 100644 --- a/src/test/resources/jenkins/plugins/git/configuration-as-code.yaml +++ b/src/test/resources/jenkins/plugins/git/configuration-as-code.yaml @@ -19,6 +19,8 @@ unclassified: - userIdentity: email: "customuser@acmecorp.com" name: "custom user" + - messageExclusion: + excludedMessage: ".*\[ci skip\].*" - preBuildMerge: options: mergeRemote: "myrepo" From 844ad45050e54b5b3b6f552e04a3e8fd3f8bff59 Mon Sep 17 00:00:00 2001 From: Chris Kilding Date: Fri, 28 Jun 2019 15:07:49 +0100 Subject: [PATCH 2/5] Update tests --- .../jenkins/plugins/git/GitSCMSourceTraitsTest.java | 12 ++++++++++++ .../jenkins/plugins/git/configuration-as-code.yaml | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java b/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java index 77266980d9..4cf6f35c26 100644 --- a/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java +++ b/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java @@ -9,6 +9,7 @@ import hudson.plugins.git.extensions.impl.CloneOption; import hudson.plugins.git.extensions.impl.GitLFSPull; import hudson.plugins.git.extensions.impl.LocalBranch; +import hudson.plugins.git.extensions.impl.MessageExclusion; import hudson.plugins.git.extensions.impl.PruneStaleBranch; import hudson.plugins.git.extensions.impl.SubmoduleOption; import hudson.plugins.git.extensions.impl.UserIdentity; @@ -25,6 +26,7 @@ import jenkins.plugins.git.traits.GitLFSPullTrait; import jenkins.plugins.git.traits.IgnoreOnPushNotificationTrait; import jenkins.plugins.git.traits.LocalBranchTrait; +import jenkins.plugins.git.traits.MessageExclusionTrait; import jenkins.plugins.git.traits.PruneStaleBranchTrait; import jenkins.plugins.git.traits.RefSpecsSCMSourceTrait; import jenkins.plugins.git.traits.RemoteNameSCMSourceTrait; @@ -134,6 +136,12 @@ public void pimpped_out() throws Exception { ), Matchers.instanceOf(CleanAfterCheckoutTrait.class), Matchers.instanceOf(CleanBeforeCheckoutTrait.class), + Matchers.allOf( + instanceOf(MessageExclusionTrait.class), + hasProperty("extension", + hasProperty("excludedMessage", is("does not work")) + ) + ), Matchers.allOf( instanceOf(UserIdentityTrait.class), hasProperty("extension", @@ -198,6 +206,10 @@ public void pimpped_out() throws Exception { hasProperty("name", is("bob")), hasProperty("email", is("bob@example.com")) ), + Matchers.allOf( + instanceOf(MessageExclusion.class), + hasProperty("excludedMessage", is("does not work")) + ), Matchers.instanceOf(GitLFSPull.class), Matchers.instanceOf(PruneStaleBranch.class), Matchers.instanceOf(AuthorInChangelog.class), diff --git a/src/test/resources/jenkins/plugins/git/configuration-as-code.yaml b/src/test/resources/jenkins/plugins/git/configuration-as-code.yaml index 5ab269be4e..a2b2c1fd76 100644 --- a/src/test/resources/jenkins/plugins/git/configuration-as-code.yaml +++ b/src/test/resources/jenkins/plugins/git/configuration-as-code.yaml @@ -20,7 +20,7 @@ unclassified: email: "customuser@acmecorp.com" name: "custom user" - messageExclusion: - excludedMessage: ".*\[ci skip\].*" + excludedMessage: "does not work" - preBuildMerge: options: mergeRemote: "myrepo" From 556a5b9f04ce7e44c82e3b6c8c2f853f51155f33 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 19 Dec 2020 08:55:09 -0700 Subject: [PATCH 3/5] Fix prior merge error --- src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java b/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java index 7e41f31e77..82c5edc1a6 100644 --- a/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java +++ b/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java @@ -195,7 +195,8 @@ public void pimpped_out() throws Exception { Matchers.allOf( instanceOf(MessageExclusionTrait.class), hasProperty("extension", - hasProperty("excludedMessage", is("does not work")) + hasProperty("excludedMessage", is("does not work"))) + ) Matchers.allOf( instanceOf(CleanBeforeCheckoutTrait.class), hasProperty("extension", From 208c9b107735a4943ca8e0241795760e74f2a873 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 19 Dec 2020 08:56:09 -0700 Subject: [PATCH 4/5] Another fix to my merge error --- src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java b/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java index 82c5edc1a6..1351797d3c 100644 --- a/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java +++ b/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java @@ -197,6 +197,7 @@ public void pimpped_out() throws Exception { hasProperty("extension", hasProperty("excludedMessage", is("does not work"))) ) + ), Matchers.allOf( instanceOf(CleanBeforeCheckoutTrait.class), hasProperty("extension", From 3d6173d519d419c41a68374d9453ad518419d096 Mon Sep 17 00:00:00 2001 From: Mark Waite Date: Sat, 19 Dec 2020 09:49:40 -0700 Subject: [PATCH 5/5] Fix compile error --- src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java b/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java index 1351797d3c..8ef7b4e0ac 100644 --- a/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java +++ b/src/test/java/jenkins/plugins/git/GitSCMSourceTraitsTest.java @@ -196,7 +196,6 @@ public void pimpped_out() throws Exception { instanceOf(MessageExclusionTrait.class), hasProperty("extension", hasProperty("excludedMessage", is("does not work"))) - ) ), Matchers.allOf( instanceOf(CleanBeforeCheckoutTrait.class),