forked from badges/shields
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.js
119 lines (105 loc) · 3.68 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Have you identified a contributing guideline that should be included here?
// Please open a pull request!
const { danger, fail, message, warn } = require('danger');
const chainsmoker = require('chainsmoker');
const fileMatch = chainsmoker({
created: danger.git.created_files,
modified: danger.git.modified_files,
createdOrModified: danger.git.modified_files.concat(danger.git.created_files),
deleted: danger.git.deleted_files,
});
const documentation = fileMatch(
'**/*.md',
'lib/all-badge-examples.js',
'frontend/components/usage.js'
);
const server = fileMatch('server.js');
const serviceTests = fileMatch('services/**/*.tester.js');
const helpers = fileMatch(
'lib/**/*.js',
'!**/*.spec.js',
'!lib/all-badge-examples.js'
);
const logos = fileMatch(
'logo/*.svg'
);
const helperTests = fileMatch('lib/**/*.spec.js');
const packageJson = fileMatch('package.json');
const packageLock = fileMatch('package-lock.json');
const capitals = fileMatch('**/*[A-Z]*.js');
const underscores = fileMatch('**/*_*.js');
const targetBranch = danger.github.pr.base.ref;
message([
':sparkles: Thanks for your contribution to Shields, ',
`@${danger.github.pr.user.login}!`
].join(''));
if (targetBranch != 'master') {
const message = `This PR targets \`${targetBranch}\``;
const idea = 'It is likely that the target branch should be `master`';
warn(`${message} - <i>${idea}</i>`);
}
if (documentation.createdOrModified) {
message([
'Thanks for contributing to our documentation. ',
'We :heart: our [documentarians](http://www.writethedocs.org/)!'
].join(''));
}
if (packageJson.modified && !packageLock.modified) {
const message = 'This PR modified package.json, but not package-lock.json';
const idea = 'Perhaps you need to run `npm install`?';
warn(`${message} - <i>${idea}</i>`);
}
if (server.modified && !serviceTests.createdOrModified) {
warn([
'This PR modified the server but none of the service tests. ',
"That's okay so long as it's refactoring existing code.",
].join(''));
}
if (helpers.created && !helperTests.created) {
warn([
'This PR added helper modules in `lib/` but not accompanying tests. ',
'Generally helper modules should have their own tests.',
].join(''));
} else if (helpers.createdOrModified && !helperTests.createdOrModified) {
warn([
'This PR modified helper functions in `lib/` but not accompanying tests. ',
"That's okay so long as it's refactoring existing code.",
].join(''));
}
if (logos.created) {
message([
':art: Thanks for submitting a logo. ',
'Please ensure your contribution follows our ',
'[guidance](https://github.com/badges/shields/blob/master/CONTRIBUTING.md#logos) ',
'for logo submissions.'
].join(''));
}
if (capitals.created || underscores.created) {
fail([
'JavaScript source files should be named with kebab-case ',
'(dash-separated lowercase).',
].join(''));
}
const all_files = danger.git.created_files.concat(danger.git.modified_files);
all_files.forEach(function(file) {
danger.git.diffForFile(file).then(function(diff) {
if (/\+.*assert[(.]/.test(diff.diff)) {
warn([
`Found 'assert' statement added in ${file}. `,
'Please ensure tests are written using Chai ',
'[expect syntax](http://chaijs.com/guide/styles/#expect)'
].join(''));
}
});
});
all_files.forEach(function(file) {
if (/^services\/.+\/.+\.js$/.test(file) && file.endsWith('.js') && !file.endsWith('.tester.js')) {
const tester = file.replace('.js', '.tester.js');
if (all_files.indexOf(tester) == -1) {
warn([
`This PR modified ${file} but not ${tester}. `,
"That's okay so long as it's refactoring existing code.",
].join(''));
}
}
});