Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix for https://issues.jenkins-ci.org/browse/JENKINS-7849 #42

Merged
merged 1 commit into from

2 participants

@wpraet

Hi there,

I have added a FishEye repository browser for the jenkins Git plugin. I thought you could use it in your code?

best regards,
Wim.

@ndeloof ndeloof merged commit 1b3aac3 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 30, 2011
  1. @wpraet
This page is out of date. Refresh to see the latest.
View
131 src/main/java/hudson/plugins/git/browser/FisheyeGitRepositoryBrowser.java
@@ -0,0 +1,131 @@
+package hudson.plugins.git.browser;
+
+import hudson.Extension;
+import hudson.model.Descriptor;
+import hudson.model.Hudson;
+import hudson.plugins.git.GitChangeSet;
+import hudson.plugins.git.GitChangeSet.Path;
+import hudson.scm.EditType;
+import hudson.scm.RepositoryBrowser;
+import hudson.util.FormValidation;
+import hudson.util.FormValidation.URLCheck;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.regex.Pattern;
+
+import javax.servlet.ServletException;
+
+import net.sf.json.JSONObject;
+
+import org.kohsuke.stapler.DataBoundConstructor;
+import org.kohsuke.stapler.QueryParameter;
+import org.kohsuke.stapler.StaplerRequest;
+
+public class FisheyeGitRepositoryBrowser extends GitRepositoryBrowser {
+
+ private static final long serialVersionUID = 2881872624557203410L;
+
+ /**
+ * The URL of the FishEye repository.
+ *
+ * This is normally like <tt>http://fisheye5.cenqua.com/browse/glassfish/</tt>
+ * Normalized to have '/' at the tail.
+ */
+ public final URL url;
+
+ @DataBoundConstructor
+ public FisheyeGitRepositoryBrowser(URL url) throws MalformedURLException {
+ this.url = normalizeToEndWithSlash(url);
+ }
+
+ public URL getUrl() {
+ return url;
+ }
+
+ @Override
+ public URL getDiffLink(Path path) throws IOException {
+ if (path.getEditType() != EditType.EDIT)
+ return null; // no diff if this is not an edit change
+ String r1 = path.getChangeSet().getParentCommit();
+ String r2 = path.getChangeSet().getId();
+ return new URL(url, getPath(path) + String.format("?r1=%s&r2=%s", r1, r2));
+ }
+
+ @Override
+ public URL getFileLink(Path path) throws IOException {
+ return new URL(url, getPath(path));
+ }
+
+ private String getPath(Path path) {
+ return trimHeadSlash(path.getPath());
+ }
+
+ /**
+ * Pick up "FOOBAR" from "http://site/browse/FOOBAR/"
+ */
+ private String getProjectName() {
+ String p = url.getPath();
+ if (p.endsWith("/"))
+ p = p.substring(0, p.length() - 1);
+
+ int idx = p.lastIndexOf('/');
+ return p.substring(idx + 1);
+ }
+
+ @Override
+ public URL getChangeSetLink(GitChangeSet changeSet) throws IOException {
+ return new URL(url, "../../changelog/" + getProjectName() + "?cs=" + changeSet.getId());
+ }
+
+ @Extension
+ public static class FisheyeGitRepositoryBrowserDescriptor extends Descriptor<RepositoryBrowser<?>> {
+
+ public String getDisplayName() {
+ return "FishEye";
+ }
+
+ @Override
+ public FisheyeGitRepositoryBrowser newInstance(StaplerRequest req, JSONObject jsonObject) throws FormException {
+ return req.bindParameters(FisheyeGitRepositoryBrowser.class, "fisheye.");
+ }
+
+ /**
+ * Performs on-the-fly validation of the URL.
+ */
+ public FormValidation doCheckUrl(@QueryParameter(fixEmpty = true) String value) throws IOException,
+ ServletException {
+ if (value == null) // nothing entered yet
+ return FormValidation.ok();
+
+ if (!value.endsWith("/"))
+ value += '/';
+ if (!URL_PATTERN.matcher(value).matches())
+ return FormValidation.errorWithMarkup("The URL should end like <tt>.../browse/foobar/</tt>");
+
+ // Connect to URL and check content only if we have admin permission
+ if (!Hudson.getInstance().hasPermission(Hudson.ADMINISTER))
+ return FormValidation.ok();
+
+ final String finalValue = value;
+ return new URLCheck() {
+ @Override
+ protected FormValidation check() throws IOException, ServletException {
+ try {
+ if (findText(open(new URL(finalValue)), "FishEye")) {
+ return FormValidation.ok();
+ } else {
+ return FormValidation.error("This is a valid URL but it doesn't look like FishEye");
+ }
+ } catch (IOException e) {
+ return handleIOException(finalValue, e);
+ }
+ }
+ }.check();
+ }
+
+ private static final Pattern URL_PATTERN = Pattern.compile(".+/browse/[^/]+/");
+
+ }
+}
View
5 src/main/resources/hudson/plugins/git/browser/FisheyeGitRepositoryBrowser/config.jelly
@@ -0,0 +1,5 @@
+<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
+ <f:entry field="url" title="URL">
+ <f:textbox/>
+ </f:entry>
+</j:jelly>
View
3  src/main/resources/hudson/plugins/git/browser/FisheyeGitRepositoryBrowser/help-url.html
@@ -0,0 +1,3 @@
+<div>
+ Specify the URL of this module in FishEye. (such as http://fisheye6.cenqua.com/browse/ant/)
+</div>
Something went wrong with that request. Please try again.