2021-12-14 19:50:52 +00:00
"use strict" ;
var _ _createBinding = ( this && this . _ _createBinding ) || ( Object . create ? ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
2023-01-18 20:00:33 +00:00
var desc = Object . getOwnPropertyDescriptor ( m , k ) ;
if ( ! desc || ( "get" in desc ? ! m . _ _esModule : desc . writable || desc . configurable ) ) {
desc = { enumerable : true , get : function ( ) { return m [ k ] ; } } ;
}
Object . defineProperty ( o , k2 , desc ) ;
2021-12-14 19:50:52 +00:00
} ) : ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
o [ k2 ] = m [ k ] ;
} ) ) ;
var _ _setModuleDefault = ( this && this . _ _setModuleDefault ) || ( Object . create ? ( function ( o , v ) {
Object . defineProperty ( o , "default" , { enumerable : true , value : v } ) ;
} ) : function ( o , v ) {
o [ "default" ] = v ;
} ) ;
2024-12-03 18:39:38 +00:00
var _ _importStar = ( this && this . _ _importStar ) || ( function ( ) {
var ownKeys = function ( o ) {
ownKeys = Object . getOwnPropertyNames || function ( o ) {
var ar = [ ] ;
for ( var k in o ) if ( Object . prototype . hasOwnProperty . call ( o , k ) ) ar [ ar . length ] = k ;
return ar ;
} ;
return ownKeys ( o ) ;
} ;
return function ( mod ) {
if ( mod && mod . _ _esModule ) return mod ;
var result = { } ;
if ( mod != null ) for ( var k = ownKeys ( mod ) , i = 0 ; i < k . length ; i ++ ) if ( k [ i ] !== "default" ) _ _createBinding ( result , mod , k [ i ] ) ;
_ _setModuleDefault ( result , mod ) ;
return result ;
} ;
} ) ( ) ;
2021-12-14 19:50:52 +00:00
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
2025-01-15 17:59:15 +00:00
exports . Features = exports . FEATURE _FLAGS _FILE _NAME = exports . featureConfig = exports . Feature = exports . CODEQL _VERSION _ZSTD _BUNDLE = void 0 ;
2022-11-21 11:14:38 -08:00
const fs = _ _importStar ( require ( "fs" ) ) ;
const path = _ _importStar ( require ( "path" ) ) ;
2023-01-05 13:17:37 +00:00
const semver = _ _importStar ( require ( "semver" ) ) ;
2021-12-14 19:50:52 +00:00
const api _client _1 = require ( "./api-client" ) ;
2023-01-12 15:46:12 +00:00
const defaults = _ _importStar ( require ( "./defaults.json" ) ) ;
2024-10-09 22:24:40 +02:00
const tools _features _1 = require ( "./tools-features" ) ;
2021-12-14 19:50:52 +00:00
const util = _ _importStar ( require ( "./util" ) ) ;
2023-01-05 13:11:53 +00:00
const DEFAULT _VERSION _FEATURE _FLAG _PREFIX = "default_codeql_version_" ;
const DEFAULT _VERSION _FEATURE _FLAG _SUFFIX = "_enabled" ;
2024-09-24 17:39:33 +01:00
/**
* The first version of the CodeQL Bundle that shipped with zstd-compressed bundles.
*/
exports . CODEQL _VERSION _ZSTD _BUNDLE = "2.19.0" ;
2023-07-18 13:12:12 +01:00
/**
2023-07-18 13:28:06 +01:00
* Feature enablement as returned by the GitHub API endpoint.
2023-07-18 13:12:12 +01:00
*
2024-10-17 11:25:52 +01:00
* Do not include the `codeql_action_` prefix as this is stripped by the API
* endpoint.
*
2024-05-09 12:08:14 +01:00
* Legacy features should end with `_enabled`.
2023-07-18 13:12:12 +01:00
*/
2022-10-06 12:31:08 -07:00
var Feature ;
( function ( Feature ) {
2024-05-22 19:14:50 +01:00
Feature [ "CleanupTrapCaches" ] = "cleanup_trap_caches" ;
2024-10-24 16:46:58 +01:00
Feature [ "CppBuildModeNone" ] = "cpp_build_mode_none" ;
2023-09-18 10:19:12 +02:00
Feature [ "CppDependencyInstallation" ] = "cpp_dependency_installation_enabled" ;
2024-10-17 13:47:23 -07:00
Feature [ "DiffInformedQueries" ] = "diff_informed_queries" ;
2024-06-11 18:45:16 +01:00
Feature [ "DisableCsharpBuildless" ] = "disable_csharp_buildless" ;
2024-02-12 22:02:22 +00:00
Feature [ "DisableJavaBuildlessEnabled" ] = "disable_java_buildless_enabled" ;
2022-11-17 10:38:48 -08:00
Feature [ "DisableKotlinAnalysisEnabled" ] = "disable_kotlin_analysis_enabled" ;
2023-03-20 14:09:04 -07:00
Feature [ "ExportDiagnosticsEnabled" ] = "export_diagnostics_enabled" ;
2024-11-06 19:49:24 +00:00
Feature [ "ExtractToToolcache" ] = "extract_to_toolcache" ;
2024-10-17 11:25:52 +01:00
Feature [ "PythonDefaultIsToNotExtractStdlib" ] = "python_default_is_to_not_extract_stdlib" ;
2023-06-30 07:53:13 -07:00
Feature [ "QaTelemetryEnabled" ] = "qa_telemetry_enabled" ;
2025-02-19 15:56:52 +01:00
Feature [ "RustAnalysis" ] = "rust_analysis" ;
2024-11-12 17:59:47 +00:00
Feature [ "ZstdBundleStreamingExtraction" ] = "zstd_bundle_streaming_extraction" ;
2023-07-13 11:17:33 +01:00
} ) ( Feature || ( exports . Feature = Feature = { } ) ) ;
2022-10-06 12:31:08 -07:00
exports . featureConfig = {
2024-05-22 19:14:50 +01:00
[ Feature . CleanupTrapCaches ] : {
defaultValue : false ,
envVar : "CODEQL_ACTION_CLEANUP_TRAP_CACHES" ,
minimumVersion : undefined ,
} ,
2024-10-24 16:46:58 +01:00
[ Feature . CppBuildModeNone ] : {
2024-10-23 12:34:26 +01:00
defaultValue : false ,
2024-10-24 16:46:58 +01:00
envVar : "CODEQL_EXTRACTOR_CPP_BUILD_MODE_NONE" ,
2024-10-23 12:34:26 +01:00
minimumVersion : undefined ,
} ,
2024-11-12 17:59:47 +00:00
[ Feature . ZstdBundleStreamingExtraction ] : {
defaultValue : false ,
envVar : "CODEQL_ACTION_ZSTD_BUNDLE_STREAMING_EXTRACTION" ,
minimumVersion : undefined ,
} ,
2023-09-18 10:19:12 +02:00
[ Feature . CppDependencyInstallation ] : {
2024-05-09 11:42:38 +01:00
defaultValue : false ,
2023-09-20 09:50:30 +02:00
envVar : "CODEQL_EXTRACTOR_CPP_AUTOINSTALL_DEPENDENCIES" ,
2024-05-09 11:42:38 +01:00
legacyApi : true ,
2023-09-18 10:19:12 +02:00
minimumVersion : "2.15.0" ,
} ,
2024-10-17 13:47:23 -07:00
[ Feature . DiffInformedQueries ] : {
defaultValue : false ,
envVar : "CODEQL_ACTION_DIFF_INFORMED_QUERIES" ,
2025-04-04 08:41:50 -07:00
minimumVersion : "2.21.0" ,
2024-10-17 13:47:23 -07:00
} ,
2024-06-11 18:45:16 +01:00
[ Feature . DisableCsharpBuildless ] : {
defaultValue : false ,
envVar : "CODEQL_ACTION_DISABLE_CSHARP_BUILDLESS" ,
minimumVersion : undefined ,
} ,
2024-02-12 22:02:22 +00:00
[ Feature . DisableJavaBuildlessEnabled ] : {
2024-05-09 11:42:38 +01:00
defaultValue : false ,
2024-02-12 22:02:22 +00:00
envVar : "CODEQL_ACTION_DISABLE_JAVA_BUILDLESS" ,
2024-05-09 11:42:38 +01:00
legacyApi : true ,
2024-02-12 22:02:22 +00:00
minimumVersion : undefined ,
} ,
2022-11-17 10:38:48 -08:00
[ Feature . DisableKotlinAnalysisEnabled ] : {
2024-05-09 11:42:38 +01:00
defaultValue : false ,
2022-11-17 10:38:48 -08:00
envVar : "CODEQL_DISABLE_KOTLIN_ANALYSIS" ,
2024-05-09 11:42:38 +01:00
legacyApi : true ,
2022-11-17 10:38:48 -08:00
minimumVersion : undefined ,
} ,
2023-03-20 14:09:04 -07:00
[ Feature . ExportDiagnosticsEnabled ] : {
2024-05-09 11:42:38 +01:00
defaultValue : true ,
2023-03-20 14:09:04 -07:00
envVar : "CODEQL_ACTION_EXPORT_DIAGNOSTICS" ,
2024-05-09 11:42:38 +01:00
legacyApi : true ,
2024-04-09 12:29:14 +01:00
minimumVersion : undefined ,
2023-03-20 14:09:04 -07:00
} ,
2024-11-06 19:49:24 +00:00
[ Feature . ExtractToToolcache ] : {
defaultValue : false ,
envVar : "CODEQL_ACTION_EXTRACT_TOOLCACHE" ,
minimumVersion : undefined ,
} ,
2024-10-17 11:25:52 +01:00
[ Feature . PythonDefaultIsToNotExtractStdlib ] : {
defaultValue : false ,
envVar : "CODEQL_ACTION_DISABLE_PYTHON_STANDARD_LIBRARY_EXTRACTION" ,
minimumVersion : undefined ,
toolsFeature : tools _features _1 . ToolsFeature . PythonDefaultIsToNotExtractStdlib ,
} ,
2025-02-19 15:56:52 +01:00
[ Feature . RustAnalysis ] : {
defaultValue : false ,
envVar : "CODEQL_ACTION_RUST_ANALYSIS" ,
minimumVersion : "2.19.3" ,
} ,
2023-06-30 07:53:13 -07:00
[ Feature . QaTelemetryEnabled ] : {
2024-05-09 11:42:38 +01:00
defaultValue : false ,
2023-06-30 07:53:13 -07:00
envVar : "CODEQL_ACTION_QA_TELEMETRY" ,
2024-05-09 11:42:38 +01:00
legacyApi : true ,
2023-06-30 07:53:13 -07:00
minimumVersion : undefined ,
} ,
2022-10-05 15:54:07 -07:00
} ;
2022-11-21 13:42:32 -08:00
exports . FEATURE _FLAGS _FILE _NAME = "cached-feature-flags.json" ;
2022-10-06 14:42:57 -07:00
/**
* Determines the enablement status of a number of features.
* If feature enablement is not able to be determined locally, a request to the
2022-10-11 18:56:15 +01:00
* GitHub API is made to determine the enablement status.
2022-10-06 14:42:57 -07:00
*/
class Features {
2022-11-21 11:14:38 -08:00
constructor ( gitHubVersion , repositoryNwo , tempDir , logger ) {
2023-03-14 20:20:35 +00:00
this . logger = logger ;
2022-11-21 11:14:38 -08:00
this . gitHubFeatureFlags = new GitHubFeatureFlags ( gitHubVersion , repositoryNwo , path . join ( tempDir , exports . FEATURE _FLAGS _FILE _NAME ) , logger ) ;
2021-12-14 19:50:52 +00:00
}
2023-01-05 13:11:53 +00:00
async getDefaultCliVersion ( variant ) {
return await this . gitHubFeatureFlags . getDefaultCliVersion ( variant ) ;
}
2022-10-06 12:29:58 -07:00
/**
*
2022-10-11 18:56:15 +01:00
* @param feature The feature to check.
2022-10-06 12:29:58 -07:00
* @param codeql An optional CodeQL object. If provided, and a `minimumVersion` is specified for the
2022-10-11 18:56:15 +01:00
* 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
2022-10-06 12:29:58 -07:00
* this function will throw.
2022-10-11 18:56:15 +01:00
* @returns true if the feature is enabled, false otherwise.
2022-10-06 12:29:58 -07:00
*
2022-10-11 18:56:15 +01:00
* @throws if a `minimumVersion` is specified for the feature, and `codeql` is not provided.
2022-10-06 12:29:58 -07:00
*/
2022-10-07 11:33:32 -07:00
async getValue ( feature , codeql ) {
if ( ! codeql && exports . featureConfig [ feature ] . minimumVersion ) {
throw new Error ( ` Internal error: A minimum version is specified for feature ${ feature } , but no instance of CodeQL was provided. ` ) ;
2022-10-06 12:29:58 -07:00
}
2024-04-12 15:59:50 +01:00
if ( ! codeql && exports . featureConfig [ feature ] . toolsFeature ) {
throw new Error ( ` Internal error: A required tools feature is specified for feature ${ feature } , but no instance of CodeQL was provided. ` ) ;
}
2022-10-07 11:33:32 -07:00
const envVar = ( process . env [ exports . featureConfig [ feature ] . envVar ] || "" ) . toLocaleLowerCase ( ) ;
2022-10-05 15:54:07 -07:00
// Do not use this feature if user explicitly disables it via an environment variable.
if ( envVar === "false" ) {
2023-03-14 20:20:35 +00:00
this . logger . debug ( ` Feature ${ feature } is disabled via the environment variable ${ exports . featureConfig [ feature ] . envVar } . ` ) ;
2022-10-05 15:54:07 -07:00
return false ;
}
// Never use this feature if the CLI version explicitly can't support it.
2022-10-07 11:33:32 -07:00
const minimumVersion = exports . featureConfig [ feature ] . minimumVersion ;
2022-10-05 15:54:07 -07:00
if ( codeql && minimumVersion ) {
2024-04-25 15:20:13 -07:00
if ( ! ( await util . codeQlVersionAtLeast ( codeql , minimumVersion ) ) ) {
2023-03-14 20:20:35 +00:00
this . logger . debug ( ` Feature ${ feature } is disabled because the CodeQL CLI version is older than the minimum ` +
` version ${ minimumVersion } . ` ) ;
2022-10-05 15:54:07 -07:00
return false ;
}
2023-03-14 20:20:35 +00:00
else {
2023-10-04 11:28:28 +01:00
this . logger . debug ( ` CodeQL CLI version ${ ( await codeql . getVersion ( ) ) . version } is newer than the minimum ` +
2023-03-14 20:20:35 +00:00
` version ${ minimumVersion } for feature ${ feature } . ` ) ;
}
2022-10-05 15:54:07 -07:00
}
2024-04-12 15:59:50 +01:00
const toolsFeature = exports . featureConfig [ feature ] . toolsFeature ;
if ( codeql && toolsFeature ) {
if ( ! ( await codeql . supportsFeature ( toolsFeature ) ) ) {
this . logger . debug ( ` Feature ${ feature } is disabled because the CodeQL CLI version does not support the ` +
` required tools feature ${ toolsFeature } . ` ) ;
return false ;
}
else {
this . logger . debug ( ` CodeQL CLI version ${ ( await codeql . getVersion ( ) ) . version } supports the required tools feature ${ toolsFeature } for feature ${ feature } . ` ) ;
}
}
2022-10-05 15:54:07 -07:00
// Use this feature if user explicitly enables it via an environment variable.
if ( envVar === "true" ) {
2023-03-14 20:20:35 +00:00
this . logger . debug ( ` Feature ${ feature } is enabled via the environment variable ${ exports . featureConfig [ feature ] . envVar } . ` ) ;
2022-10-05 15:54:07 -07:00
return true ;
}
// Ask the GitHub API if the feature is enabled.
2023-03-14 20:20:35 +00:00
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 = exports . featureConfig [ feature ] . defaultValue ;
this . logger . debug ( ` Feature ${ feature } is ${ defaultValue ? "enabled" : "disabled" } due to its default value. ` ) ;
return defaultValue ;
2022-10-06 14:42:57 -07:00
}
}
exports . Features = Features ;
class GitHubFeatureFlags {
2022-11-21 11:14:38 -08:00
constructor ( gitHubVersion , repositoryNwo , featureFlagsFile , logger ) {
2022-10-06 14:42:57 -07:00
this . gitHubVersion = gitHubVersion ;
this . repositoryNwo = repositoryNwo ;
2022-11-21 11:14:38 -08:00
this . featureFlagsFile = featureFlagsFile ;
2022-10-06 14:42:57 -07:00
this . logger = logger ;
2023-02-10 09:06:43 -08:00
this . hasAccessedRemoteFeatureFlags = false ; // Not accessed by default.
2022-10-06 14:42:57 -07:00
}
2023-01-05 13:17:37 +00:00
getCliVersionFromFeatureFlag ( f ) {
2023-01-05 13:11:53 +00:00
if ( ! f . startsWith ( DEFAULT _VERSION _FEATURE _FLAG _PREFIX ) ||
! f . endsWith ( DEFAULT _VERSION _FEATURE _FLAG _SUFFIX ) ) {
return undefined ;
}
2023-01-05 13:17:37 +00:00
const version = f
2023-01-05 13:11:53 +00:00
. substring ( DEFAULT _VERSION _FEATURE _FLAG _PREFIX . length , f . length - DEFAULT _VERSION _FEATURE _FLAG _SUFFIX . length )
. replace ( /_/g , "." ) ;
2023-01-05 13:17:37 +00:00
if ( ! semver . valid ( version ) ) {
this . logger . warning ( ` Ignoring feature flag ${ f } as it does not specify a valid CodeQL version. ` ) ;
return undefined ;
}
return version ;
2023-01-05 13:11:53 +00:00
}
async getDefaultCliVersion ( variant ) {
if ( variant === util . GitHubVariant . DOTCOM ) {
2023-07-07 14:52:52 +01:00
return await this . getDefaultDotcomCliVersion ( ) ;
2023-01-05 13:11:53 +00:00
}
return {
cliVersion : defaults . cliVersion ,
tagName : defaults . bundleVersion ,
} ;
}
async getDefaultDotcomCliVersion ( ) {
const response = await this . getAllFeatures ( ) ;
const enabledFeatureFlagCliVersions = Object . entries ( response )
2023-01-05 13:17:37 +00:00
. map ( ( [ f , isEnabled ] ) => isEnabled ? this . getCliVersionFromFeatureFlag ( f ) : undefined )
2024-08-05 18:33:27 +01:00
. filter ( ( f ) => f !== undefined ) ;
2023-01-05 13:11:53 +00:00
if ( enabledFeatureFlagCliVersions . length === 0 ) {
2023-01-23 20:00:44 +00:00
// We expect at least one default CLI version to be enabled on Dotcom at any time. However if
// the feature flags are misconfigured, rather than crashing, we fall back to the CLI version
// shipped with the Action in defaults.json. This has the effect of immediately rolling out
// new CLI versions to all users running the latest Action.
//
// A drawback of this approach relates to the small number of users that run old versions of
// the Action on Dotcom. As a result of this approach, if we misconfigure the feature flags
// then these users will experience some alert churn. This is because the CLI version in the
// defaults.json shipped with an old version of the Action is likely older than the CLI
// version that would have been specified by the feature flags before they were misconfigured.
this . logger . warning ( "Feature flags do not specify a default CLI version. Falling back to the CLI version " +
` shipped with the Action. This is ${ defaults . cliVersion } . ` ) ;
2023-07-07 14:52:52 +01:00
const result = {
cliVersion : defaults . cliVersion ,
tagName : defaults . bundleVersion ,
2023-01-25 11:09:18 -08:00
} ;
2023-07-07 14:52:52 +01:00
if ( this . hasAccessedRemoteFeatureFlags ) {
result . toolsFeatureFlagsValid = false ;
}
return result ;
2023-01-05 13:11:53 +00:00
}
const maxCliVersion = enabledFeatureFlagCliVersions . reduce ( ( maxVersion , currentVersion ) => currentVersion > maxVersion ? currentVersion : maxVersion , enabledFeatureFlagCliVersions [ 0 ] ) ;
this . logger . debug ( ` Derived default CLI version of ${ maxCliVersion } from feature flags. ` ) ;
2023-07-07 14:52:52 +01:00
return {
cliVersion : maxCliVersion ,
tagName : ` codeql-bundle-v ${ maxCliVersion } ` ,
toolsFeatureFlagsValid : true ,
} ;
2023-01-05 13:11:53 +00:00
}
2022-10-07 11:33:32 -07:00
async getValue ( feature ) {
2022-11-21 11:14:38 -08:00
const response = await this . getAllFeatures ( ) ;
2021-12-16 13:14:32 +00:00
if ( response === undefined ) {
2023-03-07 16:24:55 -08:00
this . logger . debug ( ` No feature flags API response for ${ feature } . ` ) ;
return undefined ;
2022-07-18 10:14:40 +00:00
}
2023-03-09 16:46:51 +00:00
const features = response [ feature ] ;
if ( features === undefined ) {
2023-03-07 16:24:55 -08:00
this . logger . debug ( ` Feature ' ${ feature } ' undefined in API response. ` ) ;
return undefined ;
2021-12-16 13:14:32 +00:00
}
2023-03-09 16:46:51 +00:00
return ! ! features ;
2021-12-14 19:50:52 +00:00
}
2022-11-21 11:14:38 -08:00
async getAllFeatures ( ) {
// if we have an in memory cache, use that
if ( this . cachedApiResponse !== undefined ) {
return this . cachedApiResponse ;
}
// if a previous step has written a feature flags file to disk, use that
const fileFlags = await this . readLocalFlags ( ) ;
if ( fileFlags !== undefined ) {
this . cachedApiResponse = fileFlags ;
return fileFlags ;
}
// if not, request flags from the server
let remoteFlags = await this . loadApiResponse ( ) ;
if ( remoteFlags === undefined ) {
remoteFlags = { } ;
}
// cache the response in memory
this . cachedApiResponse = remoteFlags ;
// and cache them to disk so future workflow steps can use them
await this . writeLocalFlags ( remoteFlags ) ;
return remoteFlags ;
}
async readLocalFlags ( ) {
try {
if ( fs . existsSync ( this . featureFlagsFile ) ) {
this . logger . debug ( ` Loading feature flags from ${ this . featureFlagsFile } ` ) ;
return JSON . parse ( fs . readFileSync ( this . featureFlagsFile , "utf8" ) ) ;
}
}
catch ( e ) {
this . logger . warning ( ` Error reading cached feature flags file ${ this . featureFlagsFile } : ${ e } . Requesting from GitHub instead. ` ) ;
}
return undefined ;
}
async writeLocalFlags ( flags ) {
try {
this . logger . debug ( ` Writing feature flags to ${ this . featureFlagsFile } ` ) ;
fs . writeFileSync ( this . featureFlagsFile , JSON . stringify ( flags ) ) ;
}
catch ( e ) {
this . logger . warning ( ` Error writing cached feature flags file ${ this . featureFlagsFile } : ${ e } . ` ) ;
}
2021-12-14 19:50:52 +00:00
}
2022-10-06 14:42:57 -07:00
async loadApiResponse ( ) {
// Do nothing when not running against github.com
2024-10-24 15:12:30 +01:00
if ( this . gitHubVersion . type !== util . GitHubVariant . DOTCOM &&
this . gitHubVersion . type !== util . GitHubVariant . GHE _DOTCOM ) {
2022-10-07 11:33:32 -07:00
this . logger . debug ( "Not running against github.com. Disabling all toggleable features." ) ;
2023-02-10 09:06:43 -08:00
this . hasAccessedRemoteFeatureFlags = false ;
2022-10-06 14:42:57 -07:00
return { } ;
}
try {
2024-05-09 11:42:38 +01:00
const featuresToRequest = Object . entries ( exports . featureConfig )
. filter ( ( [ , config ] ) => ! config . legacyApi )
. map ( ( [ f ] ) => f )
. join ( "," ) ;
2022-11-14 19:48:27 +00:00
const response = await ( 0 , api _client _1 . getApiClient ) ( ) . request ( "GET /repos/:owner/:repo/code-scanning/codeql-action/features" , {
2022-10-06 14:42:57 -07:00
owner : this . repositoryNwo . owner ,
repo : this . repositoryNwo . repo ,
2024-05-09 11:42:38 +01:00
features : featuresToRequest ,
2022-10-06 14:42:57 -07:00
} ) ;
2023-01-11 19:10:22 +00:00
const remoteFlags = response . data ;
2024-05-09 11:52:20 +01:00
this . logger . debug ( "Loaded the following default values for the feature flags from the Code Scanning API:" ) ;
for ( const [ feature , value ] of Object . entries ( remoteFlags ) . sort ( ( [ nameA ] , [ nameB ] ) => nameA . localeCompare ( nameB ) ) ) {
this . logger . debug ( ` ${ feature } : ${ value } ` ) ;
}
2023-02-10 09:06:43 -08:00
this . hasAccessedRemoteFeatureFlags = true ;
2023-01-11 19:10:22 +00:00
return remoteFlags ;
2022-10-06 14:42:57 -07:00
}
catch ( e ) {
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, " +
2023-07-13 11:17:33 +01:00
` please ensure the Action has the 'security-events: write' permission. Details: ${ e . message } ` ) ;
2023-02-10 09:06:43 -08:00
this . hasAccessedRemoteFeatureFlags = false ;
2023-01-11 19:10:22 +00:00
return { } ;
2022-10-06 14:42:57 -07:00
}
else {
2022-10-07 16:27:25 -07:00
// Some features, such as `ml_powered_queries_enabled` affect the produced alerts.
// Considering these features disabled in the event of a transient error could
2022-10-06 14:42:57 -07:00
// therefore lead to alert churn. As a result, we crash if we cannot determine the value of
2022-10-07 11:33:32 -07:00
// the feature.
throw new Error ( ` Encountered an error while trying to determine feature enablement: ${ e } ` ) ;
2022-10-06 14:42:57 -07:00
}
}
}
2021-12-14 19:50:52 +00:00
}
//# sourceMappingURL=feature-flags.js.map