Skip to content
Permalink
Browse files

[FIXED JENKINS-6963] CGit browser support.

  • Loading branch information...
ssogabe committed Jun 8, 2012
1 parent 6915ce8 commit 6e4060ede07917902a48190d9226d646717ae1c8
@@ -0,0 +1,95 @@
package hudson.plugins.git.browser;

import hudson.Extension;
import hudson.model.Descriptor;
import hudson.plugins.git.GitChangeSet;
import hudson.plugins.git.GitChangeSet.Path;
import hudson.scm.EditType;
import hudson.scm.RepositoryBrowser;
import hudson.scm.browsers.QueryBuilder;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

/**
* Git Browser URLs
*/
public class CGit extends GitRepositoryBrowser {

private static final long serialVersionUID = 1L;
private final URL url;

@DataBoundConstructor
public CGit(String url) throws MalformedURLException {
this.url = normalizeToEndWithSlash(new URL(url));
}

public URL getUrl() {
return url;
}

private QueryBuilder param() {
return new QueryBuilder(url.getQuery());
}

/**
* Creates a link to the change set
* http://[CGit URL]/commit?id=[commit]
*
* @param changeSet commit hash
* @return change set link
* @throws IOException
*/
@Override
public URL getChangeSetLink(GitChangeSet changeSet) throws IOException {
return new URL(url, url.getPath() + "commit/" + param().add("id=" + changeSet.getId()).toString());
}

/**
* Creates a link to the file diff.
* http://[CGit URL]/diff/[path]?id=[commit]
*
* @param path affected file path
* @return diff link
* @throws IOException
*/
@Override
public URL getDiffLink(Path path) throws IOException {
GitChangeSet changeSet = path.getChangeSet();
return new URL(url, url.getPath() + "diff/" + path.getPath() + param().add("id=" + changeSet.getId()).toString());
}

/**
* Creates a link to the file.
* http://[CGit URL]/tree/[path]?id=[commit]
*
* @param path affected file path
* @return diff link
* @throws IOException
*/
@Override
public URL getFileLink(Path path) throws IOException {
GitChangeSet changeSet = path.getChangeSet();

if (path.getEditType() == EditType.DELETE) {
return new URL(url, url.getPath() + "tree/" + path.getPath() + param().add("id=" + changeSet.getParentCommit()).toString());
} else {
return new URL(url, url.getPath() + "tree/" + path.getPath() + param().add("id=" + changeSet.getId()).toString());
}
}

@Extension
public static class CGITDescriptor extends Descriptor<RepositoryBrowser<?>> {
public String getDisplayName() {
return "cgit";
}

@Override
public CGit newInstance(StaplerRequest req, JSONObject jsonObject) throws FormException {
return req.bindParameters(CGit.class, "cgit.");
}
}
}
@@ -0,0 +1,6 @@
<?jelly escape-by-default='true'?>
<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 title="URL" help="/plugin/git/cgit.html">
<f:textbox name="cgit.url" value="${browser.url}"/>
</f:entry>
</j:jelly>

0 comments on commit 6e4060e

Please sign in to comment.
You can’t perform that action at this time.