Permalink
Browse files

Merge pull request #12 from jcarsique/master

Also trigger jobs with GitHub repositories configured via MultipleSCMs plugin
  • Loading branch information...
2 parents 64482a8 + da993ac commit 8924ab2d1ba091d1ee57bcb155c38c4b5387787b @ssogabe ssogabe committed Feb 8, 2012
Showing with 90 additions and 67 deletions.
  1. +57 −51 pom.xml
  2. +33 −16 src/main/java/com/cloudbees/jenkins/GitHubPushTrigger.java
View
108 pom.xml
@@ -6,59 +6,65 @@
<version>1.445</version>
</parent>
- <groupId>com.coravy.hudson.plugins.github</groupId>
- <artifactId>github</artifactId>
- <packaging>hpi</packaging>
- <version>1.1-SNAPSHOT</version>
- <name>GitHub plugin</name>
- <url>http://wiki.jenkins-ci.org/display/JENKINS/Github+Plugin</url>
+ <groupId>com.coravy.hudson.plugins.github</groupId>
+ <artifactId>github</artifactId>
+ <packaging>hpi</packaging>
+ <version>1.1-SNAPSHOT</version>
+ <name>GitHub plugin</name>
+ <url>http://wiki.jenkins-ci.org/display/JENKINS/Github+Plugin</url>
- <repositories>
- <repository>
- <id>jgit-repository</id>
- <name>Eclipse JGit Repository</name>
- <url>http://download.eclipse.org/jgit/maven</url>
- </repository>
- </repositories>
+ <repositories>
+ <repository>
+ <id>jgit-repository</id>
+ <name>Eclipse JGit Repository</name>
+ <url>http://download.eclipse.org/jgit/maven</url>
+ </repository>
+ </repositories>
- <developers>
- <developer>
- <id>kohsuke</id>
- <name>Kohsuke Kawaguchi</name>
- </developer>
- <developer>
- <id>juretta</id>
- <name>Stefan Saasen</name>
- </developer>
- </developers>
+ <developers>
+ <developer>
+ <id>kohsuke</id>
+ <name>Kohsuke Kawaguchi</name>
+ </developer>
+ <developer>
+ <id>juretta</id>
+ <name>Stefan Saasen</name>
+ </developer>
+ </developers>
- <dependencies>
- <dependency>
- <groupId>org.jenkins-ci.plugins</groupId>
- <artifactId>github-api</artifactId>
- <version>1.16</version>
- </dependency>
- <dependency>
- <groupId>org.jenkinsci.plugins</groupId>
- <artifactId>git</artifactId>
- <version>1.1.12</version>
- </dependency>
- <dependency>
- <groupId>org.jmock</groupId>
- <artifactId>jmock-junit4</artifactId>
- <version>2.5.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jgit</groupId>
- <artifactId>org.eclipse.jgit</artifactId>
- <version>0.12.1</version>
- </dependency>
- </dependencies>
+ <dependencies>
+ <dependency>
+ <groupId>org.jenkins-ci.plugins</groupId>
+ <artifactId>github-api</artifactId>
+ <version>1.16</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jenkinsci.plugins</groupId>
+ <artifactId>git</artifactId>
+ <version>1.1.12</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jmock</groupId>
+ <artifactId>jmock-junit4</artifactId>
+ <version>2.5.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jgit</groupId>
+ <artifactId>org.eclipse.jgit</artifactId>
+ <version>0.12.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jenkins-ci.plugins</groupId>
+ <artifactId>multiple-scms</artifactId>
+ <version>0.2</version>
+ <optional>true</optional>
+ </dependency>
+ </dependencies>
- <scm>
- <connection>scm:git:git://github.com/jenkinsci/github-plugin.git</connection>
- <developerConnection>scm:git:git@github.com:jenkinsci/github-plugin.git</developerConnection>
- <url>https://github.com/jenkinsci/github-plugin</url>
- </scm>
+ <scm>
+ <connection>scm:git:git://github.com/jenkinsci/github-plugin.git</connection>
+ <developerConnection>scm:git:git@github.com:jenkinsci/github-plugin.git</developerConnection>
+ <url>https://github.com/jenkinsci/github-plugin</url>
+ </scm>
</project>
View
49 src/main/java/com/cloudbees/jenkins/GitHubPushTrigger.java
@@ -3,24 +3,17 @@
import hudson.Extension;
import hudson.Util;
import hudson.console.AnnotatedLargeText;
-import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.Hudson;
import hudson.model.Item;
+import hudson.model.AbstractProject;
import hudson.model.Project;
import hudson.plugins.git.GitSCM;
import hudson.scm.SCM;
import hudson.triggers.Trigger;
import hudson.triggers.TriggerDescriptor;
import hudson.util.SequentialExecutionQueue;
import hudson.util.StreamTaskListener;
-import net.sf.json.JSONObject;
-import org.apache.commons.jelly.XMLOutput;
-import org.kohsuke.github.GHRepository;
-import org.kohsuke.stapler.DataBoundConstructor;
-import org.kohsuke.stapler.StaplerRequest;
-import org.eclipse.jgit.transport.RemoteConfig;
-import org.eclipse.jgit.transport.URIish;
import java.io.File;
import java.io.IOException;
@@ -39,8 +32,16 @@
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+
+import net.sf.json.JSONObject;
+
+import org.apache.commons.jelly.XMLOutput;
+import org.eclipse.jgit.transport.RemoteConfig;
+import org.eclipse.jgit.transport.URIish;
+import org.jenkinsci.plugins.multiplescms.MultiSCM;
+import org.kohsuke.github.GHRepository;
+import org.kohsuke.stapler.DataBoundConstructor;
+import org.kohsuke.stapler.StaplerRequest;
/**
* Triggers a build when we receive a GitHub post-commit webhook.
@@ -91,24 +92,40 @@ public void run() {
}
/**
- * Does this project read from a repository of the given user name and the given repository name?
+ * Does this project read from a repository of the given user name and the
+ * given repository name?
*/
public Set<GitHubRepositoryName> getGitHubRepositories() {
Set<GitHubRepositoryName> r = new HashSet<GitHubRepositoryName>();
- SCM scm = job.getScm();
+ if (Hudson.getInstance().getPlugin("multiple-scms") != null
+ && job.getScm() instanceof MultiSCM) {
+ MultiSCM multiSCM = (MultiSCM) job.getScm();
+ List<SCM> scmList = multiSCM.getConfiguredSCMs();
+ for (SCM scm : scmList) {
+ addRepositories(r, scm);
+ }
+ } else {
+ addRepositories(r, job.getScm());
+ }
+ return r;
+ }
+
+ /**
+ * @since 1.1
+ */
+ protected void addRepositories(Set<GitHubRepositoryName> r, SCM scm) {
if (scm instanceof GitSCM) {
GitSCM git = (GitSCM) scm;
for (RemoteConfig rc : git.getRepositories()) {
for (URIish uri : rc.getURIs()) {
String url = uri.toString();
- GitHubRepositoryName repo = GitHubRepositoryName.create(uri
- .toString());
- if (repo != null)
+ GitHubRepositoryName repo = GitHubRepositoryName.create(url);
+ if (repo != null) {
r.add(repo);
+ }
}
}
}
- return r;
}
@Override

0 comments on commit 8924ab2

Please sign in to comment.