mirror of
https://github.com/BradNut/awesome-uses
synced 2025-09-08 17:40:31 +00:00
ci: Move comment creation to dangerfile
This commit is contained in:
parent
2f2ce100fd
commit
38464bf065
2 changed files with 22 additions and 13 deletions
|
|
@ -4,17 +4,25 @@ const validate = require('./scripts/data-validate');
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
let comment = '';
|
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 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 there are no errors, will leave an "all-clear" comment with relevant URLs (to ease a potential manual check)
|
||||||
if (errors.length || failedUrls.length) {
|
if (errorMsgs.length || failedUrls.length) {
|
||||||
fail('Action failed with errors, see logs & comment');
|
fail(
|
||||||
|
`Action failed with ${errorMsgs.length +
|
||||||
|
failedUrls.length} errors, see logs & comment`
|
||||||
|
);
|
||||||
|
|
||||||
comment += [
|
comment += [
|
||||||
'🚨 We have detected the following issues, let us (contributors) know if you need support or clarifications:',
|
'🚨 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');
|
].join('\n');
|
||||||
} else if (changedData.length) {
|
} else if (changedData.length) {
|
||||||
comment += [
|
comment += [
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
const core = require('@actions/core');
|
|
||||||
const { getMasterData, Schema, getStatusCode } = require('./utils.js');
|
const { getMasterData, Schema, getStatusCode } = require('./utils.js');
|
||||||
const srcData = require('../src/data.js');
|
const srcData = require('../src/data.js');
|
||||||
|
|
||||||
|
|
@ -17,28 +16,30 @@ async function main() {
|
||||||
.filter(v => v.error)
|
.filter(v => v.error)
|
||||||
.map(v => v.error);
|
.map(v => v.error);
|
||||||
|
|
||||||
|
const errorMsgs = [];
|
||||||
|
|
||||||
errors.forEach(e => {
|
errors.forEach(e => {
|
||||||
core.error(e._original.name || e._original.url);
|
e.details.forEach(d => errorMsgs.push(d.message));
|
||||||
e.details.forEach(d => core.error(d.message));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {{url: string, statusCode?: number, error?: Error}[]}
|
||||||
|
*/
|
||||||
const failedUrls = [];
|
const failedUrls = [];
|
||||||
for (const { url } of data) {
|
for (const { url } of data) {
|
||||||
try {
|
try {
|
||||||
const statusCode = await getStatusCode(url);
|
const statusCode = await getStatusCode(url);
|
||||||
if (statusCode < 200 || statusCode >= 400) {
|
if (statusCode < 200 || statusCode >= 400) {
|
||||||
core.error(`Ping to "${url}" failed with status: ${statusCode}`);
|
failedUrls.push({ url, statusCode });
|
||||||
failedUrls.push(url);
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
core.error(`Ping to "${url}" failed with error: ${e}`);
|
failedUrls.push({ url, error: e });
|
||||||
failedUrls.push(url);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
failedUrls,
|
failedUrls,
|
||||||
errors,
|
errorMsgs,
|
||||||
data,
|
data,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue