Skip to content

Commit

Permalink
Showing 6 changed files with 81 additions and 8 deletions.
14 changes: 11 additions & 3 deletions lib/config-utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/config-utils.js.map

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions lib/config-utils.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/config-utils.test.js.map

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions src/config-utils.test.ts
@@ -343,6 +343,36 @@ test("Invalid format of remote config handled correctly", async t => {
});
});

test("No detected languages", async t => {
return await util.withTmpDir(async tmpDir => {
process.env['RUNNER_TEMP'] = tmpDir;
process.env['GITHUB_WORKSPACE'] = tmpDir;

try {
await configUtils.initConfig();
throw new Error('initConfig did not throw error');
} catch (err) {
t.deepEqual(err, new Error(configUtils.getNoLanguagesError()));
}
});
});

test("Unknown languages", async t => {
return await util.withTmpDir(async tmpDir => {
process.env['RUNNER_TEMP'] = tmpDir;
process.env['GITHUB_WORKSPACE'] = tmpDir;

setInput('languages', 'ruby,english');

try {
await configUtils.initConfig();
throw new Error('initConfig did not throw error');
} catch (err) {
t.deepEqual(err, new Error(configUtils.getUnknownLanguagesError(['ruby', 'english'])));
}
});
});

function doInvalidInputTest(
testName: string,
inputFileContents: string,
14 changes: 11 additions & 3 deletions src/config-utils.ts
@@ -412,6 +412,15 @@ function getConfigFilePropertyError(configFile: string, property: string, error:
return 'The configuration file "' + configFile + '" is invalid: property "' + property + '" ' + error;
}

export function getNoLanguagesError(): string {
return "Did not detect any languages to analyze. " +
"Please update input in workflow or check that GitHub detects the correct languages in your repository.";
}

export function getUnknownLanguagesError(languages: string[]): string {
return "Did not recognise the following languages: " + languages.join(', ');
}

/**
* Gets the set of languages in the current repository
*/
@@ -484,8 +493,7 @@ async function getLanguages(): Promise<Language[]> {
// If the languages parameter was not given and no languages were
// detected then fail here as this is a workflow configuration error.
if (languages.length === 0) {
throw new Error("Did not detect any languages to analyze. " +
"Please update input in workflow or check that GitHub detects the correct languages in your repository.");
throw new Error(getNoLanguagesError());
}

// Make sure they are supported
@@ -507,7 +515,7 @@ async function getLanguages(): Promise<Language[]> {
}
}
if (unknownLanguages.length > 0) {
throw new Error("Did not recognise the following languages: " + unknownLanguages.join(', '));
throw new Error(getUnknownLanguagesError(unknownLanguages));
}

return checkedLanguages;

0 comments on commit 6575405

Please sign in to comment.