Convert GitHub variant to an enum.
This commit is contained in:
parent
0656b2c1ad
commit
c9ca4ec1bd
24 changed files with 67 additions and 52 deletions
|
|
@ -19,7 +19,7 @@ test("emptyPaths", async (t) => {
|
|||
tempDir: tmpDir,
|
||||
toolCacheDir: tmpDir,
|
||||
codeQLCmd: "",
|
||||
gitHubVersion: { type: "dotcom" } as util.GitHubVersion,
|
||||
gitHubVersion: { type: util.GitHubVariant.DOTCOM } as util.GitHubVersion,
|
||||
};
|
||||
analysisPaths.includeAndExcludeAnalysisPaths(config);
|
||||
t.is(process.env["LGTM_INDEX_INCLUDE"], undefined);
|
||||
|
|
@ -39,7 +39,7 @@ test("nonEmptyPaths", async (t) => {
|
|||
tempDir: tmpDir,
|
||||
toolCacheDir: tmpDir,
|
||||
codeQLCmd: "",
|
||||
gitHubVersion: { type: "dotcom" } as util.GitHubVersion,
|
||||
gitHubVersion: { type: util.GitHubVariant.DOTCOM } as util.GitHubVersion,
|
||||
};
|
||||
analysisPaths.includeAndExcludeAnalysisPaths(config);
|
||||
t.is(process.env["LGTM_INDEX_INCLUDE"], "path1\npath2");
|
||||
|
|
@ -63,7 +63,7 @@ test("exclude temp dir", async (t) => {
|
|||
tempDir,
|
||||
toolCacheDir,
|
||||
codeQLCmd: "",
|
||||
gitHubVersion: { type: "dotcom" } as util.GitHubVersion,
|
||||
gitHubVersion: { type: util.GitHubVariant.DOTCOM } as util.GitHubVersion,
|
||||
};
|
||||
analysisPaths.includeAndExcludeAnalysisPaths(config);
|
||||
t.is(process.env["LGTM_INDEX_INCLUDE"], undefined);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,9 @@ test("status report fields", async (t) => {
|
|||
tempDir: tmpDir,
|
||||
toolCacheDir: tmpDir,
|
||||
codeQLCmd: "",
|
||||
gitHubVersion: { type: "dotcom" } as util.GitHubVersion,
|
||||
gitHubVersion: {
|
||||
type: util.GitHubVariant.DOTCOM,
|
||||
} as util.GitHubVersion,
|
||||
};
|
||||
fs.mkdirSync(util.getCodeQLDatabasePath(config.tempDir, language), {
|
||||
recursive: true,
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ const sampleApiDetails = {
|
|||
url: "https://github.example.com",
|
||||
};
|
||||
|
||||
const gitHubVersion = { type: "dotcom" } as util.GitHubVersion;
|
||||
const gitHubVersion = { type: util.GitHubVariant.DOTCOM } as util.GitHubVersion;
|
||||
|
||||
// Returns the filepath of the newly-created file
|
||||
function createConfigFile(inputFileContents: string, tmpDir: string): string {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ function getTestConfig(tmpDir: string): configUtils.Config {
|
|||
tempDir: tmpDir,
|
||||
toolCacheDir: tmpDir,
|
||||
codeQLCmd: "",
|
||||
gitHubVersion: { type: "dotcom" } as util.GitHubVersion,
|
||||
gitHubVersion: { type: util.GitHubVariant.DOTCOM } as util.GitHubVersion,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import test from "ava";
|
|||
import { getRunnerLogger } from "./logging";
|
||||
import { setupTests } from "./testing-utils";
|
||||
import * as uploadLib from "./upload-lib";
|
||||
import { GitHubVersion, withTmpDir } from "./util";
|
||||
import { GitHubVersion, GitHubVariant, withTmpDir } from "./util";
|
||||
|
||||
setupTests(test);
|
||||
|
||||
|
|
@ -26,12 +26,12 @@ test("validateSarifFileSchema - invalid", (t) => {
|
|||
|
||||
test("validate correct payload used per version", async (t) => {
|
||||
const newVersions: GitHubVersion[] = [
|
||||
{ type: "dotcom" },
|
||||
{ type: "ghes", version: "3.1.0" },
|
||||
{ type: GitHubVariant.DOTCOM },
|
||||
{ type: GitHubVariant.GHES, version: "3.1.0" },
|
||||
];
|
||||
const oldVersions: GitHubVersion[] = [
|
||||
{ type: "ghes", version: "2.22.1" },
|
||||
{ type: "ghes", version: "3.0.0" },
|
||||
{ type: GitHubVariant.GHES, version: "2.22.1" },
|
||||
{ type: GitHubVariant.GHES, version: "3.0.0" },
|
||||
];
|
||||
const allVersions = newVersions.concat(oldVersions);
|
||||
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ export function buildPayload(
|
|||
|
||||
// This behaviour can be made the default when support for GHES 3.0 is discontinued.
|
||||
if (
|
||||
gitHubVersion.type !== "ghes" ||
|
||||
gitHubVersion.type !== util.GitHubVariant.GHES ||
|
||||
semver.satisfies(gitHubVersion.version, `>=3.1`)
|
||||
) {
|
||||
if (
|
||||
|
|
|
|||
|
|
@ -221,26 +221,26 @@ test("getGitHubVersion", async (t) => {
|
|||
auth: "",
|
||||
url: "https://github.com",
|
||||
});
|
||||
t.deepEqual("dotcom", v.type);
|
||||
t.deepEqual(util.GitHubVariant.DOTCOM, v.type);
|
||||
|
||||
mockGetMetaVersionHeader("2.0");
|
||||
const v2 = await util.getGitHubVersion({
|
||||
auth: "",
|
||||
url: "https://ghe.example.com",
|
||||
});
|
||||
t.deepEqual({ type: "ghes", version: "2.0" }, v2);
|
||||
t.deepEqual({ type: util.GitHubVariant.GHES, version: "2.0" }, v2);
|
||||
|
||||
mockGetMetaVersionHeader("GitHub AE");
|
||||
const ghae = await util.getGitHubVersion({
|
||||
auth: "",
|
||||
url: "https://example.githubenterprise.com",
|
||||
});
|
||||
t.deepEqual({ type: "ghae" }, ghae);
|
||||
t.deepEqual({ type: util.GitHubVariant.GHAE }, ghae);
|
||||
|
||||
mockGetMetaVersionHeader(undefined);
|
||||
const v3 = await util.getGitHubVersion({
|
||||
auth: "",
|
||||
url: "https://ghe.example.com",
|
||||
});
|
||||
t.deepEqual({ type: "dotcom" }, v3);
|
||||
t.deepEqual({ type: util.GitHubVariant.DOTCOM }, v3);
|
||||
});
|
||||
|
|
|
|||
21
src/util.ts
21
src/util.ts
|
|
@ -219,17 +219,22 @@ const CODEQL_ACTION_WARNED_ABOUT_VERSION_ENV_VAR =
|
|||
"CODEQL_ACTION_WARNED_ABOUT_VERSION";
|
||||
let hasBeenWarnedAboutVersion = false;
|
||||
|
||||
export enum GitHubVariant {
|
||||
DOTCOM,
|
||||
GHES,
|
||||
GHAE,
|
||||
}
|
||||
export type GitHubVersion =
|
||||
| { type: "dotcom" }
|
||||
| { type: "ghae" }
|
||||
| { type: "ghes"; version: string };
|
||||
| { type: GitHubVariant.DOTCOM }
|
||||
| { type: GitHubVariant.GHAE }
|
||||
| { type: GitHubVariant.GHES; version: string };
|
||||
|
||||
export async function getGitHubVersion(
|
||||
apiDetails: GitHubApiDetails
|
||||
): Promise<GitHubVersion> {
|
||||
// We can avoid making an API request in the standard dotcom case
|
||||
if (parseGithubUrl(apiDetails.url) === GITHUB_DOTCOM_URL) {
|
||||
return { type: "dotcom" };
|
||||
return { type: GitHubVariant.DOTCOM };
|
||||
}
|
||||
|
||||
// Doesn't strictly have to be the meta endpoint as we're only
|
||||
|
|
@ -240,15 +245,15 @@ export async function getGitHubVersion(
|
|||
// This happens on dotcom, although we expect to have already returned in that
|
||||
// case. This can also serve as a fallback in cases we haven't foreseen.
|
||||
if (response.headers[GITHUB_ENTERPRISE_VERSION_HEADER] === undefined) {
|
||||
return { type: "dotcom" };
|
||||
return { type: GitHubVariant.DOTCOM };
|
||||
}
|
||||
|
||||
if (response.headers[GITHUB_ENTERPRISE_VERSION_HEADER] === "GitHub AE") {
|
||||
return { type: "ghae" };
|
||||
return { type: GitHubVariant.GHAE };
|
||||
}
|
||||
|
||||
const version = response.headers[GITHUB_ENTERPRISE_VERSION_HEADER] as string;
|
||||
return { type: "ghes", version };
|
||||
return { type: GitHubVariant.GHES, version };
|
||||
}
|
||||
|
||||
export function checkGitHubVersionInRange(
|
||||
|
|
@ -256,7 +261,7 @@ export function checkGitHubVersionInRange(
|
|||
mode: Mode,
|
||||
logger: Logger
|
||||
) {
|
||||
if (hasBeenWarnedAboutVersion || version.type !== "ghes") {
|
||||
if (hasBeenWarnedAboutVersion || version.type !== GitHubVariant.GHES) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue