Skip to content

[JENKINS-75691] Add trait to include the ref spec of target branch of pull requests #1047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@
import com.cloudbees.jenkins.plugins.bitbucket.Messages;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Extension;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.trait.SCMSourceContext;
import jenkins.scm.api.trait.SCMSourceTrait;
import jenkins.scm.api.trait.SCMSourceTraitDescriptor;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
Expand Down Expand Up @@ -146,7 +144,7 @@ protected void decorateContext(SCMSourceContext<?, ?> context) {
*/
@Symbol("bitbucketBuildStatusNotifications")
@Extension
public static class DescriptorImpl extends SCMSourceTraitDescriptor {
public static class DescriptorImpl extends BitbucketSCMSourceTraitDescriptor {

/**
* {@inheritDoc}
Expand All @@ -156,20 +154,5 @@ public String getDisplayName() {
return Messages.BitbucketBuildStatusNotificationsTrait_displayName();
}

/**
* {@inheritDoc}
*/
@Override
public Class<? extends SCMSourceContext> getContextClass() {
return BitbucketSCMSourceContext.class;
}

/**
* {@inheritDoc}
*/
@Override
public Class<? extends SCMSource> getSourceClass() {
return BitbucketSCMSource.class;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* The MIT License
*
* Copyright (c) 2025, Falco Nikolas
*
* 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 com.cloudbees.jenkins.plugins.bitbucket.trait;

import com.cloudbees.jenkins.plugins.bitbucket.BitbucketGitSCMBuilder;
import com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource;
import com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSourceContext;
import hudson.model.Descriptor;
import hudson.plugins.git.GitSCM;
import hudson.scm.SCM;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.trait.SCMBuilder;
import jenkins.scm.api.trait.SCMSourceContext;
import jenkins.scm.api.trait.SCMSourceTrait;
import jenkins.scm.api.trait.SCMSourceTraitDescriptor;

/**
* Abstract base class for {@link Descriptor} of {@link SCMSourceTrait}
* implementations specific for bitbucket.
*
* @since 936.3.0
*/
abstract class BitbucketSCMSourceTraitDescriptor extends SCMSourceTraitDescriptor {

/**
* {@inheritDoc}
*/
@SuppressWarnings("rawtypes")
@Override
public Class<? extends SCMSourceContext> getContextClass() {
return BitbucketSCMSourceContext.class;
}

/**
* {@inheritDoc}
*/
@Override
public Class<? extends SCMSource> getSourceClass() {
return BitbucketSCMSource.class;

Check warning on line 60 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/trait/BitbucketSCMSourceTraitDescriptor.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 60 is not covered by tests
}

/**
* {@inheritDoc}
*/
@SuppressWarnings("rawtypes")
@Override
public Class<? extends SCMBuilder> getBuilderClass() {
return BitbucketGitSCMBuilder.class;
}

/**
* {@inheritDoc}
*/
@Override
public Class<? extends SCM> getScmClass() {
return GitSCM.class;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package com.cloudbees.jenkins.plugins.bitbucket.trait;

import com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource;
import com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSourceContext;
import com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSourceRequest;
import com.cloudbees.jenkins.plugins.bitbucket.BranchSCMHead;
Expand All @@ -38,14 +37,12 @@
import jenkins.scm.api.SCMHeadCategory;
import jenkins.scm.api.SCMHeadOrigin;
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.trait.SCMHeadAuthority;
import jenkins.scm.api.trait.SCMHeadAuthorityDescriptor;
import jenkins.scm.api.trait.SCMHeadFilter;
import jenkins.scm.api.trait.SCMSourceContext;
import jenkins.scm.api.trait.SCMSourceRequest;
import jenkins.scm.api.trait.SCMSourceTrait;
import jenkins.scm.api.trait.SCMSourceTraitDescriptor;
import jenkins.scm.impl.trait.Discovery;
import org.apache.commons.lang3.StringUtils;
import org.jenkinsci.Symbol;
Expand Down Expand Up @@ -158,7 +155,7 @@ public boolean includeCategory(@NonNull SCMHeadCategory category) {
@Symbol("bitbucketBranchDiscovery")
@Extension
@Discovery
public static class DescriptorImpl extends SCMSourceTraitDescriptor {
public static class DescriptorImpl extends BitbucketSCMSourceTraitDescriptor {

/**
* {@inheritDoc}
Expand All @@ -168,30 +165,13 @@ public String getDisplayName() {
return Messages.BranchDiscoveryTrait_displayName();
}

/**
* {@inheritDoc}
*/
@Override
public Class<? extends SCMSourceContext> getContextClass() {
return BitbucketSCMSourceContext.class;
}

/**
* {@inheritDoc}
*/
@Override
public Class<? extends SCMSource> getSourceClass() {
return BitbucketSCMSource.class;
}

/**
* Populates the strategy options.
*
* @return the strategy options.
*/
@NonNull
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // stapler
public ListBoxModel doFillStrategyIdItems() {
ListBoxModel result = new ListBoxModel();
result.add(Messages.BranchDiscoveryTrait_excludePRs(), "1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package com.cloudbees.jenkins.plugins.bitbucket.trait;

import com.cloudbees.jenkins.plugins.bitbucket.BitbucketGitSCMBuilder;
import com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSourceRequest;
import com.cloudbees.jenkins.plugins.bitbucket.Messages;
import com.cloudbees.jenkins.plugins.bitbucket.PullRequestSCMHead;
Expand All @@ -35,12 +34,10 @@
import java.io.IOException;
import java.time.LocalDate;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.trait.SCMBuilder;
import jenkins.scm.api.trait.SCMHeadFilter;
import jenkins.scm.api.trait.SCMSourceContext;
import jenkins.scm.api.trait.SCMSourceRequest;
import jenkins.scm.api.trait.SCMSourceTrait;
import jenkins.scm.api.trait.SCMSourceTraitDescriptor;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
Expand Down Expand Up @@ -109,11 +106,11 @@
*/
@Symbol("bitbucketDiscardOldBranch")
@Extension
public static class DescriptorImpl extends SCMSourceTraitDescriptor {
public static class DescriptorImpl extends BitbucketSCMSourceTraitDescriptor {

public FormValidation doCheckKeepForDays(@QueryParameter final int keepForDays) {
if (keepForDays <= 0) {
return FormValidation.error("Invalid value. Days must be greater than 0");
return FormValidation.error(Messages.DiscardOldBranchTrait_invalidDays());

Check warning on line 113 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/trait/DiscardOldBranchTrait.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 113 is not covered by tests
}
return FormValidation.ok();
}
Expand All @@ -123,13 +120,6 @@
return Messages.DiscardOldBranchTrait_displayName();
}

/**
* {@inheritDoc}
*/
@Override
public boolean isApplicableToBuilder(@SuppressWarnings("rawtypes") @NonNull Class<? extends SCMBuilder> builderClass) {
return BitbucketGitSCMBuilder.class.isAssignableFrom(builderClass);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package com.cloudbees.jenkins.plugins.bitbucket.trait;

import com.cloudbees.jenkins.plugins.bitbucket.BitbucketGitSCMBuilder;
import com.cloudbees.jenkins.plugins.bitbucket.Messages;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
Expand All @@ -33,11 +32,9 @@
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.mixin.TagSCMHead;
import jenkins.scm.api.trait.SCMBuilder;
import jenkins.scm.api.trait.SCMHeadPrefilter;
import jenkins.scm.api.trait.SCMSourceContext;
import jenkins.scm.api.trait.SCMSourceTrait;
import jenkins.scm.api.trait.SCMSourceTraitDescriptor;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
Expand Down Expand Up @@ -96,11 +93,11 @@

@Symbol("bitbucketDiscardOldTag")
@Extension
public static class DescriptorImpl extends SCMSourceTraitDescriptor {
public static class DescriptorImpl extends BitbucketSCMSourceTraitDescriptor {

public FormValidation doCheckKeepForDays(@QueryParameter int keepForDays) {
if (keepForDays <= 0) {
return FormValidation.error("Invalid value. Days must be greater than 0");
return FormValidation.error(Messages.DiscardOldTagTrait_invalidDays());

Check warning on line 100 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/trait/DiscardOldTagTrait.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 100 is not covered by tests
}
return FormValidation.ok();
}
Expand All @@ -110,10 +107,6 @@
return Messages.DiscardOldTagTrait_displayName();
}

@Override
public boolean isApplicableToBuilder(@NonNull Class<? extends SCMBuilder> builderClass) {
return BitbucketGitSCMBuilder.class.isAssignableFrom(builderClass);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package com.cloudbees.jenkins.plugins.bitbucket.trait;

import com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource;
import com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSourceContext;
import com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSourceRequest;
import com.cloudbees.jenkins.plugins.bitbucket.Messages;
Expand All @@ -39,14 +38,12 @@
import jenkins.scm.api.SCMHeadCategory;
import jenkins.scm.api.SCMHeadOrigin;
import jenkins.scm.api.SCMRevision;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy;
import jenkins.scm.api.mixin.ChangeRequestSCMHead2;
import jenkins.scm.api.trait.SCMHeadAuthority;
import jenkins.scm.api.trait.SCMHeadAuthorityDescriptor;
import jenkins.scm.api.trait.SCMSourceContext;
import jenkins.scm.api.trait.SCMSourceTrait;
import jenkins.scm.api.trait.SCMSourceTraitDescriptor;
import jenkins.scm.impl.ChangeRequestSCMHeadCategory;
import jenkins.scm.impl.trait.Discovery;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -166,7 +163,7 @@ public boolean includeCategory(@NonNull SCMHeadCategory category) {
@Symbol("bitbucketForkDiscovery")
@Extension
@Discovery
public static class DescriptorImpl extends SCMSourceTraitDescriptor {
public static class DescriptorImpl extends BitbucketSCMSourceTraitDescriptor {

/**
* {@inheritDoc}
Expand All @@ -176,30 +173,13 @@ public String getDisplayName() {
return Messages.ForkPullRequestDiscoveryTrait_displayName();
}

/**
* {@inheritDoc}
*/
@Override
public Class<? extends SCMSourceContext> getContextClass() {
return BitbucketSCMSourceContext.class;
}

/**
* {@inheritDoc}
*/
@Override
public Class<? extends SCMSource> getSourceClass() {
return BitbucketSCMSource.class;
}

/**
* Populates the strategy options.
*
* @return the strategy options.
*/
@NonNull
@Restricted(NoExternalUse.class)
@SuppressWarnings("unused") // stapler
public ListBoxModel doFillStrategyIdItems() {
ListBoxModel result = new ListBoxModel();
result.add(Messages.ForkPullRequestDiscoveryTrait_mergeOnly(), "1");
Expand All @@ -213,8 +193,8 @@ public ListBoxModel doFillStrategyIdItems() {
*
* @return the list of appropriate {@link SCMHeadAuthorityDescriptor} instances.
*/
@SuppressWarnings("unchecked")
@NonNull
@SuppressWarnings("unused") // stapler
public List<SCMHeadAuthorityDescriptor> getTrustDescriptors() {
return SCMHeadAuthority._for(
BitbucketSCMSourceRequest.class,
Expand All @@ -230,7 +210,6 @@ public List<SCMHeadAuthorityDescriptor> getTrustDescriptors() {
* @return the default trust for new instances of {@link ForkPullRequestDiscoveryTrait}.
*/
@NonNull
@SuppressWarnings("unused") // stapler
public SCMHeadAuthority<?, ?, ?> getDefaultTrust() {
return new TrustTeamForks();
}
Expand Down
Loading
Loading