Support GitHub Enterprise Server

* parse GITHUB_SERVER_URL if present
* accept proper server remotes as well
This commit is contained in:
Johannes Nicolai 2021-01-25 18:25:20 +01:00
parent 171fc6cce4
commit adc6552966
2 changed files with 28 additions and 4 deletions

12
dist/index.js vendored
View file

@ -1157,8 +1157,16 @@ 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;
let githubServerUrl = process.env['GITHUB_SERVER_URL'];
if (!githubServerUrl) {
githubServerUrl = 'https://github.com';
}
const githubServerMatch = githubServerUrl.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 {