Set octokit baseurl for enterprise

This commit is contained in:
cnagadya
2022-11-14 13:49:52 +00:00
parent 30d5821115
commit d87317e782
3 changed files with 34 additions and 1 deletions

View File

@@ -41,6 +41,13 @@ export function isSPDXValid(license: string): boolean {
}
}
function isEnterprise(): boolean {
const serverUrl = new URL(
process.env['GITHUB_SERVER_URL'] ?? 'https://github.com'
)
return serverUrl.hostname.toLowerCase() !== 'github.com'
}
export function octokitClient(token = 'repo-token', required = true): Octokit {
const opts: Record<string, unknown> = {}
@@ -51,5 +58,11 @@ export function octokitClient(token = 'repo-token', required = true): Octokit {
opts['auth'] = auth
}
//baseUrl is required for GitHub Enterprise Server
//https://github.com/octokit/octokit.js/blob/9c8fa89d5b0bc4ddbd6dec638db00a2f6c94c298/README.md?plain=1#L196
if (isEnterprise()) {
opts['baseUrl'] = new URL('api/v3', process.env['GITHUB_SERVER_URL'])
}
return new Octokit(opts)
}