awesome-docker/tests/pull_request.js

65 lines
1.7 KiB
Markdown
Raw Normal View History

2020-04-13 14:15:18 +00:00
const fs = require('fs-extra');
const helper = require('./helper');
2020-04-13 14:15:18 +00:00
console.log({
2020-04-13 15:54:25 +00:00
DEBUG: process.env.DEBUG || false,
2020-04-13 14:15:18 +00:00
});
const README = 'README.md';
async function main() {
2020-04-13 15:11:30 +00:00
const has_error = {
show: false,
duplicates: '',
other_links_error: '',
};
2020-04-13 14:15:18 +00:00
const markdown = await fs.readFile(README, 'utf8');
let links = helper.extract_all_links(markdown);
links = links.filter((l) => !helper.exclude_from_list(l)); // exclude websites
helper.LOG.debug_string({ links });
2020-04-13 17:59:09 +00:00
console.log(`total links to check ${links.length}`);
console.log('checking for duplicates links...');
const duplicates = helper.find_duplicates(links);
2020-04-13 14:15:18 +00:00
if (duplicates.length > 0) {
2020-04-13 15:11:30 +00:00
has_error.show = true;
has_error.duplicates = duplicates;
2020-04-13 14:15:18 +00:00
}
helper.LOG.debug_string({ duplicates });
const [github_links, external_links] = helper.partition(links, (link) =>
2020-04-13 14:15:18 +00:00
link.startsWith('https://github.com'),
);
2020-04-13 17:59:09 +00:00
console.log(`checking ${external_links.length} external links...`);
const external_links_error = await helper.batch_fetch({
2020-04-13 17:59:09 +00:00
arr: external_links,
get: helper.fetch_link,
2020-04-13 14:15:18 +00:00
post_filter_func: (x) => !x[1].ok,
BATCH_SIZE: 8,
});
2020-04-13 17:59:09 +00:00
if (external_links_error.length > 0) {
2020-04-13 15:11:30 +00:00
has_error.show = true;
2020-04-13 17:59:09 +00:00
has_error.other_links_error = external_links_error;
2020-04-13 14:15:18 +00:00
}
2020-04-13 17:59:09 +00:00
console.log(`checking ${github_links.length} GitHub repositories...`);
2020-11-09 18:30:28 +00:00
console.log(`skipping GitHub repository check. Run "npm run test" to execute them manually.`);
2020-04-13 17:59:09 +00:00
console.log({
2020-11-08 20:47:56 +00:00
TEST_PASSED: !has_error.show,
2020-04-13 17:59:09 +00:00
EXTERNAL_LINKS: external_links.length,
});
2020-04-13 15:11:30 +00:00
if (has_error.show) {
helper.LOG.error_string(has_error);
2020-04-13 15:11:30 +00:00
process.exit(1);
}
2020-04-13 14:15:18 +00:00
}
console.log('starting...');
main();