Use the API URL from the environment if it is present.

This commit is contained in:
Chris Gavin 2022-08-10 21:11:50 +01:00
parent a6d09016e7
commit bbdc9efa94
No known key found for this signature in database
GPG key ID: 07F950B80C27E4DA
42 changed files with 122 additions and 22 deletions

View file

@ -22,11 +22,13 @@ export type GitHubApiCombinedDetails = GitHubApiDetails &
export interface GitHubApiDetails {
auth: string;
url: string;
apiURL: string | undefined;
}
export interface GitHubApiExternalRepoDetails {
externalRepoAuth?: string;
url: string;
apiURL: string | undefined;
}
export const getApiClient = function (
@ -36,16 +38,21 @@ export const getApiClient = function (
const auth =
(allowExternal && apiDetails.externalRepoAuth) || apiDetails.auth;
const retryingOctokit = githubUtils.GitHub.plugin(retry.retry);
let apiURL = apiDetails.apiURL;
if (!apiURL) {
apiURL = deriveApiUrl(apiDetails.url);
}
return new retryingOctokit(
githubUtils.getOctokitOptions(auth, {
baseUrl: getApiUrl(apiDetails.url),
baseUrl: apiURL,
userAgent: `CodeQL-${getMode()}/${pkg.version}`,
log: consoleLogLevel({ level: "debug" }),
})
);
};
function getApiUrl(githubUrl: string): string {
// Once the runner is deleted, this can also be removed since the GitHub API URL is always available in an environment variable on Actions.
function deriveApiUrl(githubUrl: string): string {
const url = new URL(githubUrl);
// If we detect this is trying to connect to github.com
@ -63,6 +70,7 @@ function getApiDetails() {
return {
auth: getRequiredInput("token"),
url: getRequiredEnvParam("GITHUB_SERVER_URL"),
apiURL: getRequiredEnvParam("GITHUB_API_URL"),
};
}