Search in sources :

Example 1 with OriginPullRequestDiscoveryTrait

use of org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait in project blueocean-plugin by jenkinsci.

the class GithubPipelineCreateRequest method createSource.

@Override
protected SCMSource createSource(@Nonnull MultiBranchProject project, @Nonnull BlueScmConfig scmConfig) {
    // Update endpoint only if its GitHub Enterprise
    if (scmConfig.getId().equals(GithubEnterpriseScm.ID)) {
        updateEndpoints(scmConfig.getUri());
    }
    Set<ChangeRequestCheckoutStrategy> strategies = new HashSet<>();
    strategies.add(ChangeRequestCheckoutStrategy.MERGE);
    return new GitHubSCMSourceBuilder(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.TrustPermission())).withTrait(new OriginPullRequestDiscoveryTrait(strategies)).withTrait(new CleanBeforeCheckoutTrait()).withTrait(new CleanAfterCheckoutTrait()).withTrait(new LocalBranchTrait()).build();
}
Also used : ForkPullRequestDiscoveryTrait(org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait) OriginPullRequestDiscoveryTrait(org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait) CleanAfterCheckoutTrait(jenkins.plugins.git.traits.CleanAfterCheckoutTrait) CleanBeforeCheckoutTrait(jenkins.plugins.git.traits.CleanBeforeCheckoutTrait) GitHubSCMSourceBuilder(org.jenkinsci.plugins.github_branch_source.GitHubSCMSourceBuilder) LocalBranchTrait(jenkins.plugins.git.traits.LocalBranchTrait) ChangeRequestCheckoutStrategy(jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy) BranchDiscoveryTrait(org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait) HashSet(java.util.HashSet)

Example 2 with OriginPullRequestDiscoveryTrait

use of org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait in project blueocean-plugin by jenkinsci.

the class GithubPipelineCreateRequestTest method createPipeline.

@Test
public void createPipeline() throws UnirestException {
    PowerMockito.mockStatic(GitHubWebHook.class);
    GitHubWebHook gitHubWebHookMock = Mockito.spy(GitHubWebHook.class);
    PowerMockito.when(GitHubWebHook.get()).thenReturn(gitHubWebHookMock);
    PowerMockito.when(GitHubWebHook.getJenkinsInstance()).thenReturn(this.j.jenkins);
    String credentialId = createGithubCredential(user);
    Map r = new PipelineBaseTest.RequestBuilder(baseUrl).status(201).jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId())).crumb(this.crumb).post("/organizations/jenkins/pipelines/").data(MapsHelper.of("name", "pipeline1", "$class", "io.jenkins.blueocean.blueocean_github_pipeline.GithubPipelineCreateRequest", "scmConfig", MapsHelper.of("id", GithubScm.ID, "uri", githubApiUrl, "credentialId", credentialId, "config", MapsHelper.of("repoOwner", "cloudbeers", "repository", "PR-demo")))).build(Map.class);
    assertNotNull(r);
    assertEquals("pipeline1", r.get("name"));
    MultiBranchProject mbp = (MultiBranchProject) j.getInstance().getItem("pipeline1");
    GitHubSCMSource source = (GitHubSCMSource) 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.TrustPermission);
    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));
    Mockito.verify(gitHubWebHookMock, Mockito.times(1)).registerHookFor(mbp);
}
Also used : GitHubWebHook(com.cloudbees.jenkins.GitHubWebHook) OriginPullRequestDiscoveryTrait(org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait) CleanBeforeCheckoutTrait(jenkins.plugins.git.traits.CleanBeforeCheckoutTrait) GitHubSCMSource(org.jenkinsci.plugins.github_branch_source.GitHubSCMSource) ForkPullRequestDiscoveryTrait(org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait) CleanAfterCheckoutTrait(jenkins.plugins.git.traits.CleanAfterCheckoutTrait) SCMSourceTrait(jenkins.scm.api.trait.SCMSourceTrait) WorkflowMultiBranchProject(org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject) MultiBranchProject(jenkins.branch.MultiBranchProject) Map(java.util.Map) LocalBranchTrait(jenkins.plugins.git.traits.LocalBranchTrait) BranchDiscoveryTrait(org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Aggregations

CleanAfterCheckoutTrait (jenkins.plugins.git.traits.CleanAfterCheckoutTrait)2 CleanBeforeCheckoutTrait (jenkins.plugins.git.traits.CleanBeforeCheckoutTrait)2 LocalBranchTrait (jenkins.plugins.git.traits.LocalBranchTrait)2 BranchDiscoveryTrait (org.jenkinsci.plugins.github_branch_source.BranchDiscoveryTrait)2 ForkPullRequestDiscoveryTrait (org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait)2 OriginPullRequestDiscoveryTrait (org.jenkinsci.plugins.github_branch_source.OriginPullRequestDiscoveryTrait)2 GitHubWebHook (com.cloudbees.jenkins.GitHubWebHook)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 ChangeRequestCheckoutStrategy (jenkins.scm.api.mixin.ChangeRequestCheckoutStrategy)1 SCMSourceTrait (jenkins.scm.api.trait.SCMSourceTrait)1 GitHubSCMSource (org.jenkinsci.plugins.github_branch_source.GitHubSCMSource)1 GitHubSCMSourceBuilder (org.jenkinsci.plugins.github_branch_source.GitHubSCMSourceBuilder)1 WorkflowMultiBranchProject (org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1