|
3 | 3 | import hudson.Extension; |
4 | 4 | import hudson.Util; |
5 | 5 | import hudson.console.AnnotatedLargeText; |
6 | | -import hudson.model.AbstractProject; |
7 | 6 | import hudson.model.Action; |
8 | 7 | import hudson.model.Hudson; |
9 | 8 | import hudson.model.Item; |
| 9 | +import hudson.model.AbstractProject; |
10 | 10 | import hudson.model.Project; |
11 | 11 | import hudson.plugins.git.GitSCM; |
12 | 12 | import hudson.scm.SCM; |
13 | 13 | import hudson.triggers.Trigger; |
14 | 14 | import hudson.triggers.TriggerDescriptor; |
15 | 15 | import hudson.util.SequentialExecutionQueue; |
16 | 16 | import hudson.util.StreamTaskListener; |
17 | | -import net.sf.json.JSONObject; |
18 | | -import org.apache.commons.jelly.XMLOutput; |
19 | | -import org.kohsuke.github.GHRepository; |
20 | | -import org.kohsuke.stapler.DataBoundConstructor; |
21 | | -import org.kohsuke.stapler.StaplerRequest; |
22 | | -import org.eclipse.jgit.transport.RemoteConfig; |
23 | | -import org.eclipse.jgit.transport.URIish; |
24 | 17 |
|
25 | 18 | import java.io.File; |
26 | 19 | import java.io.IOException; |
|
39 | 32 | import java.util.concurrent.Executors; |
40 | 33 | import java.util.logging.Level; |
41 | 34 | import java.util.logging.Logger; |
42 | | -import java.util.regex.Matcher; |
43 | | -import java.util.regex.Pattern; |
| 35 | + |
| 36 | +import net.sf.json.JSONObject; |
| 37 | + |
| 38 | +import org.apache.commons.jelly.XMLOutput; |
| 39 | +import org.eclipse.jgit.transport.RemoteConfig; |
| 40 | +import org.eclipse.jgit.transport.URIish; |
| 41 | +import org.jenkinsci.plugins.multiplescms.MultiSCM; |
| 42 | +import org.kohsuke.github.GHRepository; |
| 43 | +import org.kohsuke.stapler.DataBoundConstructor; |
| 44 | +import org.kohsuke.stapler.StaplerRequest; |
44 | 45 |
|
45 | 46 | /** |
46 | 47 | * Triggers a build when we receive a GitHub post-commit webhook. |
@@ -91,24 +92,40 @@ public void run() { |
91 | 92 | } |
92 | 93 |
|
93 | 94 | /** |
94 | | - * Does this project read from a repository of the given user name and the given repository name? |
| 95 | + * Does this project read from a repository of the given user name and the |
| 96 | + * given repository name? |
95 | 97 | */ |
96 | 98 | public Set<GitHubRepositoryName> getGitHubRepositories() { |
97 | 99 | Set<GitHubRepositoryName> r = new HashSet<GitHubRepositoryName>(); |
98 | | - SCM scm = job.getScm(); |
| 100 | + if (Hudson.getInstance().getPlugin("multiple-scms") != null |
| 101 | + && job.getScm() instanceof MultiSCM) { |
| 102 | + MultiSCM multiSCM = (MultiSCM) job.getScm(); |
| 103 | + List<SCM> scmList = multiSCM.getConfiguredSCMs(); |
| 104 | + for (SCM scm : scmList) { |
| 105 | + addRepositories(r, scm); |
| 106 | + } |
| 107 | + } else { |
| 108 | + addRepositories(r, job.getScm()); |
| 109 | + } |
| 110 | + return r; |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * @since 1.1 |
| 115 | + */ |
| 116 | + protected void addRepositories(Set<GitHubRepositoryName> r, SCM scm) { |
99 | 117 | if (scm instanceof GitSCM) { |
100 | 118 | GitSCM git = (GitSCM) scm; |
101 | 119 | for (RemoteConfig rc : git.getRepositories()) { |
102 | 120 | for (URIish uri : rc.getURIs()) { |
103 | 121 | String url = uri.toString(); |
104 | | - GitHubRepositoryName repo = GitHubRepositoryName.create(uri |
105 | | - .toString()); |
106 | | - if (repo != null) |
| 122 | + GitHubRepositoryName repo = GitHubRepositoryName.create(url); |
| 123 | + if (repo != null) { |
107 | 124 | r.add(repo); |
| 125 | + } |
108 | 126 | } |
109 | 127 | } |
110 | 128 | } |
111 | | - return r; |
112 | 129 | } |
113 | 130 |
|
114 | 131 | @Override |
|
0 commit comments