Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-48035] Add a GitHubRepositoryNameContributor that recognises…
… 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
Showing
2 changed files
with
36 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
.../org/jenkinsci/plugins/github_branch_source/GitHubSCMSourceRepositoryNameContributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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())); | ||
|
||
} | ||
} | ||
} | ||
} | ||
} |