Skip to content

Commit

Permalink
[JENKINS-48035] Add a GitHubRepositoryNameContributor that recognises…
Browse files Browse the repository at this point in the history
… multi branch

The existing name contributors could only find the repo name if a build
of a branch had been made and added git build data to the job.
Since branches are discovered and built after GitHubSCMSource.afterSaved is called
there was no repo names recognised to add webhooks to.

This only solves the case when a single multi branch project is created.
Because when an org folder creates the multi branch jobs it does not call
afterSaved on the children. So that needs to be fixed someplace else.
  • Loading branch information
rsandell committed Dec 11, 2017
1 parent aa3e8bd commit 9213e3b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pom.xml
Expand Up @@ -23,7 +23,7 @@
<properties>
<jenkins.version>1.642.3</jenkins.version>
<workflow.version>1.14.2</workflow.version>
<scm-api.version>2.2.0</scm-api.version>
<scm-api.version>2.2.3</scm-api.version>
</properties>

<scm>
Expand Down Expand Up @@ -68,6 +68,11 @@
<artifactId>display-url-api</artifactId>
<version>0.2</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>branch-api</artifactId>
<version>2.0.16</version>
</dependency>
<!-- Currently just here for interactive testing via hpi:run: -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -88,12 +93,6 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>branch-api</artifactId>
<version>2.0.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-aggregator</artifactId>
Expand Down
@@ -0,0 +1,30 @@
package org.jenkinsci.plugins.github_branch_source;

import com.cloudbees.jenkins.GitHubRepositoryName;
import com.cloudbees.jenkins.GitHubRepositoryNameContributor;
import hudson.Extension;
import hudson.model.Item;
import jenkins.branch.MultiBranchProject;

import java.util.Collection;

@Extension
public class GitHubSCMSourceRepositoryNameContributor extends GitHubRepositoryNameContributor {

@Override
public void parseAssociatedNames(Item item, Collection<GitHubRepositoryName> result) {
if (item instanceof MultiBranchProject) {
MultiBranchProject mp = (MultiBranchProject) item;
for (Object o : mp.getSCMSources()) {
if (o instanceof GitHubSCMSource) {
GitHubSCMSource gitHubSCMSource = (GitHubSCMSource) o;
result.add(new GitHubRepositoryName(
RepositoryUriResolver.hostnameFromApiUri(gitHubSCMSource.getApiUri()),
gitHubSCMSource.getRepoOwner(),
gitHubSCMSource.getRepository()));

}
}
}
}
}

0 comments on commit 9213e3b

Please sign in to comment.