Permalink
Browse files

git browser url

  • Loading branch information...
1 parent 7646a24 commit 7d6c29ff7c60588b149012fd2349e7e888321b69 joewilliams committed Sep 5, 2011
Showing with 33 additions and 12 deletions.
  1. +0 −5 pom.xml
  2. +33 −7 src/main/java/hudson/plugins/boundary/Boundary.java
View
5 pom.xml
@@ -55,11 +55,6 @@
<artifactId>git</artifactId>
<version>1.1.12</version>
</dependency>
- <dependency>
- <groupId>com.coravy.hudson.plugins.github</groupId>
- <artifactId>github</artifactId>
- <version>0.7</version>
- </dependency>
</dependencies>
<build>
<plugins>
View
40 src/main/java/hudson/plugins/boundary/Boundary.java
@@ -4,10 +4,13 @@
import hudson.model.AbstractBuild;
import hudson.model.Hudson;
+import hudson.plugins.git.GitSCM;
+import hudson.plugins.git.browser.GitRepositoryBrowser;
+import hudson.plugins.git.browser.GitWeb;
+import hudson.plugins.git.browser.GithubWeb;
+import hudson.plugins.git.browser.GitoriousWeb;
import hudson.plugins.git.util.BuildData;
-
-import com.coravy.hudson.plugins.github.GithubUrl;
-import com.coravy.hudson.plugins.github.GithubProjectProperty;
+import hudson.scm.SCM;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
@@ -63,14 +66,37 @@ public void annotate(AbstractBuild<?, ?> build)
Map<String, String> linkThree = new HashMap<String, String>();
linkThree.put("rel", "version");
- linkThree.put("href", ""); // get github or gitweb link
-
BuildData data = build.getAction(BuildData.class);
if (data != null) {
- String rev = data.getLastBuiltRevision().getSha1String();
+ // Grab the SHA1
+ String rev = data.getLastBuiltRevision().getSha1String();
linkThree.put("note", rev);
+
+ // Now, attempt to build a URL for this changeset.
+ String url = null;
+ SCM scm = build.getProject().getScm();
+ if (scm instanceof GitSCM) {
+ GitRepositoryBrowser browser = ((GitSCM) scm).getBrowser();
+ if (browser instanceof GitWeb) {
+ String baseURL = ((GitWeb) browser).getUrl().toString();
+ url = baseURL + "?a=commit&h=" + rev;
+ } else if (browser instanceof GithubWeb) {
+ String baseURL = ((GithubWeb) browser).getUrl().toString();
+ url = baseURL + "commit/" + rev;
+ } else if (browser instanceof GitoriousWeb) {
+ String baseURL = ((GitoriousWeb) browser).getUrl().toString();
+ url = baseURL + "commit/" + rev;
+ }
+ }
+
+ if (url != null) {
+ linkThree.put("href", url);
+ } else {
+ linkThree.put("href", "http://www.sadtrombone.com/");
+ }
+
}
-
+
linkList.add(linkThree);
annot.put("links", linkList);

0 comments on commit 7d6c29f

Please sign in to comment.