Skip to content

Commit

Permalink
Reformat declarative pipeline (#344)
Browse files Browse the repository at this point in the history
* added symbol annotations for easier naming in pipeline

* added test and example for declarative pipeline
  • Loading branch information
julioc-p authored Sep 26, 2024
1 parent e33f7f1 commit 4217fb7
Show file tree
Hide file tree
Showing 19 changed files with 365 additions and 175 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
/*******************************************************************************
* 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,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* 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;
import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;

import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

Expand All @@ -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 =
Expand Down Expand Up @@ -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);
}
Expand All @@ -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 {

Expand All @@ -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()

Check warning on line 106 in src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestApprovedActionFilter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 105-106 are not covered by tests
== 0;
}

private boolean isReviewer(BitBucketPPRParticipant pullRequestParticipant) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -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()

Check warning on line 113 in src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCommentCreatedActionFilter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 68-113 are not covered by tests
+ "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {

Expand All @@ -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()

Check warning on line 96 in src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCommentDeletedActionFilter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 63-96 are not covered by tests
+ "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -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()

Check warning on line 113 in src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCommentUpdatedActionFilter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 76-113 are not covered by tests
+ "]";
}
}
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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 {

Expand All @@ -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()

Check warning on line 107 in src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/filter/pullrequest/cloud/BitBucketPPRPullRequestCreatedActionFilter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 100-107 are not covered by tests
+ "]";
}
}
Loading

0 comments on commit 4217fb7

Please sign in to comment.