From 765d21b3606103f42950cf05af112324c2e17367 Mon Sep 17 00:00:00 2001 From: julioc-p <14-10820@usb.ve> Date: Thu, 26 Sep 2024 14:32:48 +0200 Subject: [PATCH 1/2] added symbol annotations for easier naming in pipeline --- ...ketPPRPullRequestApprovedActionFilter.java | 22 +++++----- ...PullRequestCommentCreatedActionFilter.java | 29 +++++++++----- ...PullRequestCommentDeletedActionFilter.java | 23 +++++++---- ...PullRequestCommentUpdatedActionFilter.java | 23 +++++++---- ...cketPPRPullRequestCreatedActionFilter.java | 30 +++++++++----- ...ketPPRPullRequestDeclinedActionFilter.java | 33 +++++++++------ ...ucketPPRPullRequestMergedActionFilter.java | 32 +++++++++------ .../BitBucketPPRPullRequestTriggerFilter.java | 15 ++++--- ...cketPPRPullRequestUpdatedActionFilter.java | 30 +++++++++----- ...PullRequestServerApprovedActionFilter.java | 24 ++++++----- ...questServerCommentCreatedActionFilter.java | 40 ++++++++++++------- ...RPullRequestServerCreatedActionFilter.java | 23 ++++++----- ...PullRequestServerDeclinedActionFilter.java | 21 +++++----- ...PRPullRequestServerMergedActionFilter.java | 20 +++++----- ...equestServerSourceUpdatedActionFilter.java | 29 ++++++++------ ...cketPPRPullRequestServerTriggerFilter.java | 17 ++++---- ...RPullRequestServerUpdatedActionFilter.java | 21 +++++----- 17 files changed, 261 insertions(+), 171 deletions(-) diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestApprovedActionFilter.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestApprovedActionFilter.java index 320572b..015aaed 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestApprovedActionFilter.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestApprovedActionFilter.java @@ -1,17 +1,17 @@ /******************************************************************************* * The MIT License - * + * * Copyright (C) 2020, CloudBees, Inc. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, @@ -19,7 +19,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ - package io.jenkins.plugins.bitbucketpushandpullrequest.filter.pullrequest.cloud; import static io.jenkins.plugins.bitbucketpushandpullrequest.common.BitBucketPPRConst.PULL_REQUEST_REVIEWER; @@ -27,6 +26,7 @@ import java.io.IOException; import java.util.logging.Logger; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; @@ -37,7 +37,6 @@ import io.jenkins.plugins.bitbucketpushandpullrequest.model.BitBucketPPRHookEvent; import io.jenkins.plugins.bitbucketpushandpullrequest.model.cloud.BitBucketPPRParticipant; - public class BitBucketPPRPullRequestApprovedActionFilter extends BitBucketPPRPullRequestActionFilter { private static final Logger logger = @@ -71,8 +70,8 @@ public boolean shouldTriggerBuild(BitBucketPPRAction bitbucketAction) { } @Override - public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction pullRequestAction, - BitBucketPPRHookEvent bitBucketEvent) + public BitBucketPPRTriggerCause getCause( + File pollingLog, BitBucketPPRAction pullRequestAction, BitBucketPPRHookEvent bitBucketEvent) throws IOException { return new BitBucketPPRPullRequestApprovedCause(pollingLog, pullRequestAction, bitBucketEvent); } @@ -81,12 +80,13 @@ public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction pul public boolean shouldSendApprove() { return false; } - + @Override public boolean shouldSendDecline() { return false; } + @Symbol("bitbucketCloudPullRequestApproved") @Extension public static class ActionFilterDescriptorImpl extends BitBucketPPRPullRequestActionDescriptor { @@ -102,7 +102,9 @@ public boolean getTriggerOnlyIfAllReviewersApproved() { private boolean allReviewersHaveApproved(BitBucketPPRAction pullRequestAction) { return pullRequestAction.getPayload().getPullRequest().getParticipants().stream() - .filter(p -> isReviewer(p) && !p.getApproved()).count() == 0; + .filter(p -> isReviewer(p) && !p.getApproved()) + .count() + == 0; } private boolean isReviewer(BitBucketPPRParticipant pullRequestParticipant) { diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCommentCreatedActionFilter.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCommentCreatedActionFilter.java index 2d069bc..9a0969c 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCommentCreatedActionFilter.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCommentCreatedActionFilter.java @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; @@ -64,22 +65,23 @@ public void setCommentFilter(String commentFilter) { @Override public boolean shouldTriggerBuild(BitBucketPPRAction bitbucketAction) { - return matches(allowedBranches, bitbucketAction.getTargetBranch(), null) && - hasInComment(bitbucketAction.getComment(), null); - } + return matches(allowedBranches, bitbucketAction.getTargetBranch(), null) + && hasInComment(bitbucketAction.getComment(), null); + } @Override - public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction pullRequestAction, - BitBucketPPRHookEvent bitBucketEvent) + public BitBucketPPRTriggerCause getCause( + File pollingLog, BitBucketPPRAction pullRequestAction, BitBucketPPRHookEvent bitBucketEvent) throws IOException { - return new BitBucketPPRPullRequestCommentCreatedCause(pollingLog, pullRequestAction, bitBucketEvent); + return new BitBucketPPRPullRequestCommentCreatedCause( + pollingLog, pullRequestAction, bitBucketEvent); } @Override public boolean shouldSendApprove() { return false; } - + @Override public boolean shouldSendDecline() { return false; @@ -89,6 +91,7 @@ public boolean hasInComment(String comment, EnvVars vars) { return BitBucketPPRUtils.matchWithRegex(comment, commentFilter, vars); } + @Symbol("bitbucketCloudPullRequestCommentCreated") @Extension public static class ActionFilterDescriptorImpl extends BitBucketPPRPullRequestActionDescriptor { @@ -100,8 +103,14 @@ public String getDisplayName() { @Override public String toString() { - return "BitBucketPPRPullRequestCommentCreatedActionFilter [getDescriptor()=" + getDescriptor() - + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" - + super.toString() + "]"; + return "BitBucketPPRPullRequestCommentCreatedActionFilter [getDescriptor()=" + + getDescriptor() + + ", getClass()=" + + getClass() + + ", hashCode()=" + + hashCode() + + ", toString()=" + + super.toString() + + "]"; } } diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCommentDeletedActionFilter.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCommentDeletedActionFilter.java index 23370e2..3d60b79 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCommentDeletedActionFilter.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCommentDeletedActionFilter.java @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; @@ -56,22 +57,24 @@ public boolean shouldTriggerBuild(BitBucketPPRAction bitbucketAction) { } @Override - public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction pullRequestAction, - BitBucketPPRHookEvent bitBucketEvent) + public BitBucketPPRTriggerCause getCause( + File pollingLog, BitBucketPPRAction pullRequestAction, BitBucketPPRHookEvent bitBucketEvent) throws IOException { - return new BitBucketPPRPullRequestCommentDeletedCause(pollingLog, pullRequestAction, bitBucketEvent); + return new BitBucketPPRPullRequestCommentDeletedCause( + pollingLog, pullRequestAction, bitBucketEvent); } @Override public boolean shouldSendApprove() { return false; } - + @Override public boolean shouldSendDecline() { return false; } + @Symbol("bitbucketCloudPullRequestCommentDeletedActionFilter") @Extension public static class ActionFilterDescriptorImpl extends BitBucketPPRPullRequestActionDescriptor { @@ -83,8 +86,14 @@ public String getDisplayName() { @Override public String toString() { - return "BitBucketPPRPullRequestCommentDeletedActionFilter [getDescriptor()=" + getDescriptor() - + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" - + super.toString() + "]"; + return "BitBucketPPRPullRequestCommentDeletedActionFilter [getDescriptor()=" + + getDescriptor() + + ", getClass()=" + + getClass() + + ", hashCode()=" + + hashCode() + + ", toString()=" + + super.toString() + + "]"; } } diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCommentUpdatedActionFilter.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCommentUpdatedActionFilter.java index c02342e..927c207 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCommentUpdatedActionFilter.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCommentUpdatedActionFilter.java @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; @@ -69,17 +70,18 @@ public boolean shouldTriggerBuild(BitBucketPPRAction bitbucketAction) { } @Override - public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction pullRequestAction, - BitBucketPPRHookEvent bitBucketEvent) + public BitBucketPPRTriggerCause getCause( + File pollingLog, BitBucketPPRAction pullRequestAction, BitBucketPPRHookEvent bitBucketEvent) throws IOException { - return new BitBucketPPRPullRequestCommentUpdatedCause(pollingLog, pullRequestAction, bitBucketEvent); + return new BitBucketPPRPullRequestCommentUpdatedCause( + pollingLog, pullRequestAction, bitBucketEvent); } @Override public boolean shouldSendApprove() { return false; } - + @Override public boolean shouldSendDecline() { return false; @@ -89,6 +91,7 @@ public boolean hasInComment(String comment, EnvVars vars) { return BitBucketPPRUtils.matchWithRegex(comment, commentFilter, vars); } + @Symbol("bitbucketCloudPullRequestCommentUpdated") @Extension public static class ActionFilterDescriptorImpl extends BitBucketPPRPullRequestActionDescriptor { @@ -100,8 +103,14 @@ public String getDisplayName() { @Override public String toString() { - return "BitBucketPPRPullRequestCommentUpdatedActionFilter [getDescriptor()=" + getDescriptor() - + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" - + super.toString() + "]"; + return "BitBucketPPRPullRequestCommentUpdatedActionFilter [getDescriptor()=" + + getDescriptor() + + ", getClass()=" + + getClass() + + ", hashCode()=" + + hashCode() + + ", toString()=" + + super.toString() + + "]"; } } diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCreatedActionFilter.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCreatedActionFilter.java index 352db1c..afdb4b9 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCreatedActionFilter.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCreatedActionFilter.java @@ -1,17 +1,17 @@ /******************************************************************************* * The MIT License - * + * * Copyright (C) 2020, CloudBees, Inc. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; @@ -56,7 +57,7 @@ public void setAllowedBranches(String allowedBranches) { public void setIsToApprove(boolean isToApprove) { this.isToApprove = isToApprove; } - + @DataBoundSetter public void setIsToDecline(boolean isToDecline) { this.isToDecline = isToDecline; @@ -68,8 +69,8 @@ public boolean shouldTriggerBuild(BitBucketPPRAction bitbucketAction) { } @Override - public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction pullRequestAction, - BitBucketPPRHookEvent bitBucketEvent) + public BitBucketPPRTriggerCause getCause( + File pollingLog, BitBucketPPRAction pullRequestAction, BitBucketPPRHookEvent bitBucketEvent) throws IOException { return new BitBucketPPRPullRequestCreatedCause(pollingLog, pullRequestAction, bitBucketEvent); } @@ -78,12 +79,13 @@ public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction pul public boolean shouldSendApprove() { return isToApprove; } - + @Override public boolean shouldSendDecline() { return isToDecline; } + @Symbol("bitbucketCloudPullRequestCreatedActionFilter") @Extension public static class ActionFilterDescriptorImpl extends BitBucketPPRPullRequestActionDescriptor { @@ -95,8 +97,14 @@ public String getDisplayName() { @Override public String toString() { - return "BitBucketPPRPullRequestCreatedActionFilter [getDescriptor()=" + getDescriptor() - + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" - + super.toString() + "]"; + return "BitBucketPPRPullRequestCreatedActionFilter [getDescriptor()=" + + getDescriptor() + + ", getClass()=" + + getClass() + + ", hashCode()=" + + hashCode() + + ", toString()=" + + super.toString() + + "]"; } } diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestDeclinedActionFilter.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestDeclinedActionFilter.java index e5a7898..9fc1fc3 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestDeclinedActionFilter.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestDeclinedActionFilter.java @@ -1,17 +1,17 @@ /******************************************************************************* * The MIT License - * + * * Copyright (C) 2019, CloudBees, Inc. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, @@ -26,18 +26,20 @@ import io.jenkins.plugins.bitbucketpushandpullrequest.cause.BitBucketPPRTriggerCause; import io.jenkins.plugins.bitbucketpushandpullrequest.cause.pullrequest.cloud.BitBucketPPRPullRequestDeclinedCause; import io.jenkins.plugins.bitbucketpushandpullrequest.model.BitBucketPPRHookEvent; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; import java.io.File; import java.io.IOException; -public class BitBucketPPRPullRequestDeclinedActionFilter extends BitBucketPPRPullRequestActionFilter { +public class BitBucketPPRPullRequestDeclinedActionFilter + extends BitBucketPPRPullRequestActionFilter { public String allowedBranches; @DataBoundConstructor public BitBucketPPRPullRequestDeclinedActionFilter() {} - + @DataBoundSetter public void setAllowedBranches(String allowedBranches) { if (allowedBranches == null) { @@ -53,8 +55,8 @@ public boolean shouldTriggerBuild(BitBucketPPRAction bitbucketAction) { } @Override - public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction pullRequestAction, - BitBucketPPRHookEvent bitBucketEvent) + public BitBucketPPRTriggerCause getCause( + File pollingLog, BitBucketPPRAction pullRequestAction, BitBucketPPRHookEvent bitBucketEvent) throws IOException { return new BitBucketPPRPullRequestDeclinedCause(pollingLog, pullRequestAction, bitBucketEvent); } @@ -68,7 +70,8 @@ public boolean shouldSendApprove() { public boolean shouldSendDecline() { return false; } - + + @Symbol("bitbucketCloudPullRequestDeclined") @Extension public static class ActionFilterDescriptorImpl extends BitBucketPPRPullRequestActionDescriptor { @@ -80,8 +83,14 @@ public String getDisplayName() { @Override public String toString() { - return "BitBucketPPRPullRequestDeclinedActionFilter [getDescriptor()=" + getDescriptor() - + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" - + super.toString() + "]"; + return "BitBucketPPRPullRequestDeclinedActionFilter [getDescriptor()=" + + getDescriptor() + + ", getClass()=" + + getClass() + + ", hashCode()=" + + hashCode() + + ", toString()=" + + super.toString() + + "]"; } } diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestMergedActionFilter.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestMergedActionFilter.java index 2c82522..f1d5492 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestMergedActionFilter.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestMergedActionFilter.java @@ -1,17 +1,17 @@ /******************************************************************************* * The MIT License - * + * * Copyright (C) 2019, CloudBees, Inc. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; @@ -39,7 +40,7 @@ public class BitBucketPPRPullRequestMergedActionFilter extends BitBucketPPRPullR @DataBoundConstructor public BitBucketPPRPullRequestMergedActionFilter() {} - + @DataBoundSetter public void setAllowedBranches(String allowedBranches) { if (allowedBranches == null) { @@ -53,15 +54,15 @@ public void setAllowedBranches(String allowedBranches) { public void setIsToApprove(boolean isToApprove) { this.isToApprove = isToApprove; } - + @Override public boolean shouldTriggerBuild(BitBucketPPRAction bitbucketAction) { return matches(allowedBranches, bitbucketAction.getTargetBranch(), null); } @Override - public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction pullRequestAction, - BitBucketPPRHookEvent bitBucketEvent) + public BitBucketPPRTriggerCause getCause( + File pollingLog, BitBucketPPRAction pullRequestAction, BitBucketPPRHookEvent bitBucketEvent) throws IOException { return new BitBucketPPRPullRequestUpdatedCause(pollingLog, pullRequestAction, bitBucketEvent); } @@ -70,12 +71,13 @@ public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction pul public boolean shouldSendApprove() { return isToApprove; } - + @Override public boolean shouldSendDecline() { return false; } + @Symbol("bitbucketCloudPullRequestMerged") @Extension public static class ActionFilterDescriptorImpl extends BitBucketPPRPullRequestActionDescriptor { @@ -87,8 +89,14 @@ public String getDisplayName() { @Override public String toString() { - return "BitBucketPPRPullRequestMergedActionFilter [getDescriptor()=" + getDescriptor() - + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" - + super.toString() + "]"; + return "BitBucketPPRPullRequestMergedActionFilter [getDescriptor()=" + + getDescriptor() + + ", getClass()=" + + getClass() + + ", hashCode()=" + + hashCode() + + ", toString()=" + + super.toString() + + "]"; } } diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestTriggerFilter.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestTriggerFilter.java index 0a39c2b..921ccb1 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestTriggerFilter.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestTriggerFilter.java @@ -1,17 +1,17 @@ /******************************************************************************* * The MIT License - * + * * Copyright (C) 2018, CloudBees, Inc. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, @@ -25,6 +25,7 @@ import java.io.IOException; import java.util.List; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import hudson.Extension; @@ -53,18 +54,20 @@ public boolean shouldScheduleJob(BitBucketPPRAction bitbucketAction) { public boolean shouldSendApprove() { return actionFilter.shouldSendApprove(); } - + @Override public boolean shouldSendDecline() { return actionFilter.shouldSendDecline(); } @Override - public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction action, BitBucketPPRHookEvent bitBucketEvent) + public BitBucketPPRTriggerCause getCause( + File pollingLog, BitBucketPPRAction action, BitBucketPPRHookEvent bitBucketEvent) throws IOException { return actionFilter.getCause(pollingLog, action, bitBucketEvent); } + @Symbol("bitbucketCloudPullRequest") @Extension public static class FilterDescriptorImpl extends BitBucketPPRTriggerFilterDescriptor { diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestUpdatedActionFilter.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestUpdatedActionFilter.java index 441cb83..86c5aef 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestUpdatedActionFilter.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestUpdatedActionFilter.java @@ -1,17 +1,17 @@ /******************************************************************************* * The MIT License - * + * * Copyright (C) 2018, CloudBees, Inc. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; @@ -56,7 +57,7 @@ public void setAllowedBranches(String allowedBranches) { public void setIsToApprove(boolean isToApprove) { this.isToApprove = isToApprove; } - + @DataBoundSetter public void setIsToDecline(boolean isToDecline) { this.isToDecline = isToDecline; @@ -66,7 +67,7 @@ public void setIsToDecline(boolean isToDecline) { public boolean shouldSendApprove() { return isToApprove; } - + @Override public boolean shouldSendDecline() { return isToDecline; @@ -78,12 +79,13 @@ public boolean shouldTriggerBuild(BitBucketPPRAction bitbucketAction) { } @Override - public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction pullRequestAction, - BitBucketPPRHookEvent bitBucketEvent) + public BitBucketPPRTriggerCause getCause( + File pollingLog, BitBucketPPRAction pullRequestAction, BitBucketPPRHookEvent bitBucketEvent) throws IOException { return new BitBucketPPRPullRequestUpdatedCause(pollingLog, pullRequestAction, bitBucketEvent); } + @Symbol("bitbucketCloudPullRequestUpdated") @Extension public static class ActionFilterDescriptorImpl extends BitBucketPPRPullRequestActionDescriptor { @@ -95,8 +97,14 @@ public String getDisplayName() { @Override public String toString() { - return "BitBucketPPRPullRequestUpdatedActionFilter [getDescriptor()=" + getDescriptor() - + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" - + super.toString() + "]"; + return "BitBucketPPRPullRequestUpdatedActionFilter [getDescriptor()=" + + getDescriptor() + + ", getClass()=" + + getClass() + + ", hashCode()=" + + hashCode() + + ", toString()=" + + super.toString() + + "]"; } } diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerApprovedActionFilter.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerApprovedActionFilter.java index a081eab..66806f3 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerApprovedActionFilter.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerApprovedActionFilter.java @@ -1,17 +1,17 @@ /******************************************************************************* * The MIT License - * + * * Copyright (C) 2019, CloudBees, Inc. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, @@ -19,7 +19,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ - package io.jenkins.plugins.bitbucketpushandpullrequest.filter.pullrequest.server; import static io.jenkins.plugins.bitbucketpushandpullrequest.common.BitBucketPPRConst.PULL_REQUEST_REVIEWER; @@ -27,6 +26,7 @@ import java.io.IOException; import java.util.logging.Logger; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; @@ -73,12 +73,14 @@ public boolean shouldTriggerBuild(BitBucketPPRAction bitbucketAction) { } @Override - public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction pullRequestAction, - BitBucketPPRHookEvent bitBucketEvent) + public BitBucketPPRTriggerCause getCause( + File pollingLog, BitBucketPPRAction pullRequestAction, BitBucketPPRHookEvent bitBucketEvent) throws IOException { - return new BitBucketPPRPullRequestServerApprovedCause(pollingLog, pullRequestAction, bitBucketEvent); + return new BitBucketPPRPullRequestServerApprovedCause( + pollingLog, pullRequestAction, bitBucketEvent); } + @Symbol("bitbucketServerPullRequestApproved") @Extension public static class ActionFilterDescriptorImpl extends BitBucketPPRPullRequestServerActionDescriptor { @@ -95,7 +97,9 @@ public boolean getTriggerOnlyIfAllReviewersApproved() { private boolean allReviewersHaveApproved(BitBucketPPRAction pullRequestAction) { return pullRequestAction.getPayload().getPullRequest().getParticipants().stream() - .filter(p -> isReviewer(p) && !p.getApproved()).count() == 0; + .filter(p -> isReviewer(p) && !p.getApproved()) + .count() + == 0; } private boolean isReviewer(BitBucketPPRParticipant pullRequestParticipant) { @@ -108,7 +112,7 @@ private boolean isReviewer(BitBucketPPRParticipant pullRequestParticipant) { public boolean shouldSendApprove() { return false; } - + @Override public boolean shouldSendDecline() { return false; diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerCommentCreatedActionFilter.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerCommentCreatedActionFilter.java index 6322d9b..23fd44b 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerCommentCreatedActionFilter.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerCommentCreatedActionFilter.java @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; @@ -35,14 +36,14 @@ import io.jenkins.plugins.bitbucketpushandpullrequest.common.BitBucketPPRUtils; import io.jenkins.plugins.bitbucketpushandpullrequest.model.BitBucketPPRHookEvent; -public class BitBucketPPRPullRequestServerCommentCreatedActionFilter extends BitBucketPPRPullRequestServerActionFilter { +public class BitBucketPPRPullRequestServerCommentCreatedActionFilter + extends BitBucketPPRPullRequestServerActionFilter { public String allowedBranches; public String commentFilter; @DataBoundConstructor - public BitBucketPPRPullRequestServerCommentCreatedActionFilter() { - } + public BitBucketPPRPullRequestServerCommentCreatedActionFilter() {} @DataBoundSetter public void setAllowedBranches(String allowedBranches) { @@ -64,22 +65,24 @@ public void setCommentFilter(String commentFilter) { @Override public boolean shouldTriggerBuild(BitBucketPPRAction bitbucketAction) { - return ( matches(allowedBranches, bitbucketAction.getTargetBranch(), null) - || matches(allowedBranches, bitbucketAction.getTargetBranchRefId(), null)) && - hasInComment(bitbucketAction.getServerComment(), null); - } + return (matches(allowedBranches, bitbucketAction.getTargetBranch(), null) + || matches(allowedBranches, bitbucketAction.getTargetBranchRefId(), null)) + && hasInComment(bitbucketAction.getServerComment(), null); + } @Override - public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction pullRequestAction, - BitBucketPPRHookEvent bitBucketEvent) throws IOException { - return new BitBucketPPRPullRequestServerCommentCreatedCause(pollingLog, pullRequestAction, bitBucketEvent); + public BitBucketPPRTriggerCause getCause( + File pollingLog, BitBucketPPRAction pullRequestAction, BitBucketPPRHookEvent bitBucketEvent) + throws IOException { + return new BitBucketPPRPullRequestServerCommentCreatedCause( + pollingLog, pullRequestAction, bitBucketEvent); } @Override public boolean shouldSendApprove() { return false; } - + @Override public boolean shouldSendDecline() { return false; @@ -89,8 +92,10 @@ public boolean hasInComment(String comment, EnvVars vars) { return BitBucketPPRUtils.matchWithRegex(comment, commentFilter, vars); } + @Symbol("bitbucketServerPullRequestCommentCreated") @Extension - public static class ActionFilterDescriptorImpl extends BitBucketPPRPullRequestServerActionDescriptor { + public static class ActionFilterDescriptorImpl + extends BitBucketPPRPullRequestServerActionDescriptor { @Override public String getDisplayName() { @@ -100,7 +105,14 @@ public String getDisplayName() { @Override public String toString() { - return "BitBucketPPRPullRequestServerCommentCreatedActionFilter [getDescriptor()=" + getDescriptor() - + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" + super.toString() + "]"; + return "BitBucketPPRPullRequestServerCommentCreatedActionFilter [getDescriptor()=" + + getDescriptor() + + ", getClass()=" + + getClass() + + ", hashCode()=" + + hashCode() + + ", toString()=" + + super.toString() + + "]"; } } diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerCreatedActionFilter.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerCreatedActionFilter.java index 49e8197..9f631d3 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerCreatedActionFilter.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerCreatedActionFilter.java @@ -1,17 +1,17 @@ /******************************************************************************* * The MIT License - * + * * Copyright (C) 2019, CloudBees, Inc. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, @@ -19,12 +19,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ - package io.jenkins.plugins.bitbucketpushandpullrequest.filter.pullrequest.server; import java.io.File; import java.io.IOException; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; @@ -34,7 +34,6 @@ import io.jenkins.plugins.bitbucketpushandpullrequest.cause.pullrequest.server.BitBucketPPRPullRequestServerCreatedCause; import io.jenkins.plugins.bitbucketpushandpullrequest.model.BitBucketPPRHookEvent; - public class BitBucketPPRPullRequestServerCreatedActionFilter extends BitBucketPPRPullRequestServerActionFilter { @@ -63,7 +62,7 @@ public void setIsToApprove(boolean isToApprove) { public void setIsToDecline(boolean isToDecline) { this.isToDecline = isToDecline; } - + @Override public boolean shouldTriggerBuild(BitBucketPPRAction bitbucketAction) { return matches(allowedBranches, bitbucketAction.getTargetBranch(), null) @@ -71,12 +70,14 @@ public boolean shouldTriggerBuild(BitBucketPPRAction bitbucketAction) { } @Override - public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction pullRequestAction, - BitBucketPPRHookEvent bitBucketEvent) + public BitBucketPPRTriggerCause getCause( + File pollingLog, BitBucketPPRAction pullRequestAction, BitBucketPPRHookEvent bitBucketEvent) throws IOException { - return new BitBucketPPRPullRequestServerCreatedCause(pollingLog, pullRequestAction, bitBucketEvent); + return new BitBucketPPRPullRequestServerCreatedCause( + pollingLog, pullRequestAction, bitBucketEvent); } + @Symbol("bitbucketServerPullRequestCreated") @Extension public static class ActionFilterDescriptorImpl extends BitBucketPPRPullRequestServerActionDescriptor { @@ -91,7 +92,7 @@ public String getDisplayName() { public boolean shouldSendApprove() { return isToApprove; } - + @Override public boolean shouldSendDecline() { return isToDecline; diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerDeclinedActionFilter.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerDeclinedActionFilter.java index a173765..ed6c236 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerDeclinedActionFilter.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerDeclinedActionFilter.java @@ -1,17 +1,17 @@ /******************************************************************************* * The MIT License - * + * * Copyright (C) 2019, CloudBees, Inc. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, @@ -19,7 +19,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ - package io.jenkins.plugins.bitbucketpushandpullrequest.filter.pullrequest.server; import hudson.Extension; @@ -27,13 +26,13 @@ import io.jenkins.plugins.bitbucketpushandpullrequest.cause.BitBucketPPRTriggerCause; import io.jenkins.plugins.bitbucketpushandpullrequest.cause.pullrequest.server.BitBucketPPRPullRequestServerDeclinedCause; import io.jenkins.plugins.bitbucketpushandpullrequest.model.BitBucketPPRHookEvent; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; import java.io.File; import java.io.IOException; - public class BitBucketPPRPullRequestServerDeclinedActionFilter extends BitBucketPPRPullRequestServerActionFilter { @@ -58,12 +57,14 @@ public boolean shouldTriggerBuild(BitBucketPPRAction bitbucketAction) { } @Override - public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction pullRequestAction, - BitBucketPPRHookEvent bitBucketEvent) + public BitBucketPPRTriggerCause getCause( + File pollingLog, BitBucketPPRAction pullRequestAction, BitBucketPPRHookEvent bitBucketEvent) throws IOException { - return new BitBucketPPRPullRequestServerDeclinedCause(pollingLog, pullRequestAction, bitBucketEvent); + return new BitBucketPPRPullRequestServerDeclinedCause( + pollingLog, pullRequestAction, bitBucketEvent); } + @Symbol("bitbucketServerPullRequestDeclined") @Extension public static class ActionFilterDescriptorImpl extends BitBucketPPRPullRequestServerActionDescriptor { @@ -78,7 +79,7 @@ public String getDisplayName() { public boolean shouldSendApprove() { return false; } - + @Override public boolean shouldSendDecline() { return false; diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerMergedActionFilter.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerMergedActionFilter.java index cfc3e77..8e1f2a1 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerMergedActionFilter.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerMergedActionFilter.java @@ -1,17 +1,17 @@ /******************************************************************************* * The MIT License - * + * * Copyright (C) 2019, CloudBees, Inc. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, @@ -19,12 +19,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ - package io.jenkins.plugins.bitbucketpushandpullrequest.filter.pullrequest.server; import java.io.File; import java.io.IOException; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; @@ -34,7 +34,6 @@ import io.jenkins.plugins.bitbucketpushandpullrequest.cause.pullrequest.server.BitBucketPPRPullRequestServerUpdatedCause; import io.jenkins.plugins.bitbucketpushandpullrequest.model.BitBucketPPRHookEvent; - public class BitBucketPPRPullRequestServerMergedActionFilter extends BitBucketPPRPullRequestServerActionFilter { @@ -65,12 +64,14 @@ public boolean shouldTriggerBuild(BitBucketPPRAction bitbucketAction) { } @Override - public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction pullRequestAction, - BitBucketPPRHookEvent bitBucketEvent) + public BitBucketPPRTriggerCause getCause( + File pollingLog, BitBucketPPRAction pullRequestAction, BitBucketPPRHookEvent bitBucketEvent) throws IOException { - return new BitBucketPPRPullRequestServerUpdatedCause(pollingLog, pullRequestAction, bitBucketEvent); + return new BitBucketPPRPullRequestServerUpdatedCause( + pollingLog, pullRequestAction, bitBucketEvent); } + @Symbol("bitbucketServerPullRequestMerged") @Extension public static class ActionFilterDescriptorImpl extends BitBucketPPRPullRequestServerActionDescriptor { @@ -90,5 +91,4 @@ public boolean shouldSendApprove() { public boolean shouldSendDecline() { return false; } - } diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerSourceUpdatedActionFilter.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerSourceUpdatedActionFilter.java index f93fc49..25280c2 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerSourceUpdatedActionFilter.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerSourceUpdatedActionFilter.java @@ -1,17 +1,17 @@ /******************************************************************************* * The MIT License - * + * * Copyright (C) 2019, CloudBees, Inc. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; @@ -33,15 +34,15 @@ import io.jenkins.plugins.bitbucketpushandpullrequest.cause.pullrequest.server.BitBucketPPRPullRequestServerUpdatedCause; import io.jenkins.plugins.bitbucketpushandpullrequest.model.BitBucketPPRHookEvent; -public class BitBucketPPRPullRequestServerSourceUpdatedActionFilter extends BitBucketPPRPullRequestServerActionFilter { +public class BitBucketPPRPullRequestServerSourceUpdatedActionFilter + extends BitBucketPPRPullRequestServerActionFilter { public String allowedBranches; public boolean isToApprove; public boolean isToDecline; @DataBoundConstructor - public BitBucketPPRPullRequestServerSourceUpdatedActionFilter() { - } + public BitBucketPPRPullRequestServerSourceUpdatedActionFilter() {} @DataBoundSetter public void setAllowedBranches(String allowedBranches) { @@ -56,7 +57,7 @@ public void setAllowedBranches(String allowedBranches) { public void setIsToApprove(boolean isToApprove) { this.isToApprove = isToApprove; } - + @DataBoundSetter public void setIsToDecline(boolean isToDecline) { this.isToDecline = isToDecline; @@ -69,13 +70,17 @@ public boolean shouldTriggerBuild(BitBucketPPRAction bitbucketAction) { } @Override - public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction pullRequestAction, - BitBucketPPRHookEvent bitBucketEvent) throws IOException { - return new BitBucketPPRPullRequestServerUpdatedCause(pollingLog, pullRequestAction, bitBucketEvent); + public BitBucketPPRTriggerCause getCause( + File pollingLog, BitBucketPPRAction pullRequestAction, BitBucketPPRHookEvent bitBucketEvent) + throws IOException { + return new BitBucketPPRPullRequestServerUpdatedCause( + pollingLog, pullRequestAction, bitBucketEvent); } + @Symbol("bitbucketServerPullRequestSourceUpdated") @Extension - public static class ActionFilterDescriptorImpl extends BitBucketPPRPullRequestServerActionDescriptor { + public static class ActionFilterDescriptorImpl + extends BitBucketPPRPullRequestServerActionDescriptor { @Override public String getDisplayName() { diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerTriggerFilter.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerTriggerFilter.java index 9804700..67d2999 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerTriggerFilter.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerTriggerFilter.java @@ -1,17 +1,17 @@ /******************************************************************************* * The MIT License - * + * * Copyright (C) 2020, CloudBees, Inc. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, @@ -19,12 +19,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ - package io.jenkins.plugins.bitbucketpushandpullrequest.filter.pullrequest.server; import java.io.File; import java.io.IOException; import java.util.List; + +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import hudson.Extension; import hudson.model.AbstractDescribableImpl; @@ -44,18 +45,19 @@ public BitBucketPPRPullRequestServerTriggerFilter( this.actionFilter = actionFilter; } - @Override public boolean shouldScheduleJob(BitBucketPPRAction bitbucketAction) { return actionFilter.shouldTriggerBuild(bitbucketAction); } @Override - public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction action, BitBucketPPRHookEvent bitBucketEvent) + public BitBucketPPRTriggerCause getCause( + File pollingLog, BitBucketPPRAction action, BitBucketPPRHookEvent bitBucketEvent) throws IOException { return actionFilter.getCause(pollingLog, action, bitBucketEvent); } + @Symbol("bitbucketServerPullRequest") @Extension public static class FilterDescriptorImpl extends BitBucketPPRTriggerFilterDescriptor { @@ -84,7 +86,6 @@ public boolean shouldSendApprove() { return actionFilter.shouldSendApprove(); } - @Override public boolean shouldSendDecline() { return actionFilter.shouldSendDecline(); diff --git a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerUpdatedActionFilter.java b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerUpdatedActionFilter.java index 48f2466..aae51f8 100644 --- a/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerUpdatedActionFilter.java +++ b/src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/server/BitBucketPPRPullRequestServerUpdatedActionFilter.java @@ -1,17 +1,17 @@ /******************************************************************************* * The MIT License - * + * * Copyright (C) 2019, CloudBees, Inc. - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, @@ -19,12 +19,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ - package io.jenkins.plugins.bitbucketpushandpullrequest.filter.pullrequest.server; import java.io.File; import java.io.IOException; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; @@ -34,7 +34,6 @@ import io.jenkins.plugins.bitbucketpushandpullrequest.cause.pullrequest.server.BitBucketPPRPullRequestServerUpdatedCause; import io.jenkins.plugins.bitbucketpushandpullrequest.model.BitBucketPPRHookEvent; - public class BitBucketPPRPullRequestServerUpdatedActionFilter extends BitBucketPPRPullRequestServerActionFilter { @@ -58,7 +57,7 @@ public void setAllowedBranches(String allowedBranches) { public void setIsToApprove(boolean isToApprove) { this.isToApprove = isToApprove; } - + @DataBoundSetter public void setIsToDecline(boolean isToDecline) { this.isToDecline = isToDecline; @@ -71,12 +70,14 @@ public boolean shouldTriggerBuild(BitBucketPPRAction bitbucketAction) { } @Override - public BitBucketPPRTriggerCause getCause(File pollingLog, BitBucketPPRAction pullRequestAction, - BitBucketPPRHookEvent bitBucketEvent) + public BitBucketPPRTriggerCause getCause( + File pollingLog, BitBucketPPRAction pullRequestAction, BitBucketPPRHookEvent bitBucketEvent) throws IOException { - return new BitBucketPPRPullRequestServerUpdatedCause(pollingLog, pullRequestAction, bitBucketEvent); + return new BitBucketPPRPullRequestServerUpdatedCause( + pollingLog, pullRequestAction, bitBucketEvent); } + @Symbol("bitbucketServerPullRequestUpdated") @Extension public static class ActionFilterDescriptorImpl extends BitBucketPPRPullRequestServerActionDescriptor { From e4760d6620d36d8b242fcb958e303bc287c5efa1 Mon Sep 17 00:00:00 2001 From: julioc-p <14-10820@usb.ve> Date: Thu, 26 Sep 2024 16:39:41 +0200 Subject: [PATCH 2/2] added test and example for declarative pipeline --- ...PRPullRequestApprovedActionFilterTest.java | 75 ++++++++++++++++++- ...loudTriggerPullRequestApprovedActionFilter | 33 ++++++++ 2 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 src/test/resources/pipelines/testPipelineCloudTriggerPullRequestApprovedActionFilter diff --git a/src/test/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestApprovedActionFilterTest.java b/src/test/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestApprovedActionFilterTest.java index 7522b28..a38e6c2 100644 --- a/src/test/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestApprovedActionFilterTest.java +++ b/src/test/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestApprovedActionFilterTest.java @@ -1,15 +1,44 @@ package io.jenkins.plugins.bitbucketpushandpullrequest.filter.pullrequest.cloud; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import hudson.model.FreeStyleProject; +import hudson.triggers.Trigger; +import hudson.triggers.TriggerDescriptor; +import io.jenkins.plugins.bitbucketpushandpullrequest.BitBucketPPRTrigger; +import javaposse.jobdsl.plugin.ExecuteDslScripts; +import javaposse.jobdsl.plugin.RemovedJobAction; +import org.apache.commons.io.IOUtils; +import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; +import org.jenkinsci.plugins.workflow.job.WorkflowJob; +import org.jenkinsci.plugins.workflow.job.WorkflowRun; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; +import org.jvnet.hudson.test.JenkinsRule; import org.mockito.junit.MockitoJUnitRunner; import hudson.EnvVars; +import static org.junit.Assert.*; + @RunWith(MockitoJUnitRunner.class) public class BitBucketPPRPullRequestApprovedActionFilterTest { + @Rule public JenkinsRule j = new JenkinsRule(); + + private void createSeedJob(String script) throws Exception { + WorkflowJob pipelineJob = j.createProject(WorkflowJob.class, "pipelineJob"); + + // Set the pipeline script (like setting a Jenkinsfile) + pipelineJob.setDefinition(new CpsFlowDefinition(script, true)); + + // Build and assert that it succeeded + j.buildAndAssertSuccess(pipelineJob); + } @Test public void testMatches() { @@ -133,7 +162,6 @@ public void testUsesRefsHeads() { new BitBucketPPRPullRequestApprovedActionFilter(false); c.setAllowedBranches(allowedBranches); - assertTrue(c.matches(allowedBranches, "refs/heads/jenkins", null)); assertTrue(c.matches(allowedBranches, "refs/heads/jane", null)); assertTrue(c.matches(allowedBranches, "refs/heads/jones", null)); @@ -197,7 +225,6 @@ public void testMatchesEmptyBranches() { assertTrue(c.matches(allowedBranches, "feature/new-stuff", null)); } - @Test public void testUsesJavaPatternWithRepetition() { String allowedBranches = ":origin/release-\\d{8}"; @@ -227,4 +254,44 @@ public void testUsesJavaPatternToExcludeMultipleBranches() { assertFalse(c.matches(allowedBranches, "origin/master", null)); assertFalse(c.matches(allowedBranches, "origin/develop", null)); } + + private String readScript(String path) throws Exception { + String script = null; + try { + ClassLoader classloader = Thread.currentThread().getContextClassLoader(); + InputStream is = classloader.getResourceAsStream(path); + script = IOUtils.toString(is, StandardCharsets.UTF_8); + } catch (Exception e) { + e.printStackTrace(); + } + return script; + } + + @Test + public void testPipelineTrigger() throws Exception { + + createSeedJob( + readScript("./pipelines/testPipelineCloudTriggerPullRequestApprovedActionFilter")); + // get newly created pipeline job + WorkflowJob createdJob = (WorkflowJob) j.getInstance().getItem("pipelineJob"); + assert createdJob != null; + Map> triggers = createdJob.getTriggers(); + assertEquals(1, triggers.size()); + List dispNames = new ArrayList<>(); + boolean isToApprove = false; + for (Trigger entry : triggers.values()) { + BitBucketPPRTrigger tmp2 = (BitBucketPPRTrigger) entry; + assertEquals(1, tmp2.getTriggers().size()); + String tmpName = tmp2.getTriggers().get(0).getActionFilter().getClass().getName(); + String dispName = tmpName.substring(tmpName.lastIndexOf(".") + 1); + dispNames.add(dispName); + BitBucketPPRPullRequestApprovedActionFilter tmp3 = + (BitBucketPPRPullRequestApprovedActionFilter) tmp2.getTriggers().get(0).getActionFilter(); + isToApprove = tmp3.shouldSendApprove(); + } + + assertEquals(1, dispNames.size()); + assertEquals(dispNames.get(0), "BitBucketPPRPullRequestApprovedActionFilter"); + assertFalse(isToApprove); + } } diff --git a/src/test/resources/pipelines/testPipelineCloudTriggerPullRequestApprovedActionFilter b/src/test/resources/pipelines/testPipelineCloudTriggerPullRequestApprovedActionFilter new file mode 100644 index 0000000..1d32d47 --- /dev/null +++ b/src/test/resources/pipelines/testPipelineCloudTriggerPullRequestApprovedActionFilter @@ -0,0 +1,33 @@ +properties([ + pipelineTriggers([ + bitBucketTrigger( + triggers: [ + bitbucketCloudPullRequest( + actionFilter: + bitbucketCloudPullRequestApproved( + triggerOnlyIfAllReviewersApproved: false + ) + ) + ] + ) + ]) +]) + +pipeline { + agent any + + stages { + stage('Build') { + steps { + echo 'Building...' + echo 'Env vars for cloud pull request...' + echo "BITBUCKET_SOURCE_BRANCH ${env.BITBUCKET_SOURCE_BRANCH}" + echo "BITBUCKET_TARGET_BRANCH ${env.BITBUCKET_TARGET_BRANCH}" + echo "BITBUCKET_PULL_REQUEST_LINK ${env.BITBUCKET_PULL_REQUEST_LINK}" + echo "BITBUCKET_PULL_REQUEST_ID ${env.BITBUCKET_PULL_REQUEST_ID}" + echo "BITBUCKET_PAYLOAD ${env.BITBUCKET_PAYLOAD}" + echo "branch feature/test-branch" + } + } + } +}