Search in sources :

Example 1 with ForkPullRequestDiscoveryTrait

use of com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait in project blueocean-plugin by jenkinsci.

the class BitbucketPipelineCreateRequestTest method createdWithTraits.

@Test
public void createdWithTraits() throws Exception {
    String credentialId = createCredential(BitbucketServerScm.ID);
    Map r = new PipelineBaseTest.RequestBuilder(baseUrl).status(201).jwtToken(getJwtToken(j.jenkins, authenticatedUser.getId(), authenticatedUser.getId())).crumb(crumb).post("/organizations/jenkins/pipelines/").data(MapsHelper.of("name", "pipeline1", "$class", "io.jenkins.blueocean.blueocean_bitbucket_pipeline.BitbucketPipelineCreateRequest", "scmConfig", MapsHelper.of("id", BitbucketServerScm.ID, "credentialId", credentialId, "uri", apiUrl, "config", MapsHelper.of("repoOwner", "TESTP", "repository", "pipeline-demo-test")))).build(Map.class);
    assertNotNull(r);
    assertEquals("pipeline1", r.get("name"));
    MultiBranchProject mbp = (MultiBranchProject) j.getInstance().getItem("pipeline1");
    BitbucketSCMSource source = (BitbucketSCMSource) mbp.getSCMSources().get(0);
    List<SCMSourceTrait> traits = source.getTraits();
    Assert.assertNotNull(SCMTrait.find(traits, CleanAfterCheckoutTrait.class));
    Assert.assertNotNull(SCMTrait.find(traits, CleanBeforeCheckoutTrait.class));
    Assert.assertNotNull(SCMTrait.find(traits, LocalBranchTrait.class));
    BranchDiscoveryTrait branchDiscoveryTrait = SCMTrait.find(traits, BranchDiscoveryTrait.class);
    Assert.assertNotNull(branchDiscoveryTrait);
    Assert.assertTrue(branchDiscoveryTrait.isBuildBranch());
    Assert.assertTrue(branchDiscoveryTrait.isBuildBranchesWithPR());
    ForkPullRequestDiscoveryTrait forkPullRequestDiscoveryTrait = SCMTrait.find(traits, ForkPullRequestDiscoveryTrait.class);
    Assert.assertNotNull(forkPullRequestDiscoveryTrait);
    Assert.assertTrue(forkPullRequestDiscoveryTrait.getTrust() instanceof ForkPullRequestDiscoveryTrait.TrustTeamForks);
    Assert.assertEquals(1, forkPullRequestDiscoveryTrait.getStrategies().size());
    Assert.assertTrue(forkPullRequestDiscoveryTrait.getStrategies().contains(ChangeRequestCheckoutStrategy.MERGE));
    OriginPullRequestDiscoveryTrait originPullRequestDiscoveryTrait = SCMTrait.find(traits, OriginPullRequestDiscoveryTrait.class);
    Assert.assertNotNull(originPullRequestDiscoveryTrait);
    Assert.assertEquals(1, originPullRequestDiscoveryTrait.getStrategies().size());
    Assert.assertTrue(originPullRequestDiscoveryTrait.getStrategies().contains(ChangeRequestCheckoutStrategy.MERGE));
}
Also used : OriginPullRequestDiscoveryTrait(com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait) CleanBeforeCheckoutTrait(jenkins.plugins.git.traits.CleanBeforeCheckoutTrait) ForkPullRequestDiscoveryTrait(com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait) CleanAfterCheckoutTrait(jenkins.plugins.git.traits.CleanAfterCheckoutTrait) SCMSourceTrait(jenkins.scm.api.trait.SCMSourceTrait) MultiBranchProject(jenkins.branch.MultiBranchProject) Map(java.util.Map) LocalBranchTrait(jenkins.plugins.git.traits.LocalBranchTrait) BranchDiscoveryTrait(com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait) BitbucketSCMSource(com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Example 2 with ForkPullRequestDiscoveryTrait

use of com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait in project blueocean-plugin by jenkinsci.

the class BitbucketPipelineCreateRequest method createSource.

@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
@Override
protected SCMSource createSource(@Nonnull MultiBranchProject project, @Nonnull BlueScmConfig scmConfig) {
    /* scmConfig.uri presence is already validated in {@link #validate} but lets check just in case */
    if (StringUtils.isBlank(scmConfig.getUri())) {
        throw new ServiceException.BadRequestException("scmConfig.uri must be present");
    }
    Set<ChangeRequestCheckoutStrategy> strategies = new HashSet<>();
    strategies.add(ChangeRequestCheckoutStrategy.MERGE);
    BitbucketSCMSource bitbucketSCMSource = new BitbucketSCMSourceBuilder(null, scmConfig.getUri(), computeCredentialId(scmConfig), (String) scmConfig.getConfig().get("repoOwner"), (String) scmConfig.getConfig().get("repository")).withTrait(// take all branches
    new BranchDiscoveryTrait(true, true)).withTrait(new ForkPullRequestDiscoveryTrait(strategies, new ForkPullRequestDiscoveryTrait.TrustTeamForks())).withTrait(new OriginPullRequestDiscoveryTrait(strategies)).withTrait(new CleanBeforeCheckoutTrait()).withTrait(new CleanAfterCheckoutTrait()).withTrait(new LocalBranchTrait()).build();
    // Setup Jenkins root url, if not set bitbucket cloud notification will fail
    JenkinsLocationConfiguration jenkinsLocationConfiguration = JenkinsLocationConfiguration.get();
    if (jenkinsLocationConfiguration != null) {
        String url = jenkinsLocationConfiguration.getUrl();
        if (url == null) {
            url = Jenkins.get().getRootUrl();
            if (url != null) {
                jenkinsLocationConfiguration.setUrl(url);
            }
        }
    }
    return bitbucketSCMSource;
}
Also used : OriginPullRequestDiscoveryTrait(com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait) JenkinsLocationConfiguration(jenkins.model.JenkinsLocationConfiguration) CleanBeforeCheckoutTrait(jenkins.plugins.git.traits.CleanBeforeCheckoutTrait) BitbucketSCMSourceBuilder(com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSourceBuilder) ChangeRequestCheckoutStrategy(jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy) ForkPullRequestDiscoveryTrait(com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait) CleanAfterCheckoutTrait(jenkins.plugins.git.traits.CleanAfterCheckoutTrait) LocalBranchTrait(jenkins.plugins.git.traits.LocalBranchTrait) BranchDiscoveryTrait(com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait) HashSet(java.util.HashSet) BitbucketSCMSource(com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

BitbucketSCMSource (com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource)2 BranchDiscoveryTrait (com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait)2 ForkPullRequestDiscoveryTrait (com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait)2 OriginPullRequestDiscoveryTrait (com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait)2 CleanAfterCheckoutTrait (jenkins.plugins.git.traits.CleanAfterCheckoutTrait)2 CleanBeforeCheckoutTrait (jenkins.plugins.git.traits.CleanBeforeCheckoutTrait)2 LocalBranchTrait (jenkins.plugins.git.traits.LocalBranchTrait)2 BitbucketSCMSourceBuilder (com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSourceBuilder)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 PipelineBaseTest (io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 MultiBranchProject (jenkins.branch.MultiBranchProject)1 JenkinsLocationConfiguration (jenkins.model.JenkinsLocationConfiguration)1 ChangeRequestCheckoutStrategy (jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy)1 SCMSourceTrait (jenkins.scm.api.trait.SCMSourceTrait)1 Test (org.junit.Test)1