ci: Move comment creation to dangerfile

This commit is contained in:
Rohit Gohri 2020-05-03 23:58:55 +05:30
parent 2f2ce100fd
commit 38464bf065
2 changed files with 22 additions and 13 deletions

View file

@ -4,17 +4,25 @@ const validate = require('./scripts/data-validate');
async function main() {
let comment = '';
const { data: changedData, errors, failedUrls } = await validate();
const { data: changedData, errorMsgs, failedUrls } = await validate();
// If there are errors, will fail the action & add a comment detailing the issues
// If there are no errors, will leave an "all-clear" comment with relevant URLs (to ease a potential manual check)
if (errors.length || failedUrls.length) {
fail('Action failed with errors, see logs & comment');
if (errorMsgs.length || failedUrls.length) {
fail(
`Action failed with ${errorMsgs.length +
failedUrls.length} errors, see logs & comment`
);
comment += [
'🚨 We have detected the following issues, let us (contributors) know if you need support or clarifications:',
...errors.map(e => `- ${e.message}`),
...failedUrls.map(url => `- URL is invalid: ${url}`),
...errorMsgs.map(msg => `- ${msg}`),
...failedUrls.map(({ url, error, statusCode }) => {
if (error) return `- URL is invalid: ${url}, error: ${error.message}`;
return `- URL is invalid: ${url}, status code: ${statusCode}`;
}),
].join('\n');
} else if (changedData.length) {
comment += [

View file

@ -1,4 +1,3 @@
const core = require('@actions/core');
const { getMasterData, Schema, getStatusCode } = require('./utils.js');
const srcData = require('../src/data.js');
@ -17,28 +16,30 @@ async function main() {
.filter(v => v.error)
.map(v => v.error);
const errorMsgs = [];
errors.forEach(e => {
core.error(e._original.name || e._original.url);
e.details.forEach(d => core.error(d.message));
e.details.forEach(d => errorMsgs.push(d.message));
});
/**
* @type {{url: string, statusCode?: number, error?: Error}[]}
*/
const failedUrls = [];
for (const { url } of data) {
try {
const statusCode = await getStatusCode(url);
if (statusCode < 200 || statusCode >= 400) {
core.error(`Ping to "${url}" failed with status: ${statusCode}`);
failedUrls.push(url);
failedUrls.push({ url, statusCode });
}
} catch (e) {
core.error(`Ping to "${url}" failed with error: ${e}`);
failedUrls.push(url);
failedUrls.push({ url, error: e });
}
}
return {
failedUrls,
errors,
errorMsgs,
data,
};
}