Skip to content

Commit

Permalink
Add debug logging for feature flag enablement
Browse files Browse the repository at this point in the history
  • Loading branch information
henrymercer committed Mar 14, 2023
1 parent ec29823 commit d9ceda3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
19 changes: 17 additions & 2 deletions lib/feature-flags.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/feature-flags.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 33 additions & 4 deletions src/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class Features implements FeatureEnablement {
gitHubVersion: util.GitHubVersion,
repositoryNwo: RepositoryNwo,
tempDir: string,
logger: Logger
private readonly logger: Logger
) {
this.gitHubFeatureFlags = new GitHubFeatureFlags(
gitHubVersion,
Expand Down Expand Up @@ -135,26 +135,55 @@ export class Features implements FeatureEnablement {

// Do not use this feature if user explicitly disables it via an environment variable.
if (envVar === "false") {
this.logger.debug(
`Feature ${feature} is disabled via the environment variable ${featureConfig[feature].envVar}.`
);
return false;
}

// Never use this feature if the CLI version explicitly can't support it.
const minimumVersion = featureConfig[feature].minimumVersion;
if (codeql && minimumVersion) {
if (!(await util.codeQlVersionAbove(codeql, minimumVersion))) {
this.logger.debug(
`Feature ${feature} is disabled because the CodeQL CLI version is older than the minimum ` +
`version ${minimumVersion}.`
);
return false;
} else {
this.logger.debug(
`CodeQL CLI version ${await codeql.getVersion()} is newer than the minimum ` +
`version ${minimumVersion} for feature ${feature}.`
);
}
}

// Use this feature if user explicitly enables it via an environment variable.
if (envVar === "true") {
this.logger.debug(
`Feature ${feature} is enabled via the environment variable ${featureConfig[feature].envVar}.`
);
return true;
}

// Ask the GitHub API if the feature is enabled.
return (
(await this.gitHubFeatureFlags.getValue(feature)) ??
featureConfig[feature].defaultValue
const apiValue = await this.gitHubFeatureFlags.getValue(feature);
if (apiValue !== undefined) {
this.logger.debug(
`Feature ${feature} is ${
apiValue ? "enabled" : "disabled"
} via the GitHub API.`
);
return apiValue;
}

const defaultValue = featureConfig[feature].defaultValue;
this.logger.debug(
`Feature ${feature} is ${
defaultValue ? "enabled" : "disabled"
} due to its default value.`
);
return defaultValue;
}
}

Expand Down

0 comments on commit d9ceda3

Please sign in to comment.