mirror of
https://github.com/github/codeql-action
synced 2026-05-29 05:00:55 +03:00
Limit Code Scanning API to 25 features per request
This commit is contained in:
@@ -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
@@ -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:",
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user