mirror of
https://github.com/github/codeql-action.git
synced 2026-11-15 09:11:25 +00:00
Add repository property for file coverage on PRs
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
@@ -380,6 +380,7 @@ async function run(startedAt: Date) {
|
||||
debugMode,
|
||||
repositoryNwo,
|
||||
features,
|
||||
repositoryPropertiesResult.orElse({}),
|
||||
),
|
||||
logger,
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user