-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support for Gitorious repositories #38
Closed
bigkraig
wants to merge
2
commits into
jenkinsci:master
from
bigkraig:5706edec674c9fc1a57124a30dfdb48e15bb7185
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
src/main/java/hudson/plugins/git/browser/GitoriousWeb.java
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,86 @@ | ||
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 java.io.IOException; | ||
import java.net.URL; | ||
import java.net.MalformedURLException; | ||
|
||
import net.sf.json.JSONObject; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.StaplerRequest; | ||
|
||
/** | ||
* Git Browser for Gitorious | ||
*/ | ||
public class GitoriousWeb extends GitRepositoryBrowser { | ||
|
||
private static final long serialVersionUID = 1L; | ||
private final URL url; | ||
|
||
@DataBoundConstructor | ||
public GitoriousWeb(String url) throws MalformedURLException { | ||
this.url = normalizeToEndWithSlash(new URL(url)); | ||
} | ||
|
||
public URL getUrl() { | ||
return url; | ||
} | ||
|
||
@Override | ||
public URL getChangeSetLink(GitChangeSet changeSet) throws IOException { | ||
return new URL(url, "commit/" + changeSet.getId().toString()); | ||
} | ||
|
||
/** | ||
* Creates a link to the commit diff. | ||
* | ||
* https://[Gitorious URL]/commit/a9182a07750c9a0dfd89a8461adf72ef5ef0885b | ||
* | ||
* @param path | ||
* @return diff link | ||
* @throws IOException | ||
*/ | ||
@Override | ||
public URL getDiffLink(Path path) throws IOException { | ||
final GitChangeSet changeSet = path.getChangeSet(); | ||
// gitorious does not show diffs on single files so we create a link to the commit | ||
return new URL(url, "commit/" + changeSet.getId().toString()); | ||
} | ||
|
||
/** | ||
* Creates a link to the file. | ||
* https://[Gitorious URL]/blobs/a9182a07750c9a0dfd89a8461adf72ef5ef0885b/pom.xml | ||
* | ||
* @param path | ||
* @return file link | ||
* @throws IOException | ||
*/ | ||
@Override | ||
public URL getFileLink(Path path) throws IOException { | ||
if (path.getEditType().equals(EditType.DELETE)) { | ||
return getDiffLink(path); | ||
} else { | ||
final String spec = "blobs/" + path.getChangeSet().getId() + "/" + path.getPath(); | ||
return new URL(url, url.getPath() + spec); | ||
} | ||
} | ||
|
||
@Extension | ||
public static class GitoriousWebDescriptor extends Descriptor<RepositoryBrowser<?>> { | ||
public String getDisplayName() { | ||
return "gitoriousweb"; | ||
} | ||
|
||
@Override | ||
public GitoriousWeb newInstance(StaplerRequest req, JSONObject jsonObject) throws FormException { | ||
return req.bindParameters(GitoriousWeb.class, "Gitoriousweb."); | ||
} | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
src/main/resources/hudson/plugins/git/browser/GitoriousWeb/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,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> |
3 changes: 3 additions & 0 deletions
3
src/main/resources/hudson/plugins/git/browser/GitoriousWeb/help-url.html
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,3 @@ | ||
<div> | ||
Specify the root URL serving this repository (such as <a href="http://gitorious.org/gitorious/mainline">http://gitorious.org/gitorious/mainline</a>). | ||
</div> |
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
123 changes: 123 additions & 0 deletions
123
src/test/java/hudson/plugins/git/browser/GitoriousWebTest.java
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,123 @@ | ||
package hudson.plugins.git.browser; | ||
|
||
import hudson.plugins.git.GitChangeLogParser; | ||
import hudson.plugins.git.GitChangeSet; | ||
import hudson.plugins.git.GitChangeSet.Path; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
||
import junit.framework.TestCase; | ||
|
||
import org.xml.sax.SAXException; | ||
|
||
|
||
public class GitoriousWebTest extends TestCase { | ||
|
||
/** | ||
* | ||
*/ | ||
private static final String GITORIOUS_URL = "https://SERVER/PROJECT"; | ||
private final GitoriousWeb gitoriousWeb; | ||
|
||
{ | ||
try { | ||
gitoriousWeb = new GitoriousWeb(GITORIOUS_URL); | ||
} catch (MalformedURLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
/** | ||
* Test method for {@link hudson.plugins.git.browser.GitoriousWeb#getUrl()}. | ||
* @throws MalformedURLException | ||
*/ | ||
public void testGetUrl() throws MalformedURLException { | ||
assertEquals(String.valueOf(gitoriousWeb.getUrl()), GITORIOUS_URL + "/"); | ||
} | ||
|
||
/** | ||
* Test method for {@link hudson.plugins.git.browser.GitoriousWeb#getUrl()}. | ||
* @throws MalformedURLException | ||
*/ | ||
public void testGetUrlForRepoWithTrailingSlash() throws MalformedURLException { | ||
assertEquals(String.valueOf(new GitoriousWeb(GITORIOUS_URL + "/").getUrl()), GITORIOUS_URL + "/"); | ||
} | ||
|
||
/** | ||
* Test method for {@link hudson.plugins.git.browser.GitoriousWeb#getChangeSetLink(hudson.plugins.git.GitChangeSet)}. | ||
* @throws SAXException | ||
* @throws IOException | ||
*/ | ||
public void testGetChangeSetLinkGitChangeSet() throws IOException, SAXException { | ||
final URL changeSetLink = gitoriousWeb.getChangeSetLink(createChangeSet("rawchangelog")); | ||
assertEquals(GITORIOUS_URL + "/commit/396fc230a3db05c427737aa5c2eb7856ba72b05d", changeSetLink.toString()); | ||
} | ||
|
||
/** | ||
* Test method for {@link hudson.plugins.git.browser.GitoriousWeb#getDiffLink(hudson.plugins.git.GitChangeSet.Path)}. | ||
* @throws SAXException | ||
* @throws IOException | ||
*/ | ||
public void testGetDiffLinkPath() throws IOException, SAXException { | ||
final HashMap<String, Path> pathMap = createPathMap("rawchangelog"); | ||
final Path modified1 = pathMap.get("src/main/java/hudson/plugins/git/browser/GithubWeb.java"); | ||
assertEquals(GITORIOUS_URL + "/commit/396fc230a3db05c427737aa5c2eb7856ba72b05d", gitoriousWeb.getDiffLink(modified1).toString()); | ||
// For added files returns a link to the commit. | ||
final Path added = pathMap.get("src/test/resources/hudson/plugins/git/browser/rawchangelog-with-deleted-file"); | ||
assertEquals(GITORIOUS_URL + "/commit/396fc230a3db05c427737aa5c2eb7856ba72b05d", gitoriousWeb.getDiffLink(added).toString()); | ||
} | ||
|
||
/** | ||
* Test method for {@link hudson.plugins.git.browser.GithubWeb#getFileLink(hudson.plugins.git.GitChangeSet.Path)}. | ||
* @throws SAXException | ||
* @throws IOException | ||
*/ | ||
public void testGetFileLinkPath() throws IOException, SAXException { | ||
final HashMap<String,Path> pathMap = createPathMap("rawchangelog"); | ||
final Path path = pathMap.get("src/main/java/hudson/plugins/git/browser/GithubWeb.java"); | ||
final URL fileLink = gitoriousWeb.getFileLink(path); | ||
assertEquals(GITORIOUS_URL + "/blobs/396fc230a3db05c427737aa5c2eb7856ba72b05d/src/main/java/hudson/plugins/git/browser/GithubWeb.java", String.valueOf(fileLink)); | ||
} | ||
|
||
/** | ||
* Test method for {@link hudson.plugins.git.browser.GithubWeb#getFileLink(hudson.plugins.git.GitChangeSet.Path)}. | ||
* @throws SAXException | ||
* @throws IOException | ||
*/ | ||
public void testGetFileLinkPathForDeletedFile() throws IOException, SAXException { | ||
final HashMap<String,Path> pathMap = createPathMap("rawchangelog-with-deleted-file"); | ||
final Path path = pathMap.get("bar"); | ||
final URL fileLink = gitoriousWeb.getFileLink(path); | ||
assertEquals(GITORIOUS_URL + "/commit/fc029da233f161c65eb06d0f1ed4f36ae81d1f4f", String.valueOf(fileLink)); | ||
} | ||
|
||
private GitChangeSet createChangeSet(String rawchangelogpath) throws IOException, SAXException { | ||
final File rawchangelog = new File(GitoriousWebTest.class.getResource(rawchangelogpath).getFile()); | ||
final GitChangeLogParser logParser = new GitChangeLogParser(false); | ||
final List<GitChangeSet> changeSetList = logParser.parse(null, rawchangelog).getLogs(); | ||
return changeSetList.get(0); | ||
} | ||
|
||
/** | ||
* @param changelog | ||
* @return | ||
* @throws IOException | ||
* @throws SAXException | ||
*/ | ||
private HashMap<String, Path> createPathMap(final String changelog) throws IOException, SAXException { | ||
final HashMap<String, Path> pathMap = new HashMap<String, Path>(); | ||
final Collection<Path> changeSet = createChangeSet(changelog).getPaths(); | ||
for (final Path path : changeSet) { | ||
pathMap.put(path.getPath(), path); | ||
} | ||
return pathMap; | ||
} | ||
|
||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello Kraig,
I see there is no method to jump directly to a specific file in the inline view, however something like:
https://gitorious.org/jenkinsci/jenkins/commit/bf2f214983517bc1656fa560e50e5e4df84eba95/diffs?diffmode=sidebyside&fragment=1#test/src/test/java/hudson/tasks/junit/TestResultTest.java
does work, so maybe changing this would be good.
`return new URL(url, "commit/" + changeSet.getId().toString() + "/diffs?diffmode=sidebyside&fragment=1#" + path);``
Regards
Mirko