Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Rhodecode server (rhodecode.org) #4

Merged
merged 2 commits into from
Oct 15, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions src/main/java/hudson/plugins/mercurial/browser/Rhodecode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package hudson.plugins.mercurial.browser;

import hudson.Extension;
import hudson.model.Descriptor;
import hudson.plugins.mercurial.MercurialChangeSet;
import hudson.scm.RepositoryBrowser;

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;

/**
* Mercurial web interface served using Rhodecode
*/
public class Rhodecode extends HgBrowser {

@DataBoundConstructor
public Rhodecode(String url) throws MalformedURLException {
super(url);
}

/**
* {@inheritDoc}
*/
@Override
public URL getChangeSetLink(MercurialChangeSet changeSet)
throws IOException {
current = changeSet;
// TODO: consider verifying the repository connection to tip at configuration time?
return new URL(getUrl(), "changeset/" + changeSet.getShortNode());
}

/**
* {@inheritDoc}
*
* Throws {@link IllegalStateException} when this method is called before at least one call
* to {@literal getChangeSetLink(MercurialChangeSet)}.
*/
@Override
public URL getFileLink(String path) throws MalformedURLException {
checkCurrentIsNotNull();
return new URL(getUrl(), "files/" + current.getShortNode() + "/" + path);
}

/**
* {@inheritDoc}
*
* Throws {@link IllegalStateException} when this method is called before at least one call
* to {@literal getChangeSetLink(MercurialChangeSet)}.
*/
@Override
public URL getDiffLink(String path) throws MalformedURLException {
checkCurrentIsNotNull();
return new URL(getUrl(), "changeset/" + current.getShortNode() + "/" + path.replace("/", "-"));
}

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

public @Override Rhodecode newInstance(StaplerRequest req, JSONObject json) throws FormException {
return req.bindParameters(Rhodecode.class,"rhodecode.");
}
}

private static final long serialVersionUID = 1L;
}

Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
Specify the root URL serving this repository (such as <a href="http://selenic.com/repo/hg">this</a>.)
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* RhodecodeTest.java 17.09.2011
*/
package hudson.plugins.mercurial.browser;
import static org.junit.Assert.assertEquals;
import hudson.plugins.mercurial.MercurialChangeSet;

import java.io.IOException;
import java.net.MalformedURLException;

import org.junit.Test;

public class RhodecodeTest {

private static final String REPO_URL = "https://secure.rhodecode.org/rhodecode";
protected final HgBrowser browser;
protected final MercurialChangeSet changeSet;

public RhodecodeTest() throws MalformedURLException {
this.browser = new Rhodecode(REPO_URL);
changeSet = new MercurialChangeSet();
changeSet.setNode("6f1439efaed6");
}

@Test(expected = IllegalStateException.class)
public void testGetFileLinkIllegalState() throws IOException {
browser.getFileLink("src/main/java/hudson/plugins/mercurial/browser/HgBrowser.java");
}

@Test(expected = IllegalStateException.class)
public void testGetDiffLinkIllegalState() throws IOException {
browser.getDiffLink("src/main/java/hudson/plugins/mercurial/browser/HgBrowser.java");
}

/**
* @param expected
* @throws IOException
* @throws MalformedURLException
*/
@Test
public void testGetFileLink() throws IOException, MalformedURLException {
String expected = REPO_URL + "/files/6f1439efaed6/rhodecode/public/css/pygments.css";
browser.getChangeSetLink(changeSet);
assertEquals(expected, browser.getFileLink("rhodecode/public/css/pygments.css").toExternalForm());
}

/**
* @param expected
* @throws IOException
* @throws MalformedURLException
*/
@Test
public void testGetDiffLink() throws IOException, MalformedURLException {
String expected = REPO_URL + "/changeset/6f1439efaed6#Crhodecode-public-css-pygments.css";
browser.getChangeSetLink(changeSet);
assertEquals(expected, browser.getDiffLink("rhodecode/public/css/pygments.css").toExternalForm());
}

/**
* @param expected
* @throws IOException
*/
@Test
public void testGetChangeSetLinkMercurialChangeSet() throws IOException {
String expected = REPO_URL + "/changeset/6f1439efaed6";
assertEquals(expected, browser.getChangeSetLink(changeSet).toExternalForm());
}
}