Skip to content

Commit

Permalink
GitLab: fix file link for version 4.2
Browse files Browse the repository at this point in the history
This was suggested in a comment to commit
73249ee by Nick Oliver (PixnBits).

[FIXES JENKINS-25568]
  • Loading branch information
olafmandel committed Nov 12, 2014
1 parent a81f76a commit 809fec0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/main/java/hudson/plugins/git/browser/GitLab.java
Expand Up @@ -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]
*
Expand All @@ -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());
Expand Down
12 changes: 11 additions & 1 deletion src/test/java/hudson/plugins/git/browser/GitLabTest.java
Expand Up @@ -20,6 +20,7 @@ public class GitLabTest extends TestCase {

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");

Expand All @@ -28,6 +29,7 @@ public class GitLabTest extends TestCase {
*/
public void testGetVersion() {
assertEquals(gitlab29.getVersion(), 2.9);
assertEquals(gitlab42.getVersion(), 4.2);
assertEquals(gitlab50.getVersion(), 5.0);
assertEquals(gitlab51.getVersion(), 5.1);
}
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 809fec0

Please sign in to comment.