Address review, add test.

This commit is contained in:
Cornelius Riemenschneider 2022-07-18 10:37:04 +00:00 committed by GitHub
parent 01fa64cb90
commit 75afbf4a30
6 changed files with 67 additions and 20 deletions

View file

@ -28,7 +28,7 @@ export class GitHubFeatureFlags implements FeatureFlags {
private apiDetails: GitHubApiDetails,
private repositoryNwo: RepositoryNwo,
private logger: Logger
) {}
) { }
async getValue(flag: FeatureFlag): Promise<boolean> {
const response = await this.getApiResponse();
@ -38,14 +38,14 @@ export class GitHubFeatureFlags implements FeatureFlags {
);
return false;
}
const flag_value = response[flag];
if (flag_value === undefined) {
const flagValue = response[flag];
if (flagValue === undefined) {
this.logger.debug(
`Feature flag '${flag}' undefined in API response, considering it disabled.`
);
return false;
}
return flag_value;
return flagValue;
}
private async getApiResponse(): Promise<FeatureFlagsApiResponse> {
@ -71,9 +71,9 @@ export class GitHubFeatureFlags implements FeatureFlags {
if (util.isHTTPError(e) && e.status === 403) {
this.logger.warning(
"This run of the CodeQL Action does not have permission to access Code Scanning API endpoints. " +
"As a result, it will not be opted into any experimental features. " +
"This could be because the Action is running on a pull request from a fork. If not, " +
`please ensure the Action has the 'security-events: write' permission. Details: ${e}`
"As a result, it will not be opted into any experimental features. " +
"This could be because the Action is running on a pull request from a fork. If not, " +
`please ensure the Action has the 'security-events: write' permission. Details: ${e}`
);
} else {
// Some feature flags, such as `ml_powered_queries_enabled` affect the produced alerts.