Limit Code Scanning API to 25 features per request

This commit is contained in:
Chuan-kai Lin
2025-07-11 10:53:24 -07:00
parent 3eaefb4deb
commit 709cf22a66
2 changed files with 24 additions and 19 deletions
+2 -8
View File
@@ -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)),
);
});
});
+22 -11
View File
@@ -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:",
);