mirror of
https://github.com/github/codeql-action.git
synced 2026-04-05 03:02:16 +00:00
Check that we are on dotcom
This commit is contained in:
@@ -5,6 +5,7 @@ import * as api from "../api-client";
|
||||
import { getRunnerLogger } from "../logging";
|
||||
import { parseRepositoryNwo } from "../repository";
|
||||
import { setupTests } from "../testing-utils";
|
||||
import * as util from "../util";
|
||||
|
||||
import * as properties from "./properties";
|
||||
|
||||
@@ -20,7 +21,13 @@ test("loadPropertiesFromApi throws if response data is not an array", async (t)
|
||||
const logger = getRunnerLogger(true);
|
||||
const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
|
||||
await t.throwsAsync(
|
||||
properties.loadPropertiesFromApi(logger, mockRepositoryNwo),
|
||||
properties.loadPropertiesFromApi(
|
||||
{
|
||||
type: util.GitHubVariant.DOTCOM,
|
||||
},
|
||||
logger,
|
||||
mockRepositoryNwo,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -34,10 +41,39 @@ test("loadPropertiesFromApi throws if response data contains unexpected objects"
|
||||
const logger = getRunnerLogger(true);
|
||||
const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
|
||||
await t.throwsAsync(
|
||||
properties.loadPropertiesFromApi(logger, mockRepositoryNwo),
|
||||
properties.loadPropertiesFromApi(
|
||||
{
|
||||
type: util.GitHubVariant.DOTCOM,
|
||||
},
|
||||
logger,
|
||||
mockRepositoryNwo,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test("loadPropertiesFromApi returns empty object if not on dotcom", async (t) => {
|
||||
sinon.stub(api, "getRepositoryProperties").resolves({
|
||||
headers: {},
|
||||
status: 200,
|
||||
url: "",
|
||||
data: [
|
||||
{ property_name: "github-codeql-extra-queries", value: "+queries" },
|
||||
{ property_name: "unknown-property", value: "something" },
|
||||
] satisfies properties.RepositoryProperty[],
|
||||
});
|
||||
const logger = getRunnerLogger(true);
|
||||
const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
|
||||
const response = await properties.loadPropertiesFromApi(
|
||||
{
|
||||
type: util.GitHubVariant.GHES,
|
||||
version: "",
|
||||
},
|
||||
logger,
|
||||
mockRepositoryNwo,
|
||||
);
|
||||
t.deepEqual(response, {});
|
||||
});
|
||||
|
||||
test("loadPropertiesFromApi loads known properties", async (t) => {
|
||||
sinon.stub(api, "getRepositoryProperties").resolves({
|
||||
headers: {},
|
||||
@@ -51,6 +87,9 @@ test("loadPropertiesFromApi loads known properties", async (t) => {
|
||||
const logger = getRunnerLogger(true);
|
||||
const mockRepositoryNwo = parseRepositoryNwo("owner/repo");
|
||||
const response = await properties.loadPropertiesFromApi(
|
||||
{
|
||||
type: util.GitHubVariant.DOTCOM,
|
||||
},
|
||||
logger,
|
||||
mockRepositoryNwo,
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { getRepositoryProperties } from "../api-client";
|
||||
import { Logger } from "../logging";
|
||||
import { RepositoryNwo } from "../repository";
|
||||
import { GitHubVariant, GitHubVersion } from "../util";
|
||||
|
||||
/**
|
||||
* Enumerates repository property names that have some meaning to us.
|
||||
@@ -37,9 +38,16 @@ export type RepositoryProperties = Partial<
|
||||
* @returns Returns a partial mapping from `RepositoryPropertyName` to values.
|
||||
*/
|
||||
export async function loadPropertiesFromApi(
|
||||
gitHubVersion: GitHubVersion,
|
||||
logger: Logger,
|
||||
repositoryNwo: RepositoryNwo,
|
||||
): Promise<RepositoryProperties> {
|
||||
// TODO: To be safe for now; later we should replace this with a version check once we know
|
||||
// which version of GHES we expect this to be supported by.
|
||||
if (gitHubVersion.type !== GitHubVariant.DOTCOM) {
|
||||
return {};
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await getRepositoryProperties(repositoryNwo);
|
||||
const remoteProperties = response.data as GitHubPropertiesResponse;
|
||||
|
||||
@@ -202,7 +202,7 @@ async function run() {
|
||||
Feature.UseRepositoryProperties,
|
||||
);
|
||||
const repositoryProperties = enableRepoProps
|
||||
? await loadPropertiesFromApi(logger, repositoryNwo)
|
||||
? await loadPropertiesFromApi(gitHubVersion, logger, repositoryNwo)
|
||||
: {};
|
||||
|
||||
const jobRunUuid = uuidV4();
|
||||
|
||||
Reference in New Issue
Block a user