mirror of
https://github.com/github/codeql-action.git
synced 2026-10-03 17:41:28 +00:00
Reduce duplication of getFileCoverageInformationEnabled
This commit is contained in:
37
lib/init-action.js
generated
37
lib/init-action.js
generated
@@ -109094,15 +109094,19 @@ function cleanupDatabaseClusterDirectory(config, logger, options = {}, rmSync2 =
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function getFileCoverageInformationEnabled(debugMode, codeql, features, repositoryProperties) {
|
async function getFileCoverageInformationEnabled(debugMode, codeql, features, repositoryProperties) {
|
||||||
return (
|
if (debugMode) {
|
||||||
// Always enable file coverage information in debug mode
|
return { enabled: true, enabledByRepositoryProperty: false };
|
||||||
debugMode || // We're most interested in speeding up PRs, and we want to keep
|
}
|
||||||
// submitting file coverage information for the default branch since
|
if (!isAnalyzingPullRequest()) {
|
||||||
// it is used to populate the status page.
|
return { enabled: true, enabledByRepositoryProperty: false };
|
||||||
!isAnalyzingPullRequest() || // Allow repositories to opt in to file coverage information on PRs
|
}
|
||||||
// using a repository property.
|
if (!await features.getValue("skip_file_coverage_on_prs" /* SkipFileCoverageOnPrs */, codeql)) {
|
||||||
repositoryProperties["github-codeql-file-coverage-on-prs" /* FILE_COVERAGE_ON_PRS */] === true || !await features.getValue("skip_file_coverage_on_prs" /* SkipFileCoverageOnPrs */, codeql)
|
return { enabled: true, enabledByRepositoryProperty: false };
|
||||||
);
|
}
|
||||||
|
if (repositoryProperties["github-codeql-file-coverage-on-prs" /* FILE_COVERAGE_ON_PRS */] === true) {
|
||||||
|
return { enabled: true, enabledByRepositoryProperty: true };
|
||||||
|
}
|
||||||
|
return { enabled: false, enabledByRepositoryProperty: false };
|
||||||
}
|
}
|
||||||
|
|
||||||
// src/status-report.ts
|
// src/status-report.ts
|
||||||
@@ -109714,6 +109718,12 @@ async function run(startedAt) {
|
|||||||
analysisKinds = await getAnalysisKinds(logger);
|
analysisKinds = await getAnalysisKinds(logger);
|
||||||
const debugMode = getOptionalInput("debug") === "true" || core13.isDebug();
|
const debugMode = getOptionalInput("debug") === "true" || core13.isDebug();
|
||||||
const repositoryProperties = repositoryPropertiesResult.orElse({});
|
const repositoryProperties = repositoryPropertiesResult.orElse({});
|
||||||
|
const fileCoverageResult = await getFileCoverageInformationEnabled(
|
||||||
|
debugMode,
|
||||||
|
codeql,
|
||||||
|
features,
|
||||||
|
repositoryProperties
|
||||||
|
);
|
||||||
config = await initConfig2(features, {
|
config = await initConfig2(features, {
|
||||||
analysisKinds,
|
analysisKinds,
|
||||||
languagesInput: getOptionalInput("languages"),
|
languagesInput: getOptionalInput("languages"),
|
||||||
@@ -109742,12 +109752,7 @@ async function run(startedAt) {
|
|||||||
apiDetails,
|
apiDetails,
|
||||||
features,
|
features,
|
||||||
repositoryProperties,
|
repositoryProperties,
|
||||||
enableFileCoverageInformation: await getFileCoverageInformationEnabled(
|
enableFileCoverageInformation: fileCoverageResult.enabled,
|
||||||
debugMode,
|
|
||||||
codeql,
|
|
||||||
features,
|
|
||||||
repositoryProperties
|
|
||||||
),
|
|
||||||
logger
|
logger
|
||||||
});
|
});
|
||||||
if (repositoryPropertiesResult.isFailure()) {
|
if (repositoryPropertiesResult.isFailure()) {
|
||||||
@@ -109762,7 +109767,7 @@ async function run(startedAt) {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (config.enableFileCoverageInformation && isAnalyzingPullRequest() && await features.getValue("skip_file_coverage_on_prs" /* SkipFileCoverageOnPrs */, codeql) && repositoryProperties["github-codeql-file-coverage-on-prs" /* FILE_COVERAGE_ON_PRS */] === true) {
|
if (fileCoverageResult.enabledByRepositoryProperty) {
|
||||||
addNoLanguageDiagnostic(
|
addNoLanguageDiagnostic(
|
||||||
config,
|
config,
|
||||||
makeTelemetryDiagnostic(
|
makeTelemetryDiagnostic(
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import {
|
|||||||
getOptionalInput,
|
getOptionalInput,
|
||||||
getRequiredInput,
|
getRequiredInput,
|
||||||
getTemporaryDirectory,
|
getTemporaryDirectory,
|
||||||
isAnalyzingPullRequest,
|
|
||||||
persistInputs,
|
persistInputs,
|
||||||
} from "./actions-util";
|
} from "./actions-util";
|
||||||
import { AnalysisKind, getAnalysisKinds } from "./analyses";
|
import { AnalysisKind, getAnalysisKinds } from "./analyses";
|
||||||
@@ -43,7 +42,6 @@ import { Feature, FeatureEnablement, initFeatures } from "./feature-flags";
|
|||||||
import {
|
import {
|
||||||
loadPropertiesFromApi,
|
loadPropertiesFromApi,
|
||||||
RepositoryProperties,
|
RepositoryProperties,
|
||||||
RepositoryPropertyName,
|
|
||||||
} from "./feature-flags/properties";
|
} from "./feature-flags/properties";
|
||||||
import {
|
import {
|
||||||
checkInstallPython311,
|
checkInstallPython311,
|
||||||
@@ -349,6 +347,13 @@ async function run(startedAt: Date) {
|
|||||||
analysisKinds = await getAnalysisKinds(logger);
|
analysisKinds = await getAnalysisKinds(logger);
|
||||||
const debugMode = getOptionalInput("debug") === "true" || core.isDebug();
|
const debugMode = getOptionalInput("debug") === "true" || core.isDebug();
|
||||||
const repositoryProperties = repositoryPropertiesResult.orElse({});
|
const repositoryProperties = repositoryPropertiesResult.orElse({});
|
||||||
|
const fileCoverageResult = await getFileCoverageInformationEnabled(
|
||||||
|
debugMode,
|
||||||
|
codeql,
|
||||||
|
features,
|
||||||
|
repositoryProperties,
|
||||||
|
);
|
||||||
|
|
||||||
config = await initConfig(features, {
|
config = await initConfig(features, {
|
||||||
analysisKinds,
|
analysisKinds,
|
||||||
languagesInput: getOptionalInput("languages"),
|
languagesInput: getOptionalInput("languages"),
|
||||||
@@ -379,12 +384,7 @@ async function run(startedAt: Date) {
|
|||||||
apiDetails,
|
apiDetails,
|
||||||
features,
|
features,
|
||||||
repositoryProperties,
|
repositoryProperties,
|
||||||
enableFileCoverageInformation: await getFileCoverageInformationEnabled(
|
enableFileCoverageInformation: fileCoverageResult.enabled,
|
||||||
debugMode,
|
|
||||||
codeql,
|
|
||||||
features,
|
|
||||||
repositoryProperties,
|
|
||||||
),
|
|
||||||
logger,
|
logger,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -401,12 +401,7 @@ async function run(startedAt: Date) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (fileCoverageResult.enabledByRepositoryProperty) {
|
||||||
config.enableFileCoverageInformation &&
|
|
||||||
isAnalyzingPullRequest() &&
|
|
||||||
(await features.getValue(Feature.SkipFileCoverageOnPrs, codeql)) &&
|
|
||||||
repositoryProperties[RepositoryPropertyName.FILE_COVERAGE_ON_PRS] === true
|
|
||||||
) {
|
|
||||||
addNoLanguageDiagnostic(
|
addNoLanguageDiagnostic(
|
||||||
config,
|
config,
|
||||||
makeTelemetryDiagnostic(
|
makeTelemetryDiagnostic(
|
||||||
|
|||||||
@@ -452,14 +452,14 @@ test(
|
|||||||
);
|
);
|
||||||
|
|
||||||
test("file coverage information enabled when debugMode is true", async (t) => {
|
test("file coverage information enabled when debugMode is true", async (t) => {
|
||||||
t.true(
|
const result = await getFileCoverageInformationEnabled(
|
||||||
await getFileCoverageInformationEnabled(
|
true, // debugMode
|
||||||
true, // debugMode
|
createStubCodeQL({}),
|
||||||
createStubCodeQL({}),
|
createFeatures([Feature.SkipFileCoverageOnPrs]),
|
||||||
createFeatures([Feature.SkipFileCoverageOnPrs]),
|
{},
|
||||||
{},
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
t.true(result.enabled);
|
||||||
|
t.false(result.enabledByRepositoryProperty);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.serial(
|
test.serial(
|
||||||
@@ -467,14 +467,14 @@ test.serial(
|
|||||||
async (t) => {
|
async (t) => {
|
||||||
sinon.stub(actionsUtil, "isAnalyzingPullRequest").returns(false);
|
sinon.stub(actionsUtil, "isAnalyzingPullRequest").returns(false);
|
||||||
|
|
||||||
t.true(
|
const result = await getFileCoverageInformationEnabled(
|
||||||
await getFileCoverageInformationEnabled(
|
false, // debugMode
|
||||||
false, // debugMode
|
createStubCodeQL({}),
|
||||||
createStubCodeQL({}),
|
createFeatures([Feature.SkipFileCoverageOnPrs]),
|
||||||
createFeatures([Feature.SkipFileCoverageOnPrs]),
|
{},
|
||||||
{},
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
t.true(result.enabled);
|
||||||
|
t.false(result.enabledByRepositoryProperty);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -483,14 +483,14 @@ test.serial(
|
|||||||
async (t) => {
|
async (t) => {
|
||||||
sinon.stub(actionsUtil, "isAnalyzingPullRequest").returns(true);
|
sinon.stub(actionsUtil, "isAnalyzingPullRequest").returns(true);
|
||||||
|
|
||||||
t.true(
|
const result = await getFileCoverageInformationEnabled(
|
||||||
await getFileCoverageInformationEnabled(
|
false, // debugMode
|
||||||
false, // debugMode
|
createStubCodeQL({}),
|
||||||
createStubCodeQL({}),
|
createFeatures([]),
|
||||||
createFeatures([]),
|
{},
|
||||||
{},
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
t.true(result.enabled);
|
||||||
|
t.false(result.enabledByRepositoryProperty);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -499,16 +499,16 @@ test.serial(
|
|||||||
async (t) => {
|
async (t) => {
|
||||||
sinon.stub(actionsUtil, "isAnalyzingPullRequest").returns(true);
|
sinon.stub(actionsUtil, "isAnalyzingPullRequest").returns(true);
|
||||||
|
|
||||||
t.true(
|
const result = await getFileCoverageInformationEnabled(
|
||||||
await getFileCoverageInformationEnabled(
|
false, // debugMode
|
||||||
false, // debugMode
|
createStubCodeQL({}),
|
||||||
createStubCodeQL({}),
|
createFeatures([Feature.SkipFileCoverageOnPrs]),
|
||||||
createFeatures([Feature.SkipFileCoverageOnPrs]),
|
{
|
||||||
{
|
"github-codeql-file-coverage-on-prs": true,
|
||||||
"github-codeql-file-coverage-on-prs": true,
|
},
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
t.true(result.enabled);
|
||||||
|
t.true(result.enabledByRepositoryProperty);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -517,13 +517,13 @@ test.serial(
|
|||||||
async (t) => {
|
async (t) => {
|
||||||
sinon.stub(actionsUtil, "isAnalyzingPullRequest").returns(true);
|
sinon.stub(actionsUtil, "isAnalyzingPullRequest").returns(true);
|
||||||
|
|
||||||
t.false(
|
const result = await getFileCoverageInformationEnabled(
|
||||||
await getFileCoverageInformationEnabled(
|
false, // debugMode
|
||||||
false, // debugMode
|
createStubCodeQL({}),
|
||||||
createStubCodeQL({}),
|
createFeatures([Feature.SkipFileCoverageOnPrs]),
|
||||||
createFeatures([Feature.SkipFileCoverageOnPrs]),
|
{},
|
||||||
{},
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
t.false(result.enabled);
|
||||||
|
t.false(result.enabledByRepositoryProperty);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
42
src/init.ts
42
src/init.ts
@@ -306,18 +306,32 @@ export async function getFileCoverageInformationEnabled(
|
|||||||
codeql: CodeQL,
|
codeql: CodeQL,
|
||||||
features: FeatureEnablement,
|
features: FeatureEnablement,
|
||||||
repositoryProperties: RepositoryProperties,
|
repositoryProperties: RepositoryProperties,
|
||||||
): Promise<boolean> {
|
): Promise<{
|
||||||
return (
|
enabled: boolean;
|
||||||
// Always enable file coverage information in debug mode
|
enabledByRepositoryProperty: boolean;
|
||||||
debugMode ||
|
}> {
|
||||||
// We're most interested in speeding up PRs, and we want to keep
|
// Always enable file coverage information in debug mode
|
||||||
// submitting file coverage information for the default branch since
|
if (debugMode) {
|
||||||
// it is used to populate the status page.
|
return { enabled: true, enabledByRepositoryProperty: false };
|
||||||
!isAnalyzingPullRequest() ||
|
}
|
||||||
// Allow repositories to opt in to file coverage information on PRs
|
// We're most interested in speeding up PRs, and we want to keep
|
||||||
// using a repository property.
|
// submitting file coverage information for the default branch since
|
||||||
repositoryProperties[RepositoryPropertyName.FILE_COVERAGE_ON_PRS] ===
|
// it is used to populate the status page.
|
||||||
true ||
|
if (!isAnalyzingPullRequest()) {
|
||||||
!(await features.getValue(Feature.SkipFileCoverageOnPrs, codeql))
|
return { enabled: true, enabledByRepositoryProperty: false };
|
||||||
);
|
}
|
||||||
|
// If the feature is disabled, then maintain the previous behavior of
|
||||||
|
// unconditionally computing file coverage information.
|
||||||
|
if (!(await features.getValue(Feature.SkipFileCoverageOnPrs, codeql))) {
|
||||||
|
return { enabled: true, enabledByRepositoryProperty: false };
|
||||||
|
}
|
||||||
|
// Allow repositories to opt in to file coverage information on PRs
|
||||||
|
// using a repository property.
|
||||||
|
if (
|
||||||
|
repositoryProperties[RepositoryPropertyName.FILE_COVERAGE_ON_PRS] === true
|
||||||
|
) {
|
||||||
|
return { enabled: true, enabledByRepositoryProperty: true };
|
||||||
|
}
|
||||||
|
// Otherwise, disable file coverage information on PRs to speed up analysis.
|
||||||
|
return { enabled: false, enabledByRepositoryProperty: false };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user