Add API call for languages if java in input
If a user explicitly includes java in their language inputs, always make an api call to check for kotlin in the repo. Also, add some suggestions from code reviews.
This commit is contained in:
parent
ad7ca9bf21
commit
eb19ecbad1
12 changed files with 112 additions and 92 deletions
38
lib/config-utils.test.js
generated
38
lib/config-utils.test.js
generated
|
|
@ -934,14 +934,7 @@ function parseInputAndConfigMacro(t, packsFromConfig, packsFromInput, languages,
|
|||
languages, "/a/b", mockLogger), expected);
|
||||
}
|
||||
parseInputAndConfigMacro.title = (providedTitle) => `Parse Packs input and config: ${providedTitle}`;
|
||||
const mockLogger = {
|
||||
info: (message) => {
|
||||
console.log("info:", message);
|
||||
},
|
||||
debug: (message) => {
|
||||
console.log("debug:", message);
|
||||
},
|
||||
};
|
||||
const mockLogger = (0, logging_1.getRunnerLogger)(true);
|
||||
function parseInputAndConfigErrorMacro(t, packsFromConfig, packsFromInput, languages, packsFromInputOverride, expected) {
|
||||
t.throws(() => {
|
||||
configUtils.parsePacks(packsFromConfig, packsFromInput, packsFromInputOverride, languages, "/a/b", mockLogger);
|
||||
|
|
@ -1285,23 +1278,6 @@ const mockRepositoryNwo = (0, repository_1.parseRepositoryNwo)("owner/repo");
|
|||
expectedLanguages: ["javascript", "csharp", "cpp"],
|
||||
expectedApiCall: true,
|
||||
},
|
||||
].forEach((args) => {
|
||||
(0, ava_1.default)(`getLanguages: ${args.name}`, async (t) => {
|
||||
const mockRequest = (0, testing_utils_1.mockLanguagesInRepo)(args.languagesInRepository);
|
||||
const languages = args.codeqlResolvedLanguages.reduce((acc, lang) => ({
|
||||
...acc,
|
||||
[lang]: true,
|
||||
}), {});
|
||||
const codeQL = (0, codeql_1.setCodeQL)({
|
||||
resolveLanguages: () => Promise.resolve(languages),
|
||||
});
|
||||
const actualLanguages = await configUtils.getLanguages(codeQL, args.languagesInput, mockRepositoryNwo, mockLogger);
|
||||
t.deepEqual(actualLanguages.sort(), args.expectedLanguages.sort());
|
||||
t.deepEqual(mockRequest.called, args.expectedApiCall);
|
||||
});
|
||||
});
|
||||
// eslint-disable-next-line github/array-foreach
|
||||
[
|
||||
{
|
||||
name: "no languages",
|
||||
codeqlResolvedLanguages: ["javascript", "java", "python"],
|
||||
|
|
@ -1319,7 +1295,7 @@ const mockRepositoryNwo = (0, repository_1.parseRepositoryNwo)("owner/repo");
|
|||
expectedError: configUtils.getUnknownLanguagesError(["a", "b"]),
|
||||
},
|
||||
].forEach((args) => {
|
||||
(0, ava_1.default)(`getLanguages (error when empty): ${args.name}`, async (t) => {
|
||||
(0, ava_1.default)(`getLanguages: ${args.name}`, async (t) => {
|
||||
const mockRequest = (0, testing_utils_1.mockLanguagesInRepo)(args.languagesInRepository);
|
||||
const languages = args.codeqlResolvedLanguages.reduce((acc, lang) => ({
|
||||
...acc,
|
||||
|
|
@ -1328,7 +1304,15 @@ const mockRepositoryNwo = (0, repository_1.parseRepositoryNwo)("owner/repo");
|
|||
const codeQL = (0, codeql_1.setCodeQL)({
|
||||
resolveLanguages: () => Promise.resolve(languages),
|
||||
});
|
||||
await t.throwsAsync(async () => await configUtils.getLanguages(codeQL, args.languagesInput, mockRepositoryNwo, mockLogger), { message: args.expectedError });
|
||||
if (args.expectedLanguages) {
|
||||
// happy path
|
||||
const actualLanguages = await configUtils.getLanguages(codeQL, args.languagesInput, mockRepositoryNwo, mockLogger);
|
||||
t.deepEqual(actualLanguages.sort(), args.expectedLanguages.sort());
|
||||
}
|
||||
else {
|
||||
// there is an error
|
||||
await t.throwsAsync(async () => await configUtils.getLanguages(codeQL, args.languagesInput, mockRepositoryNwo, mockLogger), { message: args.expectedError });
|
||||
}
|
||||
t.deepEqual(mockRequest.called, args.expectedApiCall);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue