Skip to content

Commit 2455e15

Browse files
authored
Merge pull request #704 from jonico/support-ghes
Support GitHub Enterprise Server
2 parents 171fc6c + 05bc467 commit 2455e15

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

dist/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@ class GitHubHelper {
901901
if (token) {
902902
options.auth = `${token}`;
903903
}
904+
options.baseUrl = process.env['GITHUB_API_URL'] || 'https://api.github.com';
904905
this.octokit = new octokit_client_1.Octokit(options);
905906
}
906907
parseRepository(repository) {
@@ -1157,8 +1158,13 @@ exports.getRepoPath = getRepoPath;
11571158
function getRemoteDetail(remoteUrl) {
11581159
// Parse the protocol and github repository from a URL
11591160
// e.g. HTTPS, peter-evans/create-pull-request
1160-
const httpsUrlPattern = /^https:\/\/.*@?github.com\/(.+\/.+)$/i;
1161-
const sshUrlPattern = /^git@github.com:(.+\/.+).git$/i;
1161+
const githubUrl = process.env['GITHUB_SERVER_URL'] || 'https://github.com';
1162+
const githubServerMatch = githubUrl.match(/^https?:\/\/(.+)$/i);
1163+
if (!githubServerMatch) {
1164+
throw new Error('Could not parse GitHub Server name');
1165+
}
1166+
const httpsUrlPattern = new RegExp('^https?://.*@?' + githubServerMatch[1] + '/(.+/.+)$', 'i');
1167+
const sshUrlPattern = new RegExp('^git@' + githubServerMatch[1] + ':(.+/.+).git$', 'i');
11621168
const httpsMatch = remoteUrl.match(httpsUrlPattern);
11631169
if (httpsMatch) {
11641170
return {

src/github-helper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class GitHubHelper {
2323
if (token) {
2424
options.auth = `${token}`
2525
}
26+
options.baseUrl = process.env['GITHUB_API_URL'] || 'https://api.github.com'
2627
this.octokit = new Octokit(options)
2728
}
2829

src/utils.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,21 @@ interface RemoteDetail {
3939
export function getRemoteDetail(remoteUrl: string): RemoteDetail {
4040
// Parse the protocol and github repository from a URL
4141
// e.g. HTTPS, peter-evans/create-pull-request
42-
const httpsUrlPattern = /^https:\/\/.*@?github.com\/(.+\/.+)$/i
43-
const sshUrlPattern = /^git@github.com:(.+\/.+).git$/i
42+
const githubUrl = process.env['GITHUB_SERVER_URL'] || 'https://github.com'
43+
44+
const githubServerMatch = githubUrl.match(/^https?:\/\/(.+)$/i)
45+
if (!githubServerMatch) {
46+
throw new Error('Could not parse GitHub Server name')
47+
}
48+
49+
const httpsUrlPattern = new RegExp(
50+
'^https?://.*@?' + githubServerMatch[1] + '/(.+/.+)$',
51+
'i'
52+
)
53+
const sshUrlPattern = new RegExp(
54+
'^git@' + githubServerMatch[1] + ':(.+/.+).git$',
55+
'i'
56+
)
4457

4558
const httpsMatch = remoteUrl.match(httpsUrlPattern)
4659
if (httpsMatch) {

0 commit comments

Comments
 (0)