mirror of
https://github.com/BradNut/awesome-uses
synced 2025-09-08 17:40:31 +00:00
ci: better formatted messages
This commit is contained in:
parent
3d2af7bc38
commit
ef972cf38f
2 changed files with 34 additions and 27 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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}`)
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue