forked from wesbos/awesome-uses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.js
57 lines (47 loc) · 1.75 KB
/
dangerfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* eslint-disable import/no-extraneous-dependencies */
const { danger, fail, markdown, message, schedule } = require('danger');
const validate = require('./scripts/data-validate');
const DATA_FILE = 'src/data.js';
async function main() {
if (!danger.git.modified_files.includes(DATA_FILE)) {
message(`No changes in \`${DATA_FILE}\``);
return;
}
const diff = await danger.git.diffForFile(DATA_FILE);
// eslint-disable-next-line no-eval
const masterData = eval(diff.before);
const { data: changedData, errorMsgs, failedUrls } = await validate(
masterData
);
// If there are errors, will fail the action & add a comment detailing the issues
if (errorMsgs.length) {
fail(`There are ${errorMsgs.length} validation error(s)`);
markdown(
`### Validation Issues\n${errorMsgs.map(msg => `- ${msg}`).join('\n')}`
);
}
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);