use of org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait 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();
}
use of org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait in project blueocean-plugin by jenkinsci.
the class GithubPipelineCreateRequestTest method createPipeline.
@Test
public void createPipeline() throws UnirestException, IOException {
String credentialId = createGithubCredential(user);
Map r = new PipelineBaseTest.RequestBuilder(baseUrl).status(201).jwtToken(getJwtToken(j.jenkins, user.getId(), user.getId())).post("/organizations/jenkins/pipelines/").data(ImmutableMap.of("name", "pipeline1", "$class", "io.jenkins.blueocean.blueocean_github_pipeline.GithubPipelineCreateRequest", "scmConfig", ImmutableMap.of("id", GithubScm.ID, "uri", githubApiUrl, "credentialId", credentialId, "config", ImmutableMap.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));
}
Aggregations