-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathdangerfile.js.sample
83 lines (68 loc) · 2.81 KB
/
dangerfile.js.sample
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
const includes = require('lodash.includes');
const { danger, fail, warn } = require('danger');
const jsModifiedFiles = danger.git.modified_files.filter(
path => path.startsWith('src') && path.endsWith('js'),
);
const hasAppChanges =
jsModifiedFiles.filter(filepath => !filepath.endsWith('test.js')).length > 0;
const pr = danger.github.pr;
const prBodyMsg = pr.body;
const prSender = pr.user.login;
const prBaseBranch = pr.base.ref;
const titleRegex = /^([A-Z]{3,}-)([0-9]+)/;
const bodyRegex = /^Fixes #([0-9]+)/;
// Always ensure we assign someone, so that our Slackbot can do its work correctly
if (pr.assignee === null) {
fail(
'Please assign someone to merge this PR, and optionally include people who should review.',
);
}
if (prBaseBranch !== 'development' && prSender !== 'jwu910') {
fail(':skull: Sorry! Please send all pull requests against development!');
}
if (prBaseBranch !== 'master' && prSender !== 'jwu910') {
// Fails if PR's title does not start with ticket abbreviation.
if (!pr.title.match(titleRegex)) {
fail(
':grey_question: This pull request title should start with the ticket format "CIO-1234" \n' +
'See <a href="https://github.com/jwu910/check-it-out/blob/master/CONTRIBUTING.md">Contributing Guidelines</a>',
);
}
// Fails if the description does not contain regex.
if (!prBodyMsg || prBodyMsg.length < 8 || !prBodyMsg.match(bodyRegex)) {
fail(
':grey_question: This pull request should begin with the issue number. \n' +
'Please include "Fixes #<ISSUE_NUMBER>" at the beginning of the description. \n' +
'See <a href="https://github.com/jwu910/check-it-out/blob/master/CONTRIBUTING.md">Contributing Guidelines</a>',
);
}
}
// Warns if package lock was not updated.
const packageChanged = includes(danger.git.modified_files, 'package.json');
const lockfileChanged = includes(
danger.git.modified_files,
'package-lock.json',
);
if (packageChanged && !lockfileChanged) {
const message =
'Changes were made to package.json, but not to package-lock.json';
const idea =
'Perhaps you need to run `npm install`? \n' +
'Package Lock files can be commited with the message `CIO-#<ISSUE_NUMBER> Autogenerate package-lock`';
warn(`${message} - <i>${idea}</i>`);
}
// Fail if there are app changes without a CHANGELOG
if (!danger.git.modified_files.includes('CHANGELOG.md') && hasAppChanges) {
const changelogLink =
'https://github.com/jwu910/check-it-out/blob/master/CHANGELOG.md';
warn(
`Changes to app files were detected, did you forget a CHANGELOG entry? You can find it at <a href='${changelogLink}'>CHANGELOG.md</a>`,
);
}
// Warns if file names were changed
const renamedFiles = danger.git.renamed_files;
if (renamedFiles) {
warn(
'Renamed files were found. Are you sure you want to rename these files?',
);
}