From 368f322a0919b4d86ca94485b654131d3bd32cf9 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Thu, 12 Feb 2026 17:42:40 +0000 Subject: [PATCH] Add `OfflineFeatures` class --- lib/analyze-action.js | 87 ++++++++++++++++++------ lib/autobuild-action.js | 87 ++++++++++++++++++------ lib/init-action-post.js | 87 ++++++++++++++++++------ lib/init-action.js | 87 ++++++++++++++++++------ lib/setup-codeql-action.js | 87 ++++++++++++++++++------ lib/start-proxy-action.js | 87 ++++++++++++++++++------ lib/upload-sarif-action.js | 87 ++++++++++++++++++------ src/feature-flags.ts | 136 +++++++++++++++++++++++++++---------- 8 files changed, 577 insertions(+), 168 deletions(-) diff --git a/lib/analyze-action.js b/lib/analyze-action.js index 3142e5d02..86411af34 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -107793,27 +107793,24 @@ var featureConfig = { } }; var FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json"; -var Features = class { - constructor(gitHubVersion, repositoryNwo, tempDir, logger) { +var OfflineFeatures = class { + constructor(logger) { this.logger = logger; - this.gitHubFeatureFlags = new GitHubFeatureFlags( - gitHubVersion, - repositoryNwo, - path5.join(tempDir, FEATURE_FLAGS_FILE_NAME), - logger - ); } - gitHubFeatureFlags; - async getDefaultCliVersion(variant) { - if (supportsFeatureFlags(variant)) { - return await this.gitHubFeatureFlags.getDefaultCliVersionFromFlags(); - } + async getDefaultCliVersion(_variant) { return { cliVersion, tagName: bundleVersion }; } /** + * Gets the `FeatureConfig` for `feature`. + */ + getFeatureConfig(feature) { + return featureConfig[feature]; + } + /** + * Determines whether `feature` is enabled without consulting the GitHub API. * * @param feature The feature to check. * @param codeql An optional CodeQL object. If provided, and a `minimumVersion` is specified for the @@ -107826,7 +107823,17 @@ var Features = class { * @throws if a `minimumVersion` is specified for the feature, and `codeql` is not provided. */ async getValue(feature, codeql) { - const config = featureConfig[feature]; + const offlineValue = await this.getOfflineValue(feature, codeql); + if (offlineValue !== void 0) { + return offlineValue; + } + return this.getDefaultValue(feature); + } + /** + * Determines whether `feature` is enabled using the CLI and environment variables. + */ + async getOfflineValue(feature, codeql) { + const config = this.getFeatureConfig(feature); if (!codeql && config.minimumVersion) { throw new Error( `Internal error: A minimum version is specified for feature ${feature}, but no instance of CodeQL was provided.` @@ -107876,6 +107883,52 @@ var Features = class { ); return true; } + return void 0; + } + /** Gets the default value of `feature`. */ + async getDefaultValue(feature) { + const config = this.getFeatureConfig(feature); + const defaultValue = config.defaultValue; + this.logger.debug( + `Feature ${feature} is ${defaultValue ? "enabled" : "disabled"} due to its default value.` + ); + return defaultValue; + } +}; +var Features = class extends OfflineFeatures { + gitHubFeatureFlags; + constructor(gitHubVersion, repositoryNwo, tempDir, logger) { + super(logger); + this.gitHubFeatureFlags = new GitHubFeatureFlags( + gitHubVersion, + repositoryNwo, + path5.join(tempDir, FEATURE_FLAGS_FILE_NAME), + logger + ); + } + async getDefaultCliVersion(variant) { + if (supportsFeatureFlags(variant)) { + return await this.gitHubFeatureFlags.getDefaultCliVersionFromFlags(); + } + return super.getDefaultCliVersion(variant); + } + /** + * + * @param feature The feature to check. + * @param codeql An optional CodeQL object. If provided, and a `minimumVersion` is specified for the + * feature, the version of the CodeQL CLI will be checked against the minimum version. + * If the version is less than the minimum version, the feature will be considered + * disabled. If not provided, and a `minimumVersion` is specified for the feature, the + * this function will throw. + * @returns true if the feature is enabled, false otherwise. + * + * @throws if a `minimumVersion` is specified for the feature, and `codeql` is not provided. + */ + async getValue(feature, codeql) { + const offlineValue = await this.getOfflineValue(feature, codeql); + if (offlineValue !== void 0) { + return offlineValue; + } const apiValue = await this.gitHubFeatureFlags.getValue(feature); if (apiValue !== void 0) { this.logger.debug( @@ -107883,11 +107936,7 @@ var Features = class { ); return apiValue; } - const defaultValue = config.defaultValue; - this.logger.debug( - `Feature ${feature} is ${defaultValue ? "enabled" : "disabled"} due to its default value.` - ); - return defaultValue; + return this.getDefaultValue(feature); } }; var GitHubFeatureFlags = class { diff --git a/lib/autobuild-action.js b/lib/autobuild-action.js index dfe8ff14d..5e8106587 100644 --- a/lib/autobuild-action.js +++ b/lib/autobuild-action.js @@ -104126,27 +104126,24 @@ var featureConfig = { } }; var FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json"; -var Features = class { - constructor(gitHubVersion, repositoryNwo, tempDir, logger) { +var OfflineFeatures = class { + constructor(logger) { this.logger = logger; - this.gitHubFeatureFlags = new GitHubFeatureFlags( - gitHubVersion, - repositoryNwo, - path3.join(tempDir, FEATURE_FLAGS_FILE_NAME), - logger - ); } - gitHubFeatureFlags; - async getDefaultCliVersion(variant) { - if (supportsFeatureFlags(variant)) { - return await this.gitHubFeatureFlags.getDefaultCliVersionFromFlags(); - } + async getDefaultCliVersion(_variant) { return { cliVersion, tagName: bundleVersion }; } /** + * Gets the `FeatureConfig` for `feature`. + */ + getFeatureConfig(feature) { + return featureConfig[feature]; + } + /** + * Determines whether `feature` is enabled without consulting the GitHub API. * * @param feature The feature to check. * @param codeql An optional CodeQL object. If provided, and a `minimumVersion` is specified for the @@ -104159,7 +104156,17 @@ var Features = class { * @throws if a `minimumVersion` is specified for the feature, and `codeql` is not provided. */ async getValue(feature, codeql) { - const config = featureConfig[feature]; + const offlineValue = await this.getOfflineValue(feature, codeql); + if (offlineValue !== void 0) { + return offlineValue; + } + return this.getDefaultValue(feature); + } + /** + * Determines whether `feature` is enabled using the CLI and environment variables. + */ + async getOfflineValue(feature, codeql) { + const config = this.getFeatureConfig(feature); if (!codeql && config.minimumVersion) { throw new Error( `Internal error: A minimum version is specified for feature ${feature}, but no instance of CodeQL was provided.` @@ -104209,6 +104216,52 @@ var Features = class { ); return true; } + return void 0; + } + /** Gets the default value of `feature`. */ + async getDefaultValue(feature) { + const config = this.getFeatureConfig(feature); + const defaultValue = config.defaultValue; + this.logger.debug( + `Feature ${feature} is ${defaultValue ? "enabled" : "disabled"} due to its default value.` + ); + return defaultValue; + } +}; +var Features = class extends OfflineFeatures { + gitHubFeatureFlags; + constructor(gitHubVersion, repositoryNwo, tempDir, logger) { + super(logger); + this.gitHubFeatureFlags = new GitHubFeatureFlags( + gitHubVersion, + repositoryNwo, + path3.join(tempDir, FEATURE_FLAGS_FILE_NAME), + logger + ); + } + async getDefaultCliVersion(variant) { + if (supportsFeatureFlags(variant)) { + return await this.gitHubFeatureFlags.getDefaultCliVersionFromFlags(); + } + return super.getDefaultCliVersion(variant); + } + /** + * + * @param feature The feature to check. + * @param codeql An optional CodeQL object. If provided, and a `minimumVersion` is specified for the + * feature, the version of the CodeQL CLI will be checked against the minimum version. + * If the version is less than the minimum version, the feature will be considered + * disabled. If not provided, and a `minimumVersion` is specified for the feature, the + * this function will throw. + * @returns true if the feature is enabled, false otherwise. + * + * @throws if a `minimumVersion` is specified for the feature, and `codeql` is not provided. + */ + async getValue(feature, codeql) { + const offlineValue = await this.getOfflineValue(feature, codeql); + if (offlineValue !== void 0) { + return offlineValue; + } const apiValue = await this.gitHubFeatureFlags.getValue(feature); if (apiValue !== void 0) { this.logger.debug( @@ -104216,11 +104269,7 @@ var Features = class { ); return apiValue; } - const defaultValue = config.defaultValue; - this.logger.debug( - `Feature ${feature} is ${defaultValue ? "enabled" : "disabled"} due to its default value.` - ); - return defaultValue; + return this.getDefaultValue(feature); } }; var GitHubFeatureFlags = class { diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 9549831ea..b6dbdd5b4 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -165119,27 +165119,24 @@ var featureConfig = { } }; var FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json"; -var Features = class { - constructor(gitHubVersion, repositoryNwo, tempDir, logger) { +var OfflineFeatures = class { + constructor(logger) { this.logger = logger; - this.gitHubFeatureFlags = new GitHubFeatureFlags( - gitHubVersion, - repositoryNwo, - path4.join(tempDir, FEATURE_FLAGS_FILE_NAME), - logger - ); } - gitHubFeatureFlags; - async getDefaultCliVersion(variant) { - if (supportsFeatureFlags(variant)) { - return await this.gitHubFeatureFlags.getDefaultCliVersionFromFlags(); - } + async getDefaultCliVersion(_variant) { return { cliVersion, tagName: bundleVersion }; } /** + * Gets the `FeatureConfig` for `feature`. + */ + getFeatureConfig(feature) { + return featureConfig[feature]; + } + /** + * Determines whether `feature` is enabled without consulting the GitHub API. * * @param feature The feature to check. * @param codeql An optional CodeQL object. If provided, and a `minimumVersion` is specified for the @@ -165152,7 +165149,17 @@ var Features = class { * @throws if a `minimumVersion` is specified for the feature, and `codeql` is not provided. */ async getValue(feature, codeql) { - const config = featureConfig[feature]; + const offlineValue = await this.getOfflineValue(feature, codeql); + if (offlineValue !== void 0) { + return offlineValue; + } + return this.getDefaultValue(feature); + } + /** + * Determines whether `feature` is enabled using the CLI and environment variables. + */ + async getOfflineValue(feature, codeql) { + const config = this.getFeatureConfig(feature); if (!codeql && config.minimumVersion) { throw new Error( `Internal error: A minimum version is specified for feature ${feature}, but no instance of CodeQL was provided.` @@ -165202,6 +165209,52 @@ var Features = class { ); return true; } + return void 0; + } + /** Gets the default value of `feature`. */ + async getDefaultValue(feature) { + const config = this.getFeatureConfig(feature); + const defaultValue = config.defaultValue; + this.logger.debug( + `Feature ${feature} is ${defaultValue ? "enabled" : "disabled"} due to its default value.` + ); + return defaultValue; + } +}; +var Features = class extends OfflineFeatures { + gitHubFeatureFlags; + constructor(gitHubVersion, repositoryNwo, tempDir, logger) { + super(logger); + this.gitHubFeatureFlags = new GitHubFeatureFlags( + gitHubVersion, + repositoryNwo, + path4.join(tempDir, FEATURE_FLAGS_FILE_NAME), + logger + ); + } + async getDefaultCliVersion(variant) { + if (supportsFeatureFlags(variant)) { + return await this.gitHubFeatureFlags.getDefaultCliVersionFromFlags(); + } + return super.getDefaultCliVersion(variant); + } + /** + * + * @param feature The feature to check. + * @param codeql An optional CodeQL object. If provided, and a `minimumVersion` is specified for the + * feature, the version of the CodeQL CLI will be checked against the minimum version. + * If the version is less than the minimum version, the feature will be considered + * disabled. If not provided, and a `minimumVersion` is specified for the feature, the + * this function will throw. + * @returns true if the feature is enabled, false otherwise. + * + * @throws if a `minimumVersion` is specified for the feature, and `codeql` is not provided. + */ + async getValue(feature, codeql) { + const offlineValue = await this.getOfflineValue(feature, codeql); + if (offlineValue !== void 0) { + return offlineValue; + } const apiValue = await this.gitHubFeatureFlags.getValue(feature); if (apiValue !== void 0) { this.logger.debug( @@ -165209,11 +165262,7 @@ var Features = class { ); return apiValue; } - const defaultValue = config.defaultValue; - this.logger.debug( - `Feature ${feature} is ${defaultValue ? "enabled" : "disabled"} due to its default value.` - ); - return defaultValue; + return this.getDefaultValue(feature); } }; var GitHubFeatureFlags = class { diff --git a/lib/init-action.js b/lib/init-action.js index d14f7f8e0..4bd5877f5 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -105326,27 +105326,24 @@ var featureConfig = { } }; var FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json"; -var Features = class { - constructor(gitHubVersion, repositoryNwo, tempDir, logger) { +var OfflineFeatures = class { + constructor(logger) { this.logger = logger; - this.gitHubFeatureFlags = new GitHubFeatureFlags( - gitHubVersion, - repositoryNwo, - path6.join(tempDir, FEATURE_FLAGS_FILE_NAME), - logger - ); } - gitHubFeatureFlags; - async getDefaultCliVersion(variant) { - if (supportsFeatureFlags(variant)) { - return await this.gitHubFeatureFlags.getDefaultCliVersionFromFlags(); - } + async getDefaultCliVersion(_variant) { return { cliVersion, tagName: bundleVersion }; } /** + * Gets the `FeatureConfig` for `feature`. + */ + getFeatureConfig(feature) { + return featureConfig[feature]; + } + /** + * Determines whether `feature` is enabled without consulting the GitHub API. * * @param feature The feature to check. * @param codeql An optional CodeQL object. If provided, and a `minimumVersion` is specified for the @@ -105359,7 +105356,17 @@ var Features = class { * @throws if a `minimumVersion` is specified for the feature, and `codeql` is not provided. */ async getValue(feature, codeql) { - const config = featureConfig[feature]; + const offlineValue = await this.getOfflineValue(feature, codeql); + if (offlineValue !== void 0) { + return offlineValue; + } + return this.getDefaultValue(feature); + } + /** + * Determines whether `feature` is enabled using the CLI and environment variables. + */ + async getOfflineValue(feature, codeql) { + const config = this.getFeatureConfig(feature); if (!codeql && config.minimumVersion) { throw new Error( `Internal error: A minimum version is specified for feature ${feature}, but no instance of CodeQL was provided.` @@ -105409,6 +105416,52 @@ var Features = class { ); return true; } + return void 0; + } + /** Gets the default value of `feature`. */ + async getDefaultValue(feature) { + const config = this.getFeatureConfig(feature); + const defaultValue = config.defaultValue; + this.logger.debug( + `Feature ${feature} is ${defaultValue ? "enabled" : "disabled"} due to its default value.` + ); + return defaultValue; + } +}; +var Features = class extends OfflineFeatures { + gitHubFeatureFlags; + constructor(gitHubVersion, repositoryNwo, tempDir, logger) { + super(logger); + this.gitHubFeatureFlags = new GitHubFeatureFlags( + gitHubVersion, + repositoryNwo, + path6.join(tempDir, FEATURE_FLAGS_FILE_NAME), + logger + ); + } + async getDefaultCliVersion(variant) { + if (supportsFeatureFlags(variant)) { + return await this.gitHubFeatureFlags.getDefaultCliVersionFromFlags(); + } + return super.getDefaultCliVersion(variant); + } + /** + * + * @param feature The feature to check. + * @param codeql An optional CodeQL object. If provided, and a `minimumVersion` is specified for the + * feature, the version of the CodeQL CLI will be checked against the minimum version. + * If the version is less than the minimum version, the feature will be considered + * disabled. If not provided, and a `minimumVersion` is specified for the feature, the + * this function will throw. + * @returns true if the feature is enabled, false otherwise. + * + * @throws if a `minimumVersion` is specified for the feature, and `codeql` is not provided. + */ + async getValue(feature, codeql) { + const offlineValue = await this.getOfflineValue(feature, codeql); + if (offlineValue !== void 0) { + return offlineValue; + } const apiValue = await this.gitHubFeatureFlags.getValue(feature); if (apiValue !== void 0) { this.logger.debug( @@ -105416,11 +105469,7 @@ var Features = class { ); return apiValue; } - const defaultValue = config.defaultValue; - this.logger.debug( - `Feature ${feature} is ${defaultValue ? "enabled" : "disabled"} due to its default value.` - ); - return defaultValue; + return this.getDefaultValue(feature); } }; var GitHubFeatureFlags = class { diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index 0e0f72b76..9622da8e5 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -104027,27 +104027,24 @@ var featureConfig = { } }; var FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json"; -var Features = class { - constructor(gitHubVersion, repositoryNwo, tempDir, logger) { +var OfflineFeatures = class { + constructor(logger) { this.logger = logger; - this.gitHubFeatureFlags = new GitHubFeatureFlags( - gitHubVersion, - repositoryNwo, - path4.join(tempDir, FEATURE_FLAGS_FILE_NAME), - logger - ); } - gitHubFeatureFlags; - async getDefaultCliVersion(variant) { - if (supportsFeatureFlags(variant)) { - return await this.gitHubFeatureFlags.getDefaultCliVersionFromFlags(); - } + async getDefaultCliVersion(_variant) { return { cliVersion, tagName: bundleVersion }; } /** + * Gets the `FeatureConfig` for `feature`. + */ + getFeatureConfig(feature) { + return featureConfig[feature]; + } + /** + * Determines whether `feature` is enabled without consulting the GitHub API. * * @param feature The feature to check. * @param codeql An optional CodeQL object. If provided, and a `minimumVersion` is specified for the @@ -104060,7 +104057,17 @@ var Features = class { * @throws if a `minimumVersion` is specified for the feature, and `codeql` is not provided. */ async getValue(feature, codeql) { - const config = featureConfig[feature]; + const offlineValue = await this.getOfflineValue(feature, codeql); + if (offlineValue !== void 0) { + return offlineValue; + } + return this.getDefaultValue(feature); + } + /** + * Determines whether `feature` is enabled using the CLI and environment variables. + */ + async getOfflineValue(feature, codeql) { + const config = this.getFeatureConfig(feature); if (!codeql && config.minimumVersion) { throw new Error( `Internal error: A minimum version is specified for feature ${feature}, but no instance of CodeQL was provided.` @@ -104110,6 +104117,52 @@ var Features = class { ); return true; } + return void 0; + } + /** Gets the default value of `feature`. */ + async getDefaultValue(feature) { + const config = this.getFeatureConfig(feature); + const defaultValue = config.defaultValue; + this.logger.debug( + `Feature ${feature} is ${defaultValue ? "enabled" : "disabled"} due to its default value.` + ); + return defaultValue; + } +}; +var Features = class extends OfflineFeatures { + gitHubFeatureFlags; + constructor(gitHubVersion, repositoryNwo, tempDir, logger) { + super(logger); + this.gitHubFeatureFlags = new GitHubFeatureFlags( + gitHubVersion, + repositoryNwo, + path4.join(tempDir, FEATURE_FLAGS_FILE_NAME), + logger + ); + } + async getDefaultCliVersion(variant) { + if (supportsFeatureFlags(variant)) { + return await this.gitHubFeatureFlags.getDefaultCliVersionFromFlags(); + } + return super.getDefaultCliVersion(variant); + } + /** + * + * @param feature The feature to check. + * @param codeql An optional CodeQL object. If provided, and a `minimumVersion` is specified for the + * feature, the version of the CodeQL CLI will be checked against the minimum version. + * If the version is less than the minimum version, the feature will be considered + * disabled. If not provided, and a `minimumVersion` is specified for the feature, the + * this function will throw. + * @returns true if the feature is enabled, false otherwise. + * + * @throws if a `minimumVersion` is specified for the feature, and `codeql` is not provided. + */ + async getValue(feature, codeql) { + const offlineValue = await this.getOfflineValue(feature, codeql); + if (offlineValue !== void 0) { + return offlineValue; + } const apiValue = await this.gitHubFeatureFlags.getValue(feature); if (apiValue !== void 0) { this.logger.debug( @@ -104117,11 +104170,7 @@ var Features = class { ); return apiValue; } - const defaultValue = config.defaultValue; - this.logger.debug( - `Feature ${feature} is ${defaultValue ? "enabled" : "disabled"} due to its default value.` - ); - return defaultValue; + return this.getDefaultValue(feature); } }; var GitHubFeatureFlags = class { diff --git a/lib/start-proxy-action.js b/lib/start-proxy-action.js index 6b7464505..b1fe7846a 100644 --- a/lib/start-proxy-action.js +++ b/lib/start-proxy-action.js @@ -120820,27 +120820,24 @@ var featureConfig = { } }; var FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json"; -var Features = class { - constructor(gitHubVersion, repositoryNwo, tempDir, logger) { +var OfflineFeatures = class { + constructor(logger) { this.logger = logger; - this.gitHubFeatureFlags = new GitHubFeatureFlags( - gitHubVersion, - repositoryNwo, - path.join(tempDir, FEATURE_FLAGS_FILE_NAME), - logger - ); } - gitHubFeatureFlags; - async getDefaultCliVersion(variant) { - if (supportsFeatureFlags(variant)) { - return await this.gitHubFeatureFlags.getDefaultCliVersionFromFlags(); - } + async getDefaultCliVersion(_variant) { return { cliVersion, tagName: bundleVersion }; } /** + * Gets the `FeatureConfig` for `feature`. + */ + getFeatureConfig(feature) { + return featureConfig[feature]; + } + /** + * Determines whether `feature` is enabled without consulting the GitHub API. * * @param feature The feature to check. * @param codeql An optional CodeQL object. If provided, and a `minimumVersion` is specified for the @@ -120853,7 +120850,17 @@ var Features = class { * @throws if a `minimumVersion` is specified for the feature, and `codeql` is not provided. */ async getValue(feature, codeql) { - const config = featureConfig[feature]; + const offlineValue = await this.getOfflineValue(feature, codeql); + if (offlineValue !== void 0) { + return offlineValue; + } + return this.getDefaultValue(feature); + } + /** + * Determines whether `feature` is enabled using the CLI and environment variables. + */ + async getOfflineValue(feature, codeql) { + const config = this.getFeatureConfig(feature); if (!codeql && config.minimumVersion) { throw new Error( `Internal error: A minimum version is specified for feature ${feature}, but no instance of CodeQL was provided.` @@ -120903,6 +120910,52 @@ var Features = class { ); return true; } + return void 0; + } + /** Gets the default value of `feature`. */ + async getDefaultValue(feature) { + const config = this.getFeatureConfig(feature); + const defaultValue = config.defaultValue; + this.logger.debug( + `Feature ${feature} is ${defaultValue ? "enabled" : "disabled"} due to its default value.` + ); + return defaultValue; + } +}; +var Features = class extends OfflineFeatures { + gitHubFeatureFlags; + constructor(gitHubVersion, repositoryNwo, tempDir, logger) { + super(logger); + this.gitHubFeatureFlags = new GitHubFeatureFlags( + gitHubVersion, + repositoryNwo, + path.join(tempDir, FEATURE_FLAGS_FILE_NAME), + logger + ); + } + async getDefaultCliVersion(variant) { + if (supportsFeatureFlags(variant)) { + return await this.gitHubFeatureFlags.getDefaultCliVersionFromFlags(); + } + return super.getDefaultCliVersion(variant); + } + /** + * + * @param feature The feature to check. + * @param codeql An optional CodeQL object. If provided, and a `minimumVersion` is specified for the + * feature, the version of the CodeQL CLI will be checked against the minimum version. + * If the version is less than the minimum version, the feature will be considered + * disabled. If not provided, and a `minimumVersion` is specified for the feature, the + * this function will throw. + * @returns true if the feature is enabled, false otherwise. + * + * @throws if a `minimumVersion` is specified for the feature, and `codeql` is not provided. + */ + async getValue(feature, codeql) { + const offlineValue = await this.getOfflineValue(feature, codeql); + if (offlineValue !== void 0) { + return offlineValue; + } const apiValue = await this.gitHubFeatureFlags.getValue(feature); if (apiValue !== void 0) { this.logger.debug( @@ -120910,11 +120963,7 @@ var Features = class { ); return apiValue; } - const defaultValue = config.defaultValue; - this.logger.debug( - `Feature ${feature} is ${defaultValue ? "enabled" : "disabled"} due to its default value.` - ); - return defaultValue; + return this.getDefaultValue(feature); } }; var GitHubFeatureFlags = class { diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index 14e89b9fc..843e78574 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -106981,27 +106981,24 @@ var featureConfig = { } }; var FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json"; -var Features = class { - constructor(gitHubVersion, repositoryNwo, tempDir, logger) { +var OfflineFeatures = class { + constructor(logger) { this.logger = logger; - this.gitHubFeatureFlags = new GitHubFeatureFlags( - gitHubVersion, - repositoryNwo, - path4.join(tempDir, FEATURE_FLAGS_FILE_NAME), - logger - ); } - gitHubFeatureFlags; - async getDefaultCliVersion(variant) { - if (supportsFeatureFlags(variant)) { - return await this.gitHubFeatureFlags.getDefaultCliVersionFromFlags(); - } + async getDefaultCliVersion(_variant) { return { cliVersion, tagName: bundleVersion }; } /** + * Gets the `FeatureConfig` for `feature`. + */ + getFeatureConfig(feature) { + return featureConfig[feature]; + } + /** + * Determines whether `feature` is enabled without consulting the GitHub API. * * @param feature The feature to check. * @param codeql An optional CodeQL object. If provided, and a `minimumVersion` is specified for the @@ -107014,7 +107011,17 @@ var Features = class { * @throws if a `minimumVersion` is specified for the feature, and `codeql` is not provided. */ async getValue(feature, codeql) { - const config = featureConfig[feature]; + const offlineValue = await this.getOfflineValue(feature, codeql); + if (offlineValue !== void 0) { + return offlineValue; + } + return this.getDefaultValue(feature); + } + /** + * Determines whether `feature` is enabled using the CLI and environment variables. + */ + async getOfflineValue(feature, codeql) { + const config = this.getFeatureConfig(feature); if (!codeql && config.minimumVersion) { throw new Error( `Internal error: A minimum version is specified for feature ${feature}, but no instance of CodeQL was provided.` @@ -107064,6 +107071,52 @@ var Features = class { ); return true; } + return void 0; + } + /** Gets the default value of `feature`. */ + async getDefaultValue(feature) { + const config = this.getFeatureConfig(feature); + const defaultValue = config.defaultValue; + this.logger.debug( + `Feature ${feature} is ${defaultValue ? "enabled" : "disabled"} due to its default value.` + ); + return defaultValue; + } +}; +var Features = class extends OfflineFeatures { + gitHubFeatureFlags; + constructor(gitHubVersion, repositoryNwo, tempDir, logger) { + super(logger); + this.gitHubFeatureFlags = new GitHubFeatureFlags( + gitHubVersion, + repositoryNwo, + path4.join(tempDir, FEATURE_FLAGS_FILE_NAME), + logger + ); + } + async getDefaultCliVersion(variant) { + if (supportsFeatureFlags(variant)) { + return await this.gitHubFeatureFlags.getDefaultCliVersionFromFlags(); + } + return super.getDefaultCliVersion(variant); + } + /** + * + * @param feature The feature to check. + * @param codeql An optional CodeQL object. If provided, and a `minimumVersion` is specified for the + * feature, the version of the CodeQL CLI will be checked against the minimum version. + * If the version is less than the minimum version, the feature will be considered + * disabled. If not provided, and a `minimumVersion` is specified for the feature, the + * this function will throw. + * @returns true if the feature is enabled, false otherwise. + * + * @throws if a `minimumVersion` is specified for the feature, and `codeql` is not provided. + */ + async getValue(feature, codeql) { + const offlineValue = await this.getOfflineValue(feature, codeql); + if (offlineValue !== void 0) { + return offlineValue; + } const apiValue = await this.gitHubFeatureFlags.getValue(feature); if (apiValue !== void 0) { this.logger.debug( @@ -107071,11 +107124,7 @@ var Features = class { ); return apiValue; } - const defaultValue = config.defaultValue; - this.logger.debug( - `Feature ${feature} is ${defaultValue ? "enabled" : "disabled"} due to its default value.` - ); - return defaultValue; + return this.getDefaultValue(feature); } }; var GitHubFeatureFlags = class { diff --git a/src/feature-flags.ts b/src/feature-flags.ts index ab5798ed3..0400eb40e 100644 --- a/src/feature-flags.ts +++ b/src/feature-flags.ts @@ -354,33 +354,15 @@ type GitHubFeatureFlagsApiResponse = Partial>; export const FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json"; /** - * Determines the enablement status of a number of features. - * If feature enablement is not able to be determined locally, a request to the - * GitHub API is made to determine the enablement status. + * Determines the enablement status of a number of features locally without + * consulting the GitHub API. */ -export class Features implements FeatureEnablement { - private gitHubFeatureFlags: GitHubFeatureFlags; - - constructor( - gitHubVersion: util.GitHubVersion, - repositoryNwo: RepositoryNwo, - tempDir: string, - private readonly logger: Logger, - ) { - this.gitHubFeatureFlags = new GitHubFeatureFlags( - gitHubVersion, - repositoryNwo, - path.join(tempDir, FEATURE_FLAGS_FILE_NAME), - logger, - ); - } +export class OfflineFeatures implements FeatureEnablement { + constructor(protected readonly logger: Logger) {} async getDefaultCliVersion( - variant: util.GitHubVariant, + _variant: util.GitHubVariant, ): Promise { - if (supportsFeatureFlags(variant)) { - return await this.gitHubFeatureFlags.getDefaultCliVersionFromFlags(); - } return { cliVersion: defaults.cliVersion, tagName: defaults.bundleVersion, @@ -388,6 +370,16 @@ export class Features implements FeatureEnablement { } /** + * Gets the `FeatureConfig` for `feature`. + */ + getFeatureConfig(feature: Feature): FeatureConfig { + // Narrow the type to FeatureConfig to avoid type errors. To avoid unsafe use of `as`, we + // check that the required properties exist using `satisfies`. + return featureConfig[feature] satisfies FeatureConfig as FeatureConfig; + } + + /** + * Determines whether `feature` is enabled without consulting the GitHub API. * * @param feature The feature to check. * @param codeql An optional CodeQL object. If provided, and a `minimumVersion` is specified for the @@ -400,11 +392,22 @@ export class Features implements FeatureEnablement { * @throws if a `minimumVersion` is specified for the feature, and `codeql` is not provided. */ async getValue(feature: Feature, codeql?: CodeQL): Promise { - // Narrow the type to FeatureConfig to avoid type errors. To avoid unsafe use of `as`, we - // check that the required properties exist using `satisfies`. - const config = featureConfig[ - feature - ] satisfies FeatureConfig as FeatureConfig; + const offlineValue = await this.getOfflineValue(feature, codeql); + if (offlineValue !== undefined) { + return offlineValue; + } + + return this.getDefaultValue(feature); + } + + /** + * Determines whether `feature` is enabled using the CLI and environment variables. + */ + protected async getOfflineValue( + feature: Feature, + codeql?: CodeQL, + ): Promise { + const config = this.getFeatureConfig(feature); if (!codeql && config.minimumVersion) { throw new Error( @@ -470,6 +473,74 @@ export class Features implements FeatureEnablement { return true; } + return undefined; + } + + /** Gets the default value of `feature`. */ + protected async getDefaultValue(feature: Feature): Promise { + const config = this.getFeatureConfig(feature); + const defaultValue = config.defaultValue; + this.logger.debug( + `Feature ${feature} is ${ + defaultValue ? "enabled" : "disabled" + } due to its default value.`, + ); + return defaultValue; + } +} + +/** + * Determines the enablement status of a number of features. + * If feature enablement is not able to be determined locally, a request to the + * GitHub API is made to determine the enablement status. + */ +export class Features extends OfflineFeatures { + private gitHubFeatureFlags: GitHubFeatureFlags; + + constructor( + gitHubVersion: util.GitHubVersion, + repositoryNwo: RepositoryNwo, + tempDir: string, + logger: Logger, + ) { + super(logger); + + this.gitHubFeatureFlags = new GitHubFeatureFlags( + gitHubVersion, + repositoryNwo, + path.join(tempDir, FEATURE_FLAGS_FILE_NAME), + logger, + ); + } + + async getDefaultCliVersion( + variant: util.GitHubVariant, + ): Promise { + if (supportsFeatureFlags(variant)) { + return await this.gitHubFeatureFlags.getDefaultCliVersionFromFlags(); + } + return super.getDefaultCliVersion(variant); + } + + /** + * + * @param feature The feature to check. + * @param codeql An optional CodeQL object. If provided, and a `minimumVersion` is specified for the + * feature, the version of the CodeQL CLI will be checked against the minimum version. + * If the version is less than the minimum version, the feature will be considered + * disabled. If not provided, and a `minimumVersion` is specified for the feature, the + * this function will throw. + * @returns true if the feature is enabled, false otherwise. + * + * @throws if a `minimumVersion` is specified for the feature, and `codeql` is not provided. + */ + async getValue(feature: Feature, codeql?: CodeQL): Promise { + // Check whether the feature is enabled locally. + const offlineValue = await this.getOfflineValue(feature, codeql); + if (offlineValue !== undefined) { + return offlineValue; + } + // Ask the GitHub API if the feature is enabled. const apiValue = await this.gitHubFeatureFlags.getValue(feature); if (apiValue !== undefined) { @@ -481,13 +552,8 @@ export class Features implements FeatureEnablement { return apiValue; } - const defaultValue = config.defaultValue; - this.logger.debug( - `Feature ${feature} is ${ - defaultValue ? "enabled" : "disabled" - } due to its default value.`, - ); - return defaultValue; + // Return the default value. + return this.getDefaultValue(feature); } }