awesome-uses/dangerfile.js

45 lines
1.4 KiB
JavaScript
Raw Normal View History

/* eslint-disable import/no-extraneous-dependencies */
2020-05-03 18:42:42 +00:00
const { fail, markdown, message, schedule } = require('danger');
const validate = require('./scripts/data-validate');
async function main() {
const { data: changedData, errorMsgs, failedUrls } = await validate();
// If there are errors, will fail the action & add a comment detailing the issues
2020-05-03 18:42:42 +00:00
if (errorMsgs.length) {
fail(`There are ${errorMsgs.length} validation error(s)`);
2020-05-03 18:42:42 +00:00
markdown(
`### Validation Issues\n${errorMsgs.map(msg => `- ${msg}`).join('\n')}`
);
}
2020-05-03 18:42:42 +00:00
if (failedUrls.length) {
fail(`There are ${failedUrls.length} failing URL(s)`);
2020-05-03 18:42:42 +00:00
markdown(
`### Failing URLs\n${failedUrls
.map(({ url, error, statusCode }) => {
if (error)
return `- URL, ${url}, failed with error: ${error.message}`;
return `- URL, ${url}, failed with status code: ${statusCode}`;
})
.join('\n')}`
);
}
2020-05-03 18:42:42 +00:00
// If there are no errors, will leave an "all-clear" comment with relevant URLs (to ease a potential manual check)
if (!errorMsgs.length && !failedUrls.length && changedData.length) {
message('Automatic validation checks succeeded', { icon: '✅' });
// Comment with the URLs of users that have changed
// for easy access, way easier than taking a screenshot
markdown(
`### Changed URLs\n${changedData
.map(({ name, url }) => `- ${name}, ${url}`)
.join('\n')}`
);
}
}
schedule(main);