Skip to content

Commit 9576b5c

Browse files
authored
Merge pull request #3258 from github/mbg/enablement-errors/case-insensitive
Make `isEnablementError` case-insensitive
2 parents cc88437 + f0e9bf0 commit 9576b5c

File tree

8 files changed

+44
-51
lines changed

8 files changed

+44
-51
lines changed

lib/analyze-action.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action-post.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/setup-codeql-action.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-lib.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-sarif-action.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api-client.test.ts

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -171,37 +171,30 @@ test("wrapApiConfigurationError correctly wraps specific configuration errors",
171171
);
172172

173173
// Enablement errors.
174-
const codeSecurityNotEnabledError = new util.HTTPError(
174+
const enablementErrorMessages = [
175175
"Code Security must be enabled for this repository to use code scanning",
176-
403,
177-
);
178-
res = api.wrapApiConfigurationError(codeSecurityNotEnabledError);
179-
t.deepEqual(
180-
res,
181-
new util.ConfigurationError(
182-
api.getFeatureEnablementError(codeSecurityNotEnabledError.message),
183-
),
184-
);
185-
const advancedSecurityNotEnabledError = new util.HTTPError(
186176
"Advanced Security must be enabled for this repository to use code scanning",
187-
403,
188-
);
189-
res = api.wrapApiConfigurationError(advancedSecurityNotEnabledError);
190-
t.deepEqual(
191-
res,
192-
new util.ConfigurationError(
193-
api.getFeatureEnablementError(advancedSecurityNotEnabledError.message),
194-
),
195-
);
196-
const codeScanningNotEnabledError = new util.HTTPError(
197177
"Code Scanning is not enabled for this repository. Please enable code scanning in the repository settings.",
198-
403,
199-
);
200-
res = api.wrapApiConfigurationError(codeScanningNotEnabledError);
201-
t.deepEqual(
202-
res,
203-
new util.ConfigurationError(
204-
api.getFeatureEnablementError(codeScanningNotEnabledError.message),
205-
),
206-
);
178+
];
179+
const transforms = [
180+
(msg: string) => msg,
181+
(msg: string) => msg.toLowerCase(),
182+
(msg: string) => msg.toLocaleUpperCase(),
183+
];
184+
185+
for (const enablementErrorMessage of enablementErrorMessages) {
186+
for (const transform of transforms) {
187+
const enablementError = new util.HTTPError(
188+
transform(enablementErrorMessage),
189+
403,
190+
);
191+
res = api.wrapApiConfigurationError(enablementError);
192+
t.deepEqual(
193+
res,
194+
new util.ConfigurationError(
195+
api.getFeatureEnablementError(enablementError.message),
196+
),
197+
);
198+
}
199+
}
207200
});

src/api-client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,9 @@ export async function getRepositoryProperties(repositoryNwo: RepositoryNwo) {
285285

286286
function isEnablementError(msg: string) {
287287
return [
288-
/Code Security must be enabled/,
289-
/Advanced Security must be enabled/,
290-
/Code Scanning is not enabled/,
288+
/Code Security must be enabled/i,
289+
/Advanced Security must be enabled/i,
290+
/Code Scanning is not enabled/i,
291291
].some((pattern) => pattern.test(msg));
292292
}
293293

0 commit comments

Comments
 (0)