Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXED JENKINS-6963] CGit browser support.
- Loading branch information
Showing
2 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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."); | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/resources/hudson/plugins/git/browser/CGit/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |