Java Code Examples for jenkins.scm.api.trait.SCMTrait#find()

The following examples show how to use jenkins.scm.api.trait.SCMTrait#find() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GithubOrganizationFolder.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Override
public boolean isScanAllRepos() {
    if(!getFolder().getSCMNavigators().isEmpty()) {
        SCMNavigator scmNavigator = getFolder().getSCMNavigators().get(0);
        if(scmNavigator instanceof GitHubSCMNavigator){
            GitHubSCMNavigator gitHubSCMNavigator = (GitHubSCMNavigator) scmNavigator;
            WildcardSCMHeadFilterTrait wildcardTraits = SCMTrait.find(gitHubSCMNavigator.getTraits(), WildcardSCMHeadFilterTrait.class);
            return wildcardTraits == null
                    || ((StringUtils.isBlank(wildcardTraits.getIncludes()) || wildcardTraits.getIncludes().equals("*"))
                    && StringUtils.isBlank(wildcardTraits.getExcludes()));
        }
    }
    return super.isScanAllRepos();
}
 
Example 2
Source File: GerritSCMSource.java    From gerrit-code-review-plugin with Apache License 2.0 4 votes vote down vote up
@Restricted(DoNotUse.class)
public boolean isIgnoreOnPushNotifications() {
  return SCMTrait.find(traits, IgnoreOnPushNotificationTrait.class) != null;
}
 
Example 3
Source File: BitbucketPipelineCreateRequestTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@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(ImmutableMap.of(
            "name","pipeline1",
            "$class", "io.jenkins.blueocean.blueocean_bitbucket_pipeline.BitbucketPipelineCreateRequest",
            "scmConfig", ImmutableMap.of(
                "id", BitbucketServerScm.ID,
                "credentialId", credentialId,
                "uri", apiUrl,
                "config", ImmutableMap.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));
}
 
Example 4
Source File: GithubPipelineCreateRequestTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Test
public void createPipeline() throws UnirestException, IOException {
    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(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));
    Mockito.verify(gitHubWebHookMock, Mockito.times(1)).registerHookFor(mbp);
}