awesome-uses/scripts/data-validate.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

const core = require('@actions/core');
2020-05-03 17:53:30 +00:00
const { getMasterData, Schema, getStatusCode } = require('./utils.js');
const srcData = require('../src/data.js');
async function main() {
// on master branch will be empty array
const masterDataUrls = (await getMasterData()).map(d => d.url);
// so here data will be an array with all users
const data = srcData.filter(d => !masterDataUrls.includes(d.url));
const errors = data
2020-05-03 17:55:24 +00:00
.map(person =>
Schema.validate(person, {
abortEarly: false,
})
)
.filter(v => v.error)
.map(v => v.error);
errors.forEach(e => {
core.error(e._original.name || e._original.url);
e.details.forEach(d => core.error(d.message));
2020-01-13 15:38:23 +00:00
});
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);
}
} catch (e) {
core.error(`Ping to "${url}" failed with error: ${e}`);
failedUrls.push(url);
2020-01-13 15:38:23 +00:00
}
}
return {
failedUrls,
errors,
data,
};
}
module.exports = main;