com.cloudbees.jenkins.GitHubWebHook Java Examples

The following examples show how to use com.cloudbees.jenkins.GitHubWebHook. 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: GitHubSCMNavigator.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void afterSave(@NonNull SCMNavigatorOwner owner) {
    GitHubWebHook.get().registerHookFor(owner);
    try {
        // FIXME MINOR HACK ALERT
        StandardCredentials credentials = Connector.lookupScanCredentials((Item)owner, getApiUri(), credentialsId);
        GitHub hub = Connector.connect(getApiUri(), credentials);
        try {
            GitHubOrgWebHook.register(hub, repoOwner);
        } finally {
            Connector.release(hub);
        }
    } catch (IOException e) {
        DescriptorImpl.LOGGER.log(Level.WARNING, e.getMessage(), e);
    }
}
 
Example #2
Source File: GitHubSCMSource.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void afterSave() {
    SCMSourceOwner owner = getOwner();
    if (owner != null) {
        GitHubWebHook.get().registerHookFor(owner);
    }
}
 
Example #3
Source File: GitHubTriggerDescriptor.java    From github-integration-plugin with MIT License 5 votes vote down vote up
public String getJenkinsURL() {
    String url = getPublishedURL();
    if (isNotBlank(url)) {
        if (!url.endsWith("/")) {
            url += "/";
        }
        return url;
    }
    return GitHubWebHook.getJenkinsInstance().getRootUrl();
}
 
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);
}
 
Example #5
Source File: GitHubPluginRepoProvider.java    From github-integration-plugin with MIT License 4 votes vote down vote up
@Override
public void registerHookFor(GitHubTrigger trigger) {
    GitHubWebHook.get().registerHookFor(trigger.getJob());
}
 
Example #6
Source File: GitHubPluginRepoProvider2.java    From github-integration-plugin with MIT License 4 votes vote down vote up
@Override
public void registerHookFor(GitHubSCMSource source) {
    // ideally register hook for source and not for owner with iterations
    GitHubWebHook.get().registerHookFor(source.getOwner());
}