diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/ForkPullRequestDiscoveryTrait.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/ForkPullRequestDiscoveryTrait.java index f7bf3e7d0..495380b21 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/ForkPullRequestDiscoveryTrait.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/ForkPullRequestDiscoveryTrait.java @@ -39,7 +39,6 @@ import jenkins.scm.api.trait.SCMHeadAuthority; import jenkins.scm.api.trait.SCMHeadAuthorityDescriptor; 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.ChangeRequestSCMHeadCategory; @@ -83,6 +82,12 @@ public class ForkPullRequestDiscoveryTrait extends SCMSourceTrait { * @param trust the authority to use. */ @DataBoundConstructor + public ForkPullRequestDiscoveryTrait(int strategyId, @NonNull GitHubForkTrustPolicy trust) { + this.strategyId = strategyId; + this.trust = trust; + } + + @Deprecated public ForkPullRequestDiscoveryTrait( int strategyId, @NonNull @@ -236,9 +241,15 @@ public List getTrustDescriptors() { } } + /** Trust policy for forked pull requests. + *

+ * This reduces generics in the DataBoundConstructor signature as a workaround for JENKINS-26535. + */ + public abstract static class GitHubForkTrustPolicy + extends SCMHeadAuthority {} + /** An {@link SCMHeadAuthority} that trusts nothing. */ - public static class TrustNobody - extends SCMHeadAuthority { + public static class TrustNobody extends GitHubForkTrustPolicy { /** Constructor. */ @DataBoundConstructor @@ -246,7 +257,7 @@ public TrustNobody() {} /** {@inheritDoc} */ @Override - public boolean checkTrusted(@NonNull SCMSourceRequest request, @NonNull PullRequestSCMHead head) { + public boolean checkTrusted(@NonNull GitHubSCMSourceRequest request, @NonNull PullRequestSCMHead head) { return false; } @@ -270,8 +281,7 @@ public boolean isApplicableToOrigin(@NonNull Class orig } /** An {@link SCMHeadAuthority} that trusts contributors to the repository. */ - public static class TrustContributors - extends SCMHeadAuthority { + public static class TrustContributors extends GitHubForkTrustPolicy { /** Constructor. */ @DataBoundConstructor public TrustContributors() {} @@ -303,8 +313,7 @@ public boolean isApplicableToOrigin(@NonNull Class orig } /** An {@link SCMHeadAuthority} that trusts those with write permission to the repository. */ - public static class TrustPermission - extends SCMHeadAuthority { + public static class TrustPermission extends GitHubForkTrustPolicy { /** Constructor. */ @DataBoundConstructor @@ -347,15 +356,14 @@ public boolean isApplicableToOrigin(@NonNull Class orig } /** An {@link SCMHeadAuthority} that trusts everyone. */ - public static class TrustEveryone - extends SCMHeadAuthority { + public static class TrustEveryone extends GitHubForkTrustPolicy { /** Constructor. */ @DataBoundConstructor public TrustEveryone() {} /** {@inheritDoc} */ @Override - protected boolean checkTrusted(@NonNull SCMSourceRequest request, @NonNull PullRequestSCMHead head) { + protected boolean checkTrusted(@NonNull GitHubSCMSourceRequest request, @NonNull PullRequestSCMHead head) { return true; } diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/ForkPullRequestDiscoveryTrait2Test.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/ForkPullRequestDiscoveryTrait2Test.java index 91ef0c4d5..cb61162c6 100644 --- a/src/test/java/org/jenkinsci/plugins/github_branch_source/ForkPullRequestDiscoveryTrait2Test.java +++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/ForkPullRequestDiscoveryTrait2Test.java @@ -28,9 +28,6 @@ import java.util.Collections; import java.util.List; import jenkins.branch.BranchSource; -import jenkins.scm.api.SCMRevision; -import jenkins.scm.api.mixin.ChangeRequestSCMHead2; -import jenkins.scm.api.trait.SCMHeadAuthority; import jenkins.scm.api.trait.SCMSourceTrait; import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject; import org.junit.Ignore; @@ -69,8 +66,7 @@ public void configRoundtripWithRawUrl() throws Exception { private void assertRoundTrip( WorkflowMultiBranchProject p, - SCMHeadAuthority - trust, + ForkPullRequestDiscoveryTrait.GitHubForkTrustPolicy trust, boolean configuredByUrl) throws Exception {