-
Notifications
You must be signed in to change notification settings - Fork 7
/
dangerfile.js
57 lines (48 loc) · 2.07 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 */
const fs = require("fs");
const path = require("path");
const validateMessage = require("validate-commit-msg");
const packageChanged = danger.git.modified_files.includes("package.json");
const lockfileChanged = danger.git.modified_files.includes("package-lock.json");
if (packageChanged && !lockfileChanged) {
warn(`Changes were made to \`package.json\`, but not to \`package-lock.json\`.
If you’ve changed any dependencies (added, removed or updated any packages), please run \`npm install\` and commit changes in package-lock.json file. Make sure you’re using npm 5.7+.`);
}
if (!packageChanged && lockfileChanged) {
warn(`Changes were made to \`package-lock.json\`, but not to \`package.json\`.
Please remove \`package-lock.json\` changes from your pull request. Try to run \`git checkout master -- package-lock.json\` and commit changes.`);
}
// Check test exclusion (.only) is included
var modifiedSpecFiles = danger.git.modified_files.filter(function(filePath) {
return filePath.match(/__tests__\/.+\.(js|jsx|ts|tsx)$/gi);
});
var testFilesIncludeExclusion = modifiedSpecFiles.reduce(function(acc, value) {
var content = fs.readFileSync(value).toString();
var invalid =
content.indexOf("it.only") >= 0 || content.indexOf("describe.only") >= 0;
if (invalid) {
acc.push(path.basename(value));
}
return acc;
}, []);
if (testFilesIncludeExclusion.length > 0) {
fail("an `only` was left in tests (" + testFilesIncludeExclusion + ")");
}
//validate commit message in PR if it conforms conventional change log, notify if it doesn't.
var messageConventionValid = danger.git.commits.reduce(function(acc, value) {
var valid = validateMessage(value.message);
return valid && acc;
}, true);
let errorCount = 0;
if (!messageConventionValid) {
warn(
"commit message does not follows conventional change log (" +
++errorCount +
")"
);
markdown(
"> (" +
errorCount +
") : vuepress-plugin-live uses conventional change log to generate changelog automatically. It seems some of your commit messages are not following those."
);
}