Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #12 from jcarsique/master

Also trigger jobs with GitHub repositories configured via MultipleSCMs plugin
  • Loading branch information...
commit 8924ab2d1ba091d1ee57bcb155c38c4b5387787b 2 parents 64482a8 + da993ac
Seiji Sogabe ssogabe authored
108 pom.xml
@@ -6,59 +6,65 @@
6 6 <version>1.445</version>
7 7 </parent>
8 8
9   - <groupId>com.coravy.hudson.plugins.github</groupId>
10   - <artifactId>github</artifactId>
11   - <packaging>hpi</packaging>
12   - <version>1.1-SNAPSHOT</version>
13   - <name>GitHub plugin</name>
14   - <url>http://wiki.jenkins-ci.org/display/JENKINS/Github+Plugin</url>
  9 + <groupId>com.coravy.hudson.plugins.github</groupId>
  10 + <artifactId>github</artifactId>
  11 + <packaging>hpi</packaging>
  12 + <version>1.1-SNAPSHOT</version>
  13 + <name>GitHub plugin</name>
  14 + <url>http://wiki.jenkins-ci.org/display/JENKINS/Github+Plugin</url>
15 15
16   - <repositories>
17   - <repository>
18   - <id>jgit-repository</id>
19   - <name>Eclipse JGit Repository</name>
20   - <url>http://download.eclipse.org/jgit/maven</url>
21   - </repository>
22   - </repositories>
  16 + <repositories>
  17 + <repository>
  18 + <id>jgit-repository</id>
  19 + <name>Eclipse JGit Repository</name>
  20 + <url>http://download.eclipse.org/jgit/maven</url>
  21 + </repository>
  22 + </repositories>
23 23
24   - <developers>
25   - <developer>
26   - <id>kohsuke</id>
27   - <name>Kohsuke Kawaguchi</name>
28   - </developer>
29   - <developer>
30   - <id>juretta</id>
31   - <name>Stefan Saasen</name>
32   - </developer>
33   - </developers>
  24 + <developers>
  25 + <developer>
  26 + <id>kohsuke</id>
  27 + <name>Kohsuke Kawaguchi</name>
  28 + </developer>
  29 + <developer>
  30 + <id>juretta</id>
  31 + <name>Stefan Saasen</name>
  32 + </developer>
  33 + </developers>
34 34
35   - <dependencies>
36   - <dependency>
37   - <groupId>org.jenkins-ci.plugins</groupId>
38   - <artifactId>github-api</artifactId>
39   - <version>1.16</version>
40   - </dependency>
41   - <dependency>
42   - <groupId>org.jenkinsci.plugins</groupId>
43   - <artifactId>git</artifactId>
44   - <version>1.1.12</version>
45   - </dependency>
46   - <dependency>
47   - <groupId>org.jmock</groupId>
48   - <artifactId>jmock-junit4</artifactId>
49   - <version>2.5.1</version>
50   - <scope>test</scope>
51   - </dependency>
52   - <dependency>
53   - <groupId>org.eclipse.jgit</groupId>
54   - <artifactId>org.eclipse.jgit</artifactId>
55   - <version>0.12.1</version>
56   - </dependency>
57   - </dependencies>
  35 + <dependencies>
  36 + <dependency>
  37 + <groupId>org.jenkins-ci.plugins</groupId>
  38 + <artifactId>github-api</artifactId>
  39 + <version>1.16</version>
  40 + </dependency>
  41 + <dependency>
  42 + <groupId>org.jenkinsci.plugins</groupId>
  43 + <artifactId>git</artifactId>
  44 + <version>1.1.12</version>
  45 + </dependency>
  46 + <dependency>
  47 + <groupId>org.jmock</groupId>
  48 + <artifactId>jmock-junit4</artifactId>
  49 + <version>2.5.1</version>
  50 + <scope>test</scope>
  51 + </dependency>
  52 + <dependency>
  53 + <groupId>org.eclipse.jgit</groupId>
  54 + <artifactId>org.eclipse.jgit</artifactId>
  55 + <version>0.12.1</version>
  56 + </dependency>
  57 + <dependency>
  58 + <groupId>org.jenkins-ci.plugins</groupId>
  59 + <artifactId>multiple-scms</artifactId>
  60 + <version>0.2</version>
  61 + <optional>true</optional>
  62 + </dependency>
  63 + </dependencies>
58 64
59   - <scm>
60   - <connection>scm:git:git://github.com/jenkinsci/github-plugin.git</connection>
61   - <developerConnection>scm:git:git@github.com:jenkinsci/github-plugin.git</developerConnection>
62   - <url>https://github.com/jenkinsci/github-plugin</url>
63   - </scm>
  65 + <scm>
  66 + <connection>scm:git:git://github.com/jenkinsci/github-plugin.git</connection>
  67 + <developerConnection>scm:git:git@github.com:jenkinsci/github-plugin.git</developerConnection>
  68 + <url>https://github.com/jenkinsci/github-plugin</url>
  69 + </scm>
64 70 </project>
49 src/main/java/com/cloudbees/jenkins/GitHubPushTrigger.java
@@ -3,10 +3,10 @@
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;
@@ -14,13 +14,6 @@
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,8 +32,16 @@
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 comments on commit 8924ab2

Please sign in to comment.
Something went wrong with that request. Please try again.