-
Notifications
You must be signed in to change notification settings - Fork 2
/
dangerfile.js
46 lines (36 loc) · 2.03 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
/* global danger, fail, warn, message */
const modifiedFiles = danger.git.modified_files;
const bodyAndTitle = (danger.github.pr.body + danger.github.pr.title).toLowerCase();
const isTrivial = bodyAndTitle.includes('#trivial');
if (!isTrivial) {
// Fail if there isn’t a CHANGELOG entry – should update for every PR
if (!danger.git.modified_files.includes('CHANGELOG.md')) {
const changelogLink = 'https://github.com/justeat/f-toggle/blob/master/CHANGELOG.md';
fail(`:memo: Please include a CHANGELOG entry. You can find the current version at <a href="${changelogLink}">CHANGELOG.md</a>`);
}
// Check for version update
const hasPackageJsonChanged = danger.git.modified_files.includes('package.json');
const packageDiff = danger.git.JSONDiffForFile('package.json');
packageDiff.then(result => {
if (!hasPackageJsonChanged || (hasPackageJsonChanged && !result.version)) {
const semverLink = 'https://docs.npmjs.com/getting-started/semantic-versioning';
/* eslint-disable no-console */console.log('Versioning Missing'); console.log(hasPackageJsonChanged, result);/* eslint-enable no-console */
fail(`:exclamation: This PR should include a <a href="${semverLink}">SEMVER</a> version bump, so that it can be published once merged.`);
}
}, err => {
/* eslint-disable no-console */
console.log(err);
/* eslint-enable no-console */
});
// Update the readme when config changes
const taskFiles = modifiedFiles.filter(path => path.startsWith('tasks'));
const configChanged = modifiedFiles.includes('config.js');
const readmeChanged = modifiedFiles.includes('README.md');
if ((taskFiles.length > 0 || configChanged) && !readmeChanged) {
warn(':memo: If you’ve changed the config or task files, please check that the README is still up-to-date.');
}
// Message on deletions
if (danger.github.pr.deletions > danger.github.pr.additions) {
message(':fire: :clap: You’re a deletion machine!');
}
}