diff --git a/dangerfile.js b/dangerfile.js index f35b5d0c..24bcde3a 100644 --- a/dangerfile.js +++ b/dangerfile.js @@ -1,39 +1,44 @@ /* eslint-disable import/no-extraneous-dependencies */ -const { fail, markdown, schedule } = require('danger'); +const { fail, markdown, message, schedule } = require('danger'); const validate = require('./scripts/data-validate'); async function main() { - let comment = ''; 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 (errorMsgs.length || failedUrls.length) { - fail( - `Action failed with ${errorMsgs.length + - failedUrls.length} errors, see logs & comment` + if (errorMsgs.length) { + fail(`There are ${errorMsgs.length} validation error(s)`); + + markdown( + `### Validation Issues\n${errorMsgs.map(msg => `- ${msg}`).join('\n')}` ); - - comment += [ - '🚨 We have detected the following issues, let us (contributors) know if you need support or clarifications:', - - ...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 += [ - '✅ Automatic validation checks succeeded for:', - // Comment with the URLs of users that have changed - // for easy access, way easier than taking a screenshot - ...changedData.map(({ name, url }) => `- ${name}, ${url}`), - ].join('\n'); } - if (comment) markdown(comment); + if (failedUrls.length) { + fail(`There are ${failedUrls.length} failing URL(s)`); + + 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')}` + ); + } + + // 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); diff --git a/scripts/data-validate.js b/scripts/data-validate.js index e9cc0f91..9f25cf7b 100644 --- a/scripts/data-validate.js +++ b/scripts/data-validate.js @@ -19,7 +19,9 @@ async function main() { const errorMsgs = []; errors.forEach(e => { - e.details.forEach(d => errorMsgs.push(d.message)); + e.details.forEach(d => + errorMsgs.push(`${e._original.name || e._original.url}: ${d.message}`) + ); }); /**