Skip to content
Permalink
Browse files

GitLab: fix file link for version 4.2

This was suggested in a comment to commit
73249ee by Nick Oliver (PixnBits).

[FIXES JENKINS-25568]
  • Loading branch information...
olafmandel authored and MarkEWaite committed Nov 12, 2014
1 parent c7647ca commit 01eece1ecc3bf37ea4bce5f397b043d2ddd23154
@@ -67,6 +67,7 @@ public URL getDiffLink(Path path) throws IOException {

/**
* Creates a link to the file.
* v ≤ 4.2: [GitLab URL]tree/[Hash]/[File path]
* v < 5.1: [GitLab URL][Hash]/tree/[File path]
* else: [GitLab URL]blob/[Hash]/[File path]
*
@@ -79,7 +80,9 @@ public URL getFileLink(Path path) throws IOException {
if (path.getEditType().equals(EditType.DELETE)) {
return getDiffLink(path);
} else {
if(getVersion() < 5.1) {
if(getVersion() <= 4.2) {
return new URL(getUrl(), "tree/" + path.getChangeSet().getId() + "/" + path.getPath());
} else if(getVersion() < 5.1) {
return new URL(getUrl(), path.getChangeSet().getId() + "/tree/" + path.getPath());
} else {
return new URL(getUrl(), "blob/" + path.getChangeSet().getId() + "/" + path.getPath());
@@ -20,6 +20,7 @@

private static final String GITLAB_URL = "https://SERVER/USER/REPO/";
private final GitLab gitlab29 = new GitLab(GITLAB_URL, "2.9");
private final GitLab gitlab42 = new GitLab(GITLAB_URL, "4.2");
private final GitLab gitlab50 = new GitLab(GITLAB_URL, "5.0");
private final GitLab gitlab51 = new GitLab(GITLAB_URL, "5.1");

@@ -28,6 +29,7 @@
*/
public void testGetVersion() {
assertEquals(gitlab29.getVersion(), 2.9);
assertEquals(gitlab42.getVersion(), 4.2);
assertEquals(gitlab50.getVersion(), 5.0);
assertEquals(gitlab51.getVersion(), 5.1);
}
@@ -39,6 +41,8 @@ public void testGetVersion() {
public void testGetChangeSetLinkGitChangeSet() throws IOException, SAXException {
assertEquals(GITLAB_URL + "commits/396fc230a3db05c427737aa5c2eb7856ba72b05d",
gitlab29.getChangeSetLink(createChangeSet("rawchangelog")).toString());
assertEquals(GITLAB_URL + "commit/396fc230a3db05c427737aa5c2eb7856ba72b05d",
gitlab42.getChangeSetLink(createChangeSet("rawchangelog")).toString());
assertEquals(GITLAB_URL + "commit/396fc230a3db05c427737aa5c2eb7856ba72b05d",
gitlab50.getChangeSetLink(createChangeSet("rawchangelog")).toString());
assertEquals(GITLAB_URL + "commit/396fc230a3db05c427737aa5c2eb7856ba72b05d",
@@ -54,6 +58,8 @@ public void testGetDiffLinkPath() throws IOException, SAXException {
final Path modified1 = pathMap.get("src/main/java/hudson/plugins/git/browser/GithubWeb.java");
assertEquals(GITLAB_URL + "commits/396fc230a3db05c427737aa5c2eb7856ba72b05d#src/main/java/hudson/plugins/git/browser/GithubWeb.java",
gitlab29.getDiffLink(modified1).toString());
assertEquals(GITLAB_URL + "commit/396fc230a3db05c427737aa5c2eb7856ba72b05d#src/main/java/hudson/plugins/git/browser/GithubWeb.java",
gitlab42.getDiffLink(modified1).toString());
assertEquals(GITLAB_URL + "commit/396fc230a3db05c427737aa5c2eb7856ba72b05d#src/main/java/hudson/plugins/git/browser/GithubWeb.java",
gitlab50.getDiffLink(modified1).toString());
assertEquals(GITLAB_URL + "commit/396fc230a3db05c427737aa5c2eb7856ba72b05d#src/main/java/hudson/plugins/git/browser/GithubWeb.java",
@@ -67,8 +73,10 @@ public void testGetDiffLinkPath() throws IOException, SAXException {
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");
assertEquals(GITLAB_URL + "396fc230a3db05c427737aa5c2eb7856ba72b05d/tree/src/main/java/hudson/plugins/git/browser/GithubWeb.java",
assertEquals(GITLAB_URL + "tree/396fc230a3db05c427737aa5c2eb7856ba72b05d/src/main/java/hudson/plugins/git/browser/GithubWeb.java",
gitlab29.getFileLink(path).toString());
assertEquals(GITLAB_URL + "tree/396fc230a3db05c427737aa5c2eb7856ba72b05d/src/main/java/hudson/plugins/git/browser/GithubWeb.java",
gitlab42.getFileLink(path).toString());
assertEquals(GITLAB_URL + "396fc230a3db05c427737aa5c2eb7856ba72b05d/tree/src/main/java/hudson/plugins/git/browser/GithubWeb.java",
gitlab50.getFileLink(path).toString());
assertEquals(GITLAB_URL + "blob/396fc230a3db05c427737aa5c2eb7856ba72b05d/src/main/java/hudson/plugins/git/browser/GithubWeb.java",
@@ -84,6 +92,8 @@ public void testGetFileLinkPathForDeletedFile() throws IOException, SAXException
final Path path = pathMap.get("bar");
assertEquals(GITLAB_URL + "commits/fc029da233f161c65eb06d0f1ed4f36ae81d1f4f#bar",
gitlab29.getFileLink(path).toString());
assertEquals(GITLAB_URL + "commit/fc029da233f161c65eb06d0f1ed4f36ae81d1f4f#bar",
gitlab42.getFileLink(path).toString());
assertEquals(GITLAB_URL + "commit/fc029da233f161c65eb06d0f1ed4f36ae81d1f4f#bar",
gitlab50.getFileLink(path).toString());
assertEquals(GITLAB_URL + "commit/fc029da233f161c65eb06d0f1ed4f36ae81d1f4f#bar",

0 comments on commit 01eece1

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