Support GitHub Server API URL

* pass GitHub Server API in Octokkit constructor
This commit is contained in:
Johannes Nicolai 2021-01-25 19:16:19 +01:00
parent adc6552966
commit 05bc46786e
3 changed files with 6 additions and 10 deletions

8
dist/index.js vendored
View file

@ -901,6 +901,7 @@ class GitHubHelper {
if (token) { if (token) {
options.auth = `${token}`; options.auth = `${token}`;
} }
options.baseUrl = process.env['GITHUB_API_URL'] || 'https://api.github.com';
this.octokit = new octokit_client_1.Octokit(options); this.octokit = new octokit_client_1.Octokit(options);
} }
parseRepository(repository) { parseRepository(repository) {
@ -1157,11 +1158,8 @@ exports.getRepoPath = getRepoPath;
function getRemoteDetail(remoteUrl) { function getRemoteDetail(remoteUrl) {
// Parse the protocol and github repository from a URL // Parse the protocol and github repository from a URL
// e.g. HTTPS, peter-evans/create-pull-request // e.g. HTTPS, peter-evans/create-pull-request
let githubServerUrl = process.env['GITHUB_SERVER_URL']; const githubUrl = process.env['GITHUB_SERVER_URL'] || 'https://github.com';
if (!githubServerUrl) { const githubServerMatch = githubUrl.match(/^https?:\/\/(.+)$/i);
githubServerUrl = 'https://github.com';
}
const githubServerMatch = githubServerUrl.match(/^https?:\/\/(.+)$/i);
if (!githubServerMatch) { if (!githubServerMatch) {
throw new Error('Could not parse GitHub Server name'); throw new Error('Could not parse GitHub Server name');
} }

View file

@ -23,6 +23,7 @@ export class GitHubHelper {
if (token) { if (token) {
options.auth = `${token}` options.auth = `${token}`
} }
options.baseUrl = process.env['GITHUB_API_URL'] || 'https://api.github.com'
this.octokit = new Octokit(options) this.octokit = new Octokit(options)
} }

View file

@ -39,12 +39,9 @@ interface RemoteDetail {
export function getRemoteDetail(remoteUrl: string): RemoteDetail { export function getRemoteDetail(remoteUrl: string): RemoteDetail {
// Parse the protocol and github repository from a URL // Parse the protocol and github repository from a URL
// e.g. HTTPS, peter-evans/create-pull-request // e.g. HTTPS, peter-evans/create-pull-request
let githubServerUrl = process.env['GITHUB_SERVER_URL'] const githubUrl = process.env['GITHUB_SERVER_URL'] || 'https://github.com'
if (!githubServerUrl) {
githubServerUrl = 'https://github.com'
}
const githubServerMatch = githubServerUrl.match(/^https?:\/\/(.+)$/i) const githubServerMatch = githubUrl.match(/^https?:\/\/(.+)$/i)
if (!githubServerMatch) { if (!githubServerMatch) {
throw new Error('Could not parse GitHub Server name') throw new Error('Could not parse GitHub Server name')
} }