mirror of
https://github.com/github/codeql-action.git
synced 2026-04-27 17:39:15 +00:00
Remove isCCR
This commit is contained in:
@@ -5,14 +5,13 @@ import {
|
||||
fixCodeQualityCategory,
|
||||
getPullRequestBranches,
|
||||
isAnalyzingPullRequest,
|
||||
isCCR,
|
||||
isDefaultSetup,
|
||||
isDynamicWorkflow,
|
||||
} from "./actions-util";
|
||||
import { computeAutomationID } from "./api-client";
|
||||
import { EnvVar } from "./environment";
|
||||
import { getRunnerLogger } from "./logging";
|
||||
import { mockCCR, setupTests } from "./testing-utils";
|
||||
import { setupTests } from "./testing-utils";
|
||||
import { initializeEnvironment } from "./util";
|
||||
|
||||
setupTests(test);
|
||||
@@ -257,16 +256,8 @@ test("isDynamicWorkflow() returns true if event name is `dynamic`", (t) => {
|
||||
t.false(isDynamicWorkflow());
|
||||
});
|
||||
|
||||
test("isCCR() returns true when expected", (t) => {
|
||||
mockCCR();
|
||||
|
||||
t.assert(isCCR());
|
||||
t.false(isDefaultSetup());
|
||||
});
|
||||
|
||||
test("isDefaultSetup() returns true when expected", (t) => {
|
||||
process.env.GITHUB_EVENT_NAME = "dynamic";
|
||||
process.env[EnvVar.ANALYSIS_KEY] = "dynamic/github-code-scanning";
|
||||
t.assert(isDefaultSetup());
|
||||
t.false(isCCR());
|
||||
});
|
||||
|
||||
+1
-10
@@ -8,7 +8,6 @@ import * as io from "@actions/io";
|
||||
import { JSONSchemaForNPMPackageJsonFiles } from "@schemastore/package";
|
||||
|
||||
import type { Config } from "./config-utils";
|
||||
import { EnvVar } from "./environment";
|
||||
import { Logger } from "./logging";
|
||||
import {
|
||||
doesDirectoryExist,
|
||||
@@ -255,15 +254,7 @@ export function isDynamicWorkflow(): boolean {
|
||||
|
||||
/** Determines whether we are running in default setup. */
|
||||
export function isDefaultSetup(): boolean {
|
||||
return isDynamicWorkflow() && !isCCR();
|
||||
}
|
||||
|
||||
/* The analysis key prefix used for CCR. */
|
||||
const CCR_KEY_PREFIX = "dynamic/copilot-pull-request-reviewer";
|
||||
|
||||
/** Determines whether we are running in CCR. */
|
||||
export function isCCR(): boolean {
|
||||
return process.env[EnvVar.ANALYSIS_KEY]?.startsWith(CCR_KEY_PREFIX) || false;
|
||||
return isDynamicWorkflow();
|
||||
}
|
||||
|
||||
export function prettyPrintInvocation(cmd: string, args: string[]): string {
|
||||
|
||||
+6
-3
@@ -7,7 +7,7 @@ import * as yaml from "js-yaml";
|
||||
import {
|
||||
getActionVersion,
|
||||
isAnalyzingPullRequest,
|
||||
isCCR,
|
||||
isDynamicWorkflow,
|
||||
} from "./actions-util";
|
||||
import {
|
||||
AnalysisConfig,
|
||||
@@ -964,10 +964,13 @@ export async function initConfig(
|
||||
}
|
||||
}
|
||||
|
||||
// If we are in CCR or the corresponding FF is enabled, try to determine
|
||||
// If we are in a dynamic workflow or the corresponding FF is enabled, try to determine
|
||||
// which files in the repository are marked as generated and add them to
|
||||
// the `paths-ignore` configuration.
|
||||
if ((await features.getValue(Feature.IgnoreGeneratedFiles)) && isCCR()) {
|
||||
if (
|
||||
(await features.getValue(Feature.IgnoreGeneratedFiles)) &&
|
||||
isDynamicWorkflow()
|
||||
) {
|
||||
try {
|
||||
const generatedFilesCheckStartedAt = performance.now();
|
||||
const generatedFiles = await getGeneratedFiles(inputs.sourceRoot);
|
||||
|
||||
@@ -21,7 +21,6 @@ import {
|
||||
getRecordingLogger,
|
||||
initializeFeatures,
|
||||
LoggedMessage,
|
||||
mockCCR,
|
||||
mockCodeQLVersion,
|
||||
mockFeatureFlagApiEndpoint,
|
||||
setupTests,
|
||||
@@ -535,12 +534,3 @@ test("initFeatures returns a `Features` instance by default", async (t) => {
|
||||
t.is("Features", features.constructor.name);
|
||||
});
|
||||
});
|
||||
|
||||
test("initFeatures returns an `OfflineFeatures` instance in CCR", async (t) => {
|
||||
await withTmpDir(async (tmpDir) => {
|
||||
mockCCR();
|
||||
|
||||
const features = setUpFeatureFlagTests(tmpDir);
|
||||
t.is("OfflineFeatures", features.constructor.name);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,7 +3,6 @@ import * as path from "path";
|
||||
|
||||
import * as semver from "semver";
|
||||
|
||||
import { isCCR } from "./actions-util";
|
||||
import { getApiClient } from "./api-client";
|
||||
import type { CodeQL } from "./codeql";
|
||||
import * as defaults from "./defaults.json";
|
||||
@@ -818,11 +817,6 @@ export function initFeatures(
|
||||
"Not running against github.com. Using default values for all features.",
|
||||
);
|
||||
return new OfflineFeatures(logger);
|
||||
} else if (isCCR()) {
|
||||
logger.debug(
|
||||
"Querying feature flags is not currently supported in Copilot Code Review. Using offline data for all features.",
|
||||
);
|
||||
return new OfflineFeatures(logger);
|
||||
} else {
|
||||
return new Features(repositoryNwo, tempDir, logger);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,9 @@ import {
|
||||
checkExpectedLogMessages,
|
||||
getRecordingLogger,
|
||||
LoggedMessage,
|
||||
mockCCR,
|
||||
setupTests,
|
||||
} from "../testing-utils";
|
||||
import { initializeEnvironment, withTmpDir } from "../util";
|
||||
import { GitHubVariant, initializeEnvironment, withTmpDir } from "../util";
|
||||
|
||||
import {
|
||||
assertAllFeaturesHaveDefaultValues,
|
||||
@@ -20,14 +19,16 @@ setupTests(test);
|
||||
|
||||
test.beforeEach(() => {
|
||||
initializeEnvironment("1.2.3");
|
||||
mockCCR();
|
||||
});
|
||||
|
||||
test("OfflineFeatures makes no API requests", async (t) => {
|
||||
await withTmpDir(async (tmpDir) => {
|
||||
const loggedMessages: LoggedMessage[] = [];
|
||||
const logger = getRecordingLogger(loggedMessages);
|
||||
const features = setUpFeatureFlagTests(tmpDir, logger);
|
||||
const features = setUpFeatureFlagTests(tmpDir, logger, {
|
||||
type: GitHubVariant.GHES,
|
||||
version: "3.0.0",
|
||||
});
|
||||
t.is("OfflineFeatures", features.constructor.name);
|
||||
|
||||
sinon
|
||||
@@ -36,7 +37,7 @@ test("OfflineFeatures makes no API requests", async (t) => {
|
||||
|
||||
await assertAllFeaturesHaveDefaultValues(t, features);
|
||||
checkExpectedLogMessages(t, loggedMessages, [
|
||||
"Querying feature flags is not currently supported in Copilot Code Review. Using offline data for all features.",
|
||||
"Not running against github.com. Using default values for all features.",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,7 +14,6 @@ import { CachingKind } from "./caching-utils";
|
||||
import * as codeql from "./codeql";
|
||||
import { Config } from "./config-utils";
|
||||
import * as defaults from "./defaults.json";
|
||||
import { EnvVar } from "./environment";
|
||||
import {
|
||||
CodeQLDefaultVersionInfo,
|
||||
Feature,
|
||||
@@ -505,9 +504,3 @@ export function makeTestToken(length: number = 36) {
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
return chars.repeat(Math.ceil(length / chars.length)).slice(0, length);
|
||||
}
|
||||
|
||||
/** Sets the environment variables needed for isCCR() to be `true`. */
|
||||
export function mockCCR() {
|
||||
process.env.GITHUB_EVENT_NAME = "dynamic";
|
||||
process.env[EnvVar.ANALYSIS_KEY] = "dynamic/copilot-pull-request-reviewer";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user