diff --git a/dist/index.js b/dist/index.js index 798d6b7..8bc520a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -901,6 +901,7 @@ class GitHubHelper { if (token) { options.auth = `${token}`; } + options.baseUrl = process.env['GITHUB_API_URL'] || 'https://api.github.com'; this.octokit = new octokit_client_1.Octokit(options); } parseRepository(repository) { @@ -1157,8 +1158,13 @@ exports.getRepoPath = getRepoPath; function getRemoteDetail(remoteUrl) { // Parse the protocol and github repository from a URL // e.g. HTTPS, peter-evans/create-pull-request - const httpsUrlPattern = /^https:\/\/.*@?github.com\/(.+\/.+)$/i; - const sshUrlPattern = /^git@github.com:(.+\/.+).git$/i; + const githubUrl = process.env['GITHUB_SERVER_URL'] || 'https://github.com'; + const githubServerMatch = githubUrl.match(/^https?:\/\/(.+)$/i); + if (!githubServerMatch) { + throw new Error('Could not parse GitHub Server name'); + } + const httpsUrlPattern = new RegExp('^https?://.*@?' + githubServerMatch[1] + '/(.+/.+)$', 'i'); + const sshUrlPattern = new RegExp('^git@' + githubServerMatch[1] + ':(.+/.+).git$', 'i'); const httpsMatch = remoteUrl.match(httpsUrlPattern); if (httpsMatch) { return { diff --git a/src/github-helper.ts b/src/github-helper.ts index f031230..db8e015 100644 --- a/src/github-helper.ts +++ b/src/github-helper.ts @@ -23,6 +23,7 @@ export class GitHubHelper { if (token) { options.auth = `${token}` } + options.baseUrl = process.env['GITHUB_API_URL'] || 'https://api.github.com' this.octokit = new Octokit(options) } diff --git a/src/utils.ts b/src/utils.ts index 8b1fde1..4659b04 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -39,8 +39,21 @@ interface RemoteDetail { export function getRemoteDetail(remoteUrl: string): RemoteDetail { // Parse the protocol and github repository from a URL // e.g. HTTPS, peter-evans/create-pull-request - const httpsUrlPattern = /^https:\/\/.*@?github.com\/(.+\/.+)$/i - const sshUrlPattern = /^git@github.com:(.+\/.+).git$/i + const githubUrl = process.env['GITHUB_SERVER_URL'] || 'https://github.com' + + const githubServerMatch = githubUrl.match(/^https?:\/\/(.+)$/i) + if (!githubServerMatch) { + throw new Error('Could not parse GitHub Server name') + } + + const httpsUrlPattern = new RegExp( + '^https?://.*@?' + githubServerMatch[1] + '/(.+/.+)$', + 'i' + ) + const sshUrlPattern = new RegExp( + '^git@' + githubServerMatch[1] + ':(.+/.+).git$', + 'i' + ) const httpsMatch = remoteUrl.match(httpsUrlPattern) if (httpsMatch) {