mirror of
https://github.com/github/codeql-action.git
synced 2025-12-31 19:50:32 +08:00
Turn enablement errors into configuration errors
This commit is contained in:
@@ -169,4 +169,39 @@ test("wrapApiConfigurationError correctly wraps specific configuration errors",
|
||||
res,
|
||||
new util.ConfigurationError("Resource not accessible by integration"),
|
||||
);
|
||||
|
||||
// Enablement errors.
|
||||
const codeSecurityNotEnabledError = new util.HTTPError(
|
||||
"Code Security must be enabled for this repository to use code scanning",
|
||||
403,
|
||||
);
|
||||
res = api.wrapApiConfigurationError(codeSecurityNotEnabledError);
|
||||
t.deepEqual(
|
||||
res,
|
||||
new util.ConfigurationError(
|
||||
`Please verify that the necessary features are enabled: ${codeSecurityNotEnabledError.message}`,
|
||||
),
|
||||
);
|
||||
const advancedSecurityNotEnabledError = new util.HTTPError(
|
||||
"Advanced Security must be enabled for this repository to use code scanning",
|
||||
403,
|
||||
);
|
||||
res = api.wrapApiConfigurationError(advancedSecurityNotEnabledError);
|
||||
t.deepEqual(
|
||||
res,
|
||||
new util.ConfigurationError(
|
||||
`Please verify that the necessary features are enabled: ${advancedSecurityNotEnabledError.message}`,
|
||||
),
|
||||
);
|
||||
const codeScanningNotEnabledError = new util.HTTPError(
|
||||
"Code Scanning is not enabled for this repository. Please enable code scanning in the repository settings.",
|
||||
403,
|
||||
);
|
||||
res = api.wrapApiConfigurationError(codeScanningNotEnabledError);
|
||||
t.deepEqual(
|
||||
res,
|
||||
new util.ConfigurationError(
|
||||
`Please verify that the necessary features are enabled: ${codeScanningNotEnabledError.message}`,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -283,6 +283,14 @@ export async function getRepositoryProperties(repositoryNwo: RepositoryNwo) {
|
||||
});
|
||||
}
|
||||
|
||||
function isEnablementError(msg: string) {
|
||||
return [
|
||||
/Code Security must be enabled/,
|
||||
/Advanced Security must be enabled/,
|
||||
/Code Scanning is not enabled/,
|
||||
].some((pattern) => pattern.test(msg));
|
||||
}
|
||||
|
||||
export function wrapApiConfigurationError(e: unknown) {
|
||||
const httpError = asHTTPError(e);
|
||||
if (httpError !== undefined) {
|
||||
@@ -304,6 +312,11 @@ export function wrapApiConfigurationError(e: unknown) {
|
||||
"Please check that your token is valid and has the required permissions: contents: read, security-events: write",
|
||||
);
|
||||
}
|
||||
if (isEnablementError(httpError.message)) {
|
||||
return new ConfigurationError(
|
||||
`Please verify that the necessary features are enabled: ${httpError.message}`,
|
||||
);
|
||||
}
|
||||
if (httpError.status === 429) {
|
||||
return new ConfigurationError("API rate limit exceeded");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user