Skip to content

Commit 1b3ce17

Browse files
enurebugthesystem
authored andcommitted
fix: Add parameter to specify http or https url (#81)
Closes #65
1 parent 9b1a86f commit 1b3ce17

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ Add following line into workspace settings;
7171

7272
```js
7373
{
74-
"openInGitHub.gitHubDomain":"your custom github domain here",
75-
"openInGitHub.requireSelectionForLines":false // If enabled, the copied or opened URL won't include line number(s) unless there's an active selection
74+
"openInGitHub.gitHubDomain": "your custom github domain here",
75+
"openInGitHub.requireSelectionForLines": false, // If enabled, the copied or opened URL won't include line number(s) unless there's an active selection
7676
"openInGitHub.providerType": "gitlab" //github, gitlab, bitbucket, ...
77+
"openInGitHub.providerProtocol": "https" //https, http. Useful for custom domains that don't support https. Defaults to https.
7778
}
7879
```
7980

package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"string"
5555
],
5656
"default": "github.com",
57-
"description": "Configure a custom Github domain. Useful for Github entreprise"
57+
"description": "Configure a custom Github domain. Useful for Github enterprise"
5858
},
5959
"openInGitHub.requireSelectionForLines": {
6060
"type": "boolean",
@@ -69,7 +69,16 @@
6969
"github",
7070
"bitbucket"
7171
],
72-
"description": "specify the provider type in Custom Site"
72+
"description": "Specify the provider type in Custom Site"
73+
},
74+
"openInGitHub.providerProtocol": {
75+
"type": "string",
76+
"default": "https",
77+
"enum": [
78+
"https",
79+
"http"
80+
],
81+
"description": "Specify the provider protocol for custom sites or Github enterprise"
7382
}
7483
}
7584
},

src/gitProvider.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class BaseProvider {
1010
}
1111

1212
get baseUrl() {
13-
return this.gitUrl.toString('https').replace(/(\.git)$/, '');
13+
return this.gitUrl.toString(providerProtocol).replace(/(\.git)$/, '');
1414
}
1515

1616
/**
@@ -90,6 +90,7 @@ class VisualStudio extends BaseProvider {
9090

9191
const gitHubDomain = workspace.getConfiguration('openInGitHub').get('gitHubDomain', 'github.com');
9292
const providerType = workspace.getConfiguration('openInGitHub').get('providerType', 'unknown');
93+
const providerProtocol = workspace.getConfiguration('openInGitHub').get('providerProtocol', 'https');
9394

9495
const providers = {
9596
[gitHubDomain]: GitHub,

test/gitProvider.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,38 @@ suite('gitProvider', function () {
8080
});
8181
});
8282
});
83+
84+
suite('with custom domain and protocol', function () {
85+
const testDomain = 'github.testdomain.com';
86+
const testProtocol = 'http';
87+
const remoteUrl = `https://${testDomain}/${userName}/${repoName}.git`;
88+
89+
const fakeVscode = {
90+
workspace: {
91+
getConfiguration: function () {
92+
return {
93+
get: function (configKey) {
94+
if (configKey === 'gitHubDomain') {
95+
return testDomain;
96+
} else if (providerProtocol === 'providerProtocol') {
97+
return testProtocol;
98+
}
99+
},
100+
};
101+
},
102+
},
103+
};
104+
const gitProvider = proxyquire('../src/gitProvider.js', { vscode: fakeVscode });
105+
const provider = gitProvider(remoteUrl);
106+
107+
suite('#webUrl(branch, filePath)', function () {
108+
test('should return custom domain URL', function () {
109+
const expectedUrl = `http://${testDomain}/${userName}/${repoName}/blob/${branch}${filePath}`;
110+
const webUrl = provider.webUrl(branch, filePath);
111+
expect(webUrl).to.equal(expectedUrl);
112+
});
113+
});
114+
});
83115
});
84116

85117
suite('Bitbucket', function () {

0 commit comments

Comments
 (0)