Add repository property for file coverage on PRs

This commit is contained in:
Henry Mercer
2026-03-02 19:20:43 +01:00
parent b895512248
commit b2fff91823
16 changed files with 54 additions and 3 deletions

View File

@@ -161731,6 +161731,7 @@ var semver2 = __toESM(require_semver2());
// src/feature-flags/properties.ts
var RepositoryPropertyName = /* @__PURE__ */ ((RepositoryPropertyName2) => {
RepositoryPropertyName2["DISABLE_OVERLAY"] = "github-codeql-disable-overlay";
RepositoryPropertyName2["ENABLE_FILE_COVERAGE_ON_PRS"] = "github-codeql-enable-file-coverage-on-prs";
RepositoryPropertyName2["EXTRA_QUERIES"] = "github-codeql-extra-queries";
return RepositoryPropertyName2;
})(RepositoryPropertyName || {});

1
lib/analyze-action.js generated
View File

@@ -107241,6 +107241,7 @@ var semver2 = __toESM(require_semver2());
// src/feature-flags/properties.ts
var RepositoryPropertyName = /* @__PURE__ */ ((RepositoryPropertyName2) => {
RepositoryPropertyName2["DISABLE_OVERLAY"] = "github-codeql-disable-overlay";
RepositoryPropertyName2["ENABLE_FILE_COVERAGE_ON_PRS"] = "github-codeql-enable-file-coverage-on-prs";
RepositoryPropertyName2["EXTRA_QUERIES"] = "github-codeql-extra-queries";
return RepositoryPropertyName2;
})(RepositoryPropertyName || {});

View File

@@ -103784,6 +103784,7 @@ var semver2 = __toESM(require_semver2());
// src/feature-flags/properties.ts
var RepositoryPropertyName = /* @__PURE__ */ ((RepositoryPropertyName2) => {
RepositoryPropertyName2["DISABLE_OVERLAY"] = "github-codeql-disable-overlay";
RepositoryPropertyName2["ENABLE_FILE_COVERAGE_ON_PRS"] = "github-codeql-enable-file-coverage-on-prs";
RepositoryPropertyName2["EXTRA_QUERIES"] = "github-codeql-extra-queries";
return RepositoryPropertyName2;
})(RepositoryPropertyName || {});

View File

@@ -165109,6 +165109,7 @@ var semver2 = __toESM(require_semver2());
// src/feature-flags/properties.ts
var RepositoryPropertyName = /* @__PURE__ */ ((RepositoryPropertyName2) => {
RepositoryPropertyName2["DISABLE_OVERLAY"] = "github-codeql-disable-overlay";
RepositoryPropertyName2["ENABLE_FILE_COVERAGE_ON_PRS"] = "github-codeql-enable-file-coverage-on-prs";
RepositoryPropertyName2["EXTRA_QUERIES"] = "github-codeql-extra-queries";
return RepositoryPropertyName2;
})(RepositoryPropertyName || {});

11
lib/init-action.js generated
View File

@@ -104404,11 +104404,13 @@ function getUnknownLanguagesError(languages) {
// src/feature-flags/properties.ts
var RepositoryPropertyName = /* @__PURE__ */ ((RepositoryPropertyName2) => {
RepositoryPropertyName2["DISABLE_OVERLAY"] = "github-codeql-disable-overlay";
RepositoryPropertyName2["ENABLE_FILE_COVERAGE_ON_PRS"] = "github-codeql-enable-file-coverage-on-prs";
RepositoryPropertyName2["EXTRA_QUERIES"] = "github-codeql-extra-queries";
return RepositoryPropertyName2;
})(RepositoryPropertyName || {});
var repositoryPropertyParsers = {
["github-codeql-disable-overlay" /* DISABLE_OVERLAY */]: parseBooleanRepositoryProperty,
["github-codeql-enable-file-coverage-on-prs" /* ENABLE_FILE_COVERAGE_ON_PRS */]: parseBooleanRepositoryProperty,
["github-codeql-extra-queries" /* EXTRA_QUERIES */]: parseStringRepositoryProperty
};
async function loadPropertiesFromApi(gitHubVersion, logger, repositoryNwo) {
@@ -109051,13 +109053,15 @@ function cleanupDatabaseClusterDirectory(config, logger, options = {}, rmSync2 =
}
}
}
async function getFileCoverageInformationEnabled(debugMode, repositoryNwo, features) {
async function getFileCoverageInformationEnabled(debugMode, repositoryNwo, features, repositoryProperties) {
return (
// Always enable file coverage information in debug mode
debugMode || // We're most interested in speeding up PRs, and we want to keep
// submitting file coverage information for the default branch since
// it is used to populate the status page.
!isAnalyzingPullRequest() || // For now, restrict this feature to the GitHub org
!isAnalyzingPullRequest() || // Allow repository owners to opt in to file coverage on PRs via a
// repository property.
repositoryProperties["github-codeql-enable-file-coverage-on-prs" /* ENABLE_FILE_COVERAGE_ON_PRS */] === true || // For now, restrict this feature to the GitHub org
repositoryNwo.owner !== "github" || !await features.getValue("skip_file_coverage_on_prs" /* SkipFileCoverageOnPrs */)
);
}
@@ -109701,7 +109705,8 @@ async function run(startedAt) {
enableFileCoverageInformation: await getFileCoverageInformationEnabled(
debugMode,
repositoryNwo,
features
features,
repositoryPropertiesResult.orElse({})
),
logger
});

View File

@@ -103783,6 +103783,7 @@ var semver2 = __toESM(require_semver2());
// src/feature-flags/properties.ts
var RepositoryPropertyName = /* @__PURE__ */ ((RepositoryPropertyName2) => {
RepositoryPropertyName2["DISABLE_OVERLAY"] = "github-codeql-disable-overlay";
RepositoryPropertyName2["ENABLE_FILE_COVERAGE_ON_PRS"] = "github-codeql-enable-file-coverage-on-prs";
RepositoryPropertyName2["EXTRA_QUERIES"] = "github-codeql-extra-queries";
return RepositoryPropertyName2;
})(RepositoryPropertyName || {});

View File

@@ -104777,6 +104777,7 @@ var semver5 = __toESM(require_semver2());
// src/feature-flags/properties.ts
var RepositoryPropertyName = /* @__PURE__ */ ((RepositoryPropertyName2) => {
RepositoryPropertyName2["DISABLE_OVERLAY"] = "github-codeql-disable-overlay";
RepositoryPropertyName2["ENABLE_FILE_COVERAGE_ON_PRS"] = "github-codeql-enable-file-coverage-on-prs";
RepositoryPropertyName2["EXTRA_QUERIES"] = "github-codeql-extra-queries";
return RepositoryPropertyName2;
})(RepositoryPropertyName || {});

View File

@@ -161366,6 +161366,7 @@ var semver2 = __toESM(require_semver2());
// src/feature-flags/properties.ts
var RepositoryPropertyName = /* @__PURE__ */ ((RepositoryPropertyName2) => {
RepositoryPropertyName2["DISABLE_OVERLAY"] = "github-codeql-disable-overlay";
RepositoryPropertyName2["ENABLE_FILE_COVERAGE_ON_PRS"] = "github-codeql-enable-file-coverage-on-prs";
RepositoryPropertyName2["EXTRA_QUERIES"] = "github-codeql-extra-queries";
return RepositoryPropertyName2;
})(RepositoryPropertyName || {});

View File

@@ -121384,6 +121384,7 @@ var semver5 = __toESM(require_semver2());
// src/feature-flags/properties.ts
var RepositoryPropertyName = /* @__PURE__ */ ((RepositoryPropertyName2) => {
RepositoryPropertyName2["DISABLE_OVERLAY"] = "github-codeql-disable-overlay";
RepositoryPropertyName2["ENABLE_FILE_COVERAGE_ON_PRS"] = "github-codeql-enable-file-coverage-on-prs";
RepositoryPropertyName2["EXTRA_QUERIES"] = "github-codeql-extra-queries";
return RepositoryPropertyName2;
})(RepositoryPropertyName || {});

1
lib/upload-lib.js generated
View File

@@ -106836,6 +106836,7 @@ var semver2 = __toESM(require_semver2());
// src/feature-flags/properties.ts
var RepositoryPropertyName = /* @__PURE__ */ ((RepositoryPropertyName2) => {
RepositoryPropertyName2["DISABLE_OVERLAY"] = "github-codeql-disable-overlay";
RepositoryPropertyName2["ENABLE_FILE_COVERAGE_ON_PRS"] = "github-codeql-enable-file-coverage-on-prs";
RepositoryPropertyName2["EXTRA_QUERIES"] = "github-codeql-extra-queries";
return RepositoryPropertyName2;
})(RepositoryPropertyName || {});

View File

@@ -161516,6 +161516,7 @@ var semver2 = __toESM(require_semver2());
// src/feature-flags/properties.ts
var RepositoryPropertyName = /* @__PURE__ */ ((RepositoryPropertyName2) => {
RepositoryPropertyName2["DISABLE_OVERLAY"] = "github-codeql-disable-overlay";
RepositoryPropertyName2["ENABLE_FILE_COVERAGE_ON_PRS"] = "github-codeql-enable-file-coverage-on-prs";
RepositoryPropertyName2["EXTRA_QUERIES"] = "github-codeql-extra-queries";
return RepositoryPropertyName2;
})(RepositoryPropertyName || {});

View File

@@ -107508,6 +107508,7 @@ var semver5 = __toESM(require_semver2());
// src/feature-flags/properties.ts
var RepositoryPropertyName = /* @__PURE__ */ ((RepositoryPropertyName2) => {
RepositoryPropertyName2["DISABLE_OVERLAY"] = "github-codeql-disable-overlay";
RepositoryPropertyName2["ENABLE_FILE_COVERAGE_ON_PRS"] = "github-codeql-enable-file-coverage-on-prs";
RepositoryPropertyName2["EXTRA_QUERIES"] = "github-codeql-extra-queries";
return RepositoryPropertyName2;
})(RepositoryPropertyName || {});

View File

@@ -8,12 +8,14 @@ import { GitHubVariant, GitHubVersion } from "../util";
*/
export enum RepositoryPropertyName {
DISABLE_OVERLAY = "github-codeql-disable-overlay",
ENABLE_FILE_COVERAGE_ON_PRS = "github-codeql-enable-file-coverage-on-prs",
EXTRA_QUERIES = "github-codeql-extra-queries",
}
/** Parsed types of the known repository properties. */
type AllRepositoryProperties = {
[RepositoryPropertyName.DISABLE_OVERLAY]: boolean;
[RepositoryPropertyName.ENABLE_FILE_COVERAGE_ON_PRS]: boolean;
[RepositoryPropertyName.EXTRA_QUERIES]: string;
};
@@ -29,6 +31,8 @@ const repositoryPropertyParsers: {
) => AllRepositoryProperties[K];
} = {
[RepositoryPropertyName.DISABLE_OVERLAY]: parseBooleanRepositoryProperty,
[RepositoryPropertyName.ENABLE_FILE_COVERAGE_ON_PRS]:
parseBooleanRepositoryProperty,
[RepositoryPropertyName.EXTRA_QUERIES]: parseStringRepositoryProperty,
};

View File

@@ -380,6 +380,7 @@ async function run(startedAt: Date) {
debugMode,
repositoryNwo,
features,
repositoryPropertiesResult.orElse({}),
),
logger,
});

View File

@@ -7,6 +7,7 @@ import * as sinon from "sinon";
import * as actionsUtil from "./actions-util";
import { createStubCodeQL } from "./codeql";
import { Feature } from "./feature-flags";
import { RepositoryPropertyName } from "./feature-flags/properties";
import {
checkPacksForOverlayCompatibility,
cleanupDatabaseClusterDirectory,
@@ -455,6 +456,7 @@ test("file coverage information enabled when debugMode is true", async (t) => {
true, // debugMode
parseRepositoryNwo("github/codeql-action"),
createFeatures([Feature.SkipFileCoverageOnPrs]),
{},
),
);
});
@@ -467,6 +469,7 @@ test("file coverage information enabled when not analyzing a pull request", asyn
false, // debugMode
parseRepositoryNwo("github/codeql-action"),
createFeatures([Feature.SkipFileCoverageOnPrs]),
{},
),
);
});
@@ -479,6 +482,7 @@ test("file coverage information enabled when owner is not 'github'", async (t) =
false, // debugMode
parseRepositoryNwo("other-org/some-repo"),
createFeatures([Feature.SkipFileCoverageOnPrs]),
{},
),
);
});
@@ -491,6 +495,7 @@ test("file coverage information enabled when feature flag is not enabled", async
false, // debugMode
parseRepositoryNwo("github/codeql-action"),
createFeatures([]),
{},
),
);
});
@@ -503,6 +508,22 @@ test("file coverage information disabled when all conditions for skipping are me
false, // debugMode
parseRepositoryNwo("github/codeql-action"),
createFeatures([Feature.SkipFileCoverageOnPrs]),
{},
),
);
});
test("file coverage information enabled when repository property enables it on PRs", async (t) => {
sinon.stub(actionsUtil, "isAnalyzingPullRequest").returns(true);
t.true(
await getFileCoverageInformationEnabled(
false, // debugMode
parseRepositoryNwo("github/codeql-action"),
createFeatures([Feature.SkipFileCoverageOnPrs]),
{
[RepositoryPropertyName.ENABLE_FILE_COVERAGE_ON_PRS]: true,
},
),
);
});

View File

@@ -18,6 +18,10 @@ import {
Feature,
FeatureEnablement,
} from "./feature-flags";
import {
RepositoryProperties,
RepositoryPropertyName,
} from "./feature-flags/properties";
import { KnownLanguage, Language } from "./languages";
import { Logger, withGroupAsync } from "./logging";
import { RepositoryNwo } from "./repository";
@@ -302,6 +306,7 @@ export async function getFileCoverageInformationEnabled(
debugMode: boolean,
repositoryNwo: RepositoryNwo,
features: FeatureEnablement,
repositoryProperties: RepositoryProperties,
): Promise<boolean> {
return (
// Always enable file coverage information in debug mode
@@ -310,6 +315,10 @@ export async function getFileCoverageInformationEnabled(
// submitting file coverage information for the default branch since
// it is used to populate the status page.
!isAnalyzingPullRequest() ||
// Allow repository owners to opt in to file coverage on PRs via a
// repository property.
repositoryProperties[RepositoryPropertyName.ENABLE_FILE_COVERAGE_ON_PRS] ===
true ||
// For now, restrict this feature to the GitHub org
repositoryNwo.owner !== "github" ||
!(await features.getValue(Feature.SkipFileCoverageOnPrs))