Skip to content

Commit 9097f5a

Browse files
committed
Add support for GitLab.com
URL structures of gitlab.com seem to be same as github.com
1 parent f2a3947 commit 9097f5a

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/gitProvider.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class Bitbucket extends BaseProvider {
4141
}
4242
}
4343

44+
class GitLab extends GitHub {
45+
}
46+
4447
class VisualStudio extends BaseProvider {
4548
get baseUrl() {
4649
return `https://${this.gitUrl.resource}${this.gitUrl.pathname}`.replace(/\.git/, '');
@@ -65,6 +68,7 @@ const gitHubDomain = workspace.getConfiguration('openInGitHub').get('gitHubDomai
6568
const providers = {
6669
[gitHubDomain]: GitHub,
6770
'bitbucket.org': Bitbucket,
71+
'gitlab.com': GitLab,
6872
'visualstudio.com': VisualStudio,
6973
};
7074

test/gitProvider.test.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,48 @@ suite('gitProvider', function () {
9696
});
9797
});
9898

99+
suite('GitLab', function () {
100+
const remoteUrl = `https://gitlab.com/${userName}/${repoName}.git`;
101+
const provider = gitProvider(remoteUrl);
102+
103+
suite('#webUrl(branch, filePath)', function () {
104+
test('should returns file URL', function () {
105+
const expectedUrl = `https://gitlab.com/${userName}/${repoName}/blob/${branch}${filePath}`;
106+
const webUrl = provider.webUrl(branch, filePath);
107+
expect(webUrl).to.equal(expectedUrl);
108+
});
109+
});
110+
111+
suite('#webUrl(branch, filePath, line)', function () {
112+
test('should returns file URL with line hash', function () {
113+
const expectedUrl = `https://gitlab.com/${userName}/${repoName}/blob/${branch}${filePath}#L${line}`;
114+
const webUrl = provider.webUrl(branch, filePath, line);
115+
expect(webUrl).to.equal(expectedUrl);
116+
});
117+
});
118+
119+
suite('#webUrl(branch)', function () {
120+
test('should returns repository root URL', function () {
121+
const expectedUrl = `https://gitlab.com/${userName}/${repoName}/tree/${branch}`;
122+
const webUrl = provider.webUrl(branch);
123+
expect(webUrl).to.equal(expectedUrl);
124+
});
125+
});
126+
127+
suite('with ssh remote URL', function () {
128+
const remoteUrl = `[email protected]:${userName}/${repoName}.git`;
129+
const provider = gitProvider(remoteUrl);
130+
131+
suite('#webUrl(branch, filePath)', function () {
132+
test('should returns HTTPS URL', function () {
133+
const expectedUrl = `https://gitlab.com/${userName}/${repoName}/blob/${branch}${filePath}`;
134+
const webUrl = provider.webUrl(branch, filePath);
135+
expect(webUrl).to.equal(expectedUrl);
136+
});
137+
});
138+
});
139+
});
140+
99141
suite('VisualStudio', function () {
100142
const projectName = 'testProject';
101143
const remoteUrl = `https://test-account.visualstudio.com/${projectName}/_git/${repoName}.git`;

0 commit comments

Comments
 (0)