diff --git a/src/feature-flags.test.ts b/src/feature-flags.test.ts index 778f2aef5..ae9f079ca 100644 --- a/src/feature-flags.test.ts +++ b/src/feature-flags.test.ts @@ -150,14 +150,8 @@ test("Include no more than 25 features in each API request", async (t) => { // we ask for. Under the hood, the features library will request all features // from the API. const feature = Object.values(Feature)[0]; - // TODO: change to `t.notThrowsAsync` once we implement request chunking. - await t.throwsAsync( - async () => features.getValue(feature, includeCodeQlIfRequired(feature)), - { - message: - "Encountered an error while trying to determine feature enablement: " + - "Error: Can request a maximum of 25 features.", - }, + await t.notThrowsAsync(async () => + features.getValue(feature, includeCodeQlIfRequired(feature)), ); }); }); diff --git a/src/feature-flags.ts b/src/feature-flags.ts index 426c8fa85..826ec59de 100644 --- a/src/feature-flags.ts +++ b/src/feature-flags.ts @@ -622,18 +622,29 @@ class GitHubFeatureFlags { try { const featuresToRequest = Object.entries(featureConfig) .filter(([, config]) => !config.legacyApi) - .map(([f]) => f) - .join(","); + .map(([f]) => f); + + const FEATURES_PER_REQUEST = 25; + const featureChunks: string[][] = []; + while (featuresToRequest.length > 0) { + featureChunks.push(featuresToRequest.splice(0, FEATURES_PER_REQUEST)); + } + + let remoteFlags: GitHubFeatureFlagsApiResponse = {}; + + for (const chunk of featureChunks) { + const response = await getApiClient().request( + "GET /repos/:owner/:repo/code-scanning/codeql-action/features", + { + owner: this.repositoryNwo.owner, + repo: this.repositoryNwo.repo, + features: chunk.join(","), + }, + ); + const chunkFlags = response.data as GitHubFeatureFlagsApiResponse; + remoteFlags = { ...remoteFlags, ...chunkFlags }; + } - const response = await getApiClient().request( - "GET /repos/:owner/:repo/code-scanning/codeql-action/features", - { - owner: this.repositoryNwo.owner, - repo: this.repositoryNwo.repo, - features: featuresToRequest, - }, - ); - const remoteFlags = response.data as GitHubFeatureFlagsApiResponse; this.logger.debug( "Loaded the following default values for the feature flags from the Code Scanning API:", );