Skip to content

Commit

Permalink
Merge pull request #704 from jonico/support-ghes
Browse files Browse the repository at this point in the history
Support GitHub Enterprise Server
  • Loading branch information
peter-evans authored Jan 26, 2021
2 parents 171fc6c + 05bc467 commit 2455e15
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
10 changes: 8 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/github-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
17 changes: 15 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2455e15

Please sign in to comment.