Skip to content

Commit

Permalink
Add support for GitLab.com
Browse files Browse the repository at this point in the history
URL structures of gitlab.com seem to be same as github.com
  • Loading branch information
itiut committed Nov 25, 2016
1 parent f2a3947 commit 9097f5a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/gitProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class Bitbucket extends BaseProvider {
}
}

class GitLab extends GitHub {
}

class VisualStudio extends BaseProvider {
get baseUrl() {
return `https://${this.gitUrl.resource}${this.gitUrl.pathname}`.replace(/\.git/, '');
Expand All @@ -65,6 +68,7 @@ const gitHubDomain = workspace.getConfiguration('openInGitHub').get('gitHubDomai
const providers = {
[gitHubDomain]: GitHub,
'bitbucket.org': Bitbucket,
'gitlab.com': GitLab,
'visualstudio.com': VisualStudio,
};

Expand Down
42 changes: 42 additions & 0 deletions test/gitProvider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,48 @@ suite('gitProvider', function () {
});
});

suite('GitLab', function () {
const remoteUrl = `https://gitlab.com/${userName}/${repoName}.git`;
const provider = gitProvider(remoteUrl);

suite('#webUrl(branch, filePath)', function () {
test('should returns file URL', function () {
const expectedUrl = `https://gitlab.com/${userName}/${repoName}/blob/${branch}${filePath}`;
const webUrl = provider.webUrl(branch, filePath);
expect(webUrl).to.equal(expectedUrl);
});
});

suite('#webUrl(branch, filePath, line)', function () {
test('should returns file URL with line hash', function () {
const expectedUrl = `https://gitlab.com/${userName}/${repoName}/blob/${branch}${filePath}#L${line}`;
const webUrl = provider.webUrl(branch, filePath, line);
expect(webUrl).to.equal(expectedUrl);
});
});

suite('#webUrl(branch)', function () {
test('should returns repository root URL', function () {
const expectedUrl = `https://gitlab.com/${userName}/${repoName}/tree/${branch}`;
const webUrl = provider.webUrl(branch);
expect(webUrl).to.equal(expectedUrl);
});
});

suite('with ssh remote URL', function () {
const remoteUrl = `[email protected]:${userName}/${repoName}.git`;
const provider = gitProvider(remoteUrl);

suite('#webUrl(branch, filePath)', function () {
test('should returns HTTPS URL', function () {
const expectedUrl = `https://gitlab.com/${userName}/${repoName}/blob/${branch}${filePath}`;
const webUrl = provider.webUrl(branch, filePath);
expect(webUrl).to.equal(expectedUrl);
});
});
});
});

suite('VisualStudio', function () {
const projectName = 'testProject';
const remoteUrl = `https://test-account.visualstudio.com/${projectName}/_git/${repoName}.git`;
Expand Down

0 comments on commit 9097f5a

Please sign in to comment.