Skip to content

Commit 2b05331

Browse files
author
elevatebart
committed
ci: add dangerfile
1 parent 2841542 commit 2b05331

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

dangerfile.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* eslint-disable */
2+
const fs = require("fs");
3+
const path = require("path");
4+
const validateMessage = require("validate-commit-msg");
5+
6+
const packageChanged = danger.git.modified_files.includes("package.json");
7+
const lockfileChanged = danger.git.modified_files.includes("package-lock.json");
8+
9+
if (packageChanged && !lockfileChanged) {
10+
warn(`Changes were made to \`package.json\`, but not to \`package-lock.json\`.
11+
If you’ve changed any dependencies (added, removed or updated any packages), please run \`npm install\` and commit changes in package-lock.json file.`);
12+
}
13+
14+
if (!packageChanged && lockfileChanged) {
15+
warn(`Changes were made to \`package-lock.json\`, but not to \`package.json\`.
16+
Please remove \`package-lock.json\` changes from your pull request. Try to run \`git checkout master -- package-lock.json\` and commit changes.`);
17+
}
18+
19+
// Check test exclusion (.only) is included
20+
var modifiedSpecFiles = danger.git.modified_files.filter(function (filePath) {
21+
return filePath.match(/__tests__\/.+\.(js|jsx|ts|tsx)$/gi);
22+
});
23+
24+
var testFilesIncludeExclusion = modifiedSpecFiles.reduce(function (acc, value) {
25+
var content = fs.readFileSync(value).toString();
26+
var invalid =
27+
content.indexOf("it.only") >= 0 || content.indexOf("describe.only") >= 0;
28+
if (invalid) {
29+
acc.push(path.basename(value));
30+
}
31+
return acc;
32+
}, []);
33+
34+
if (testFilesIncludeExclusion.length > 0) {
35+
fail("an `only` was left in tests (" + testFilesIncludeExclusion + ")");
36+
}
37+
38+
//validate commit message in PR if it conforms conventional change log, notify if it doesn't.
39+
var messageConventionValid = danger.git.commits.reduce(function (acc, value) {
40+
var valid = validateMessage(value.message);
41+
return valid && acc;
42+
}, true);
43+
44+
let errorCount = 0;
45+
46+
if (!messageConventionValid) {
47+
warn(
48+
"commit message does not follows conventional change log (" +
49+
++errorCount +
50+
")"
51+
);
52+
markdown(
53+
"> (" +
54+
errorCount +
55+
") : vue-live uses conventional change log to generate changelog automatically. It seems some commit messages are not following those. Use `git commit --amend` or `git rebase -i` to fix them."
56+
);
57+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"jest": "^26.5.2",
3535
"prettier": "^2.1.2",
3636
"remark": "^12.0.1",
37+
"validate-commit-msg": "^2.14.0",
3738
"vue": "^3.2.47"
3839
},
3940
"scripts": {

yarn.lock

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,13 +1105,23 @@ color-name@~1.1.4:
11051105
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
11061106
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
11071107

1108+
colors@~0.6.0-1:
1109+
version "0.6.2"
1110+
resolved "https://registry.yarnpkg.com/colors/-/colors-0.6.2.tgz#2423fe6678ac0c5dae8852e5d0e5be08c997abcc"
1111+
integrity sha512-OsSVtHK8Ir8r3+Fxw/b4jS1ZLPXkV6ZxDRJQzeD7qo0SqMXWrHDM71DgYzPMHY8SFJ0Ao+nNU2p1MmwdzKqPrw==
1112+
11081113
combined-stream@^1.0.6, combined-stream@~1.0.6:
11091114
version "1.0.8"
11101115
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
11111116
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
11121117
dependencies:
11131118
delayed-stream "~1.0.0"
11141119

1120+
commander@~2.1.0:
1121+
version "2.1.0"
1122+
resolved "https://registry.yarnpkg.com/commander/-/commander-2.1.0.tgz#d121bbae860d9992a3d517ba96f56588e47c6781"
1123+
integrity sha512-J2wnb6TKniXNOtoHS8TSrG9IOQluPrsmyAJ8oCUJOBmv+uLBCyPYAZkD2jFvw2DCzIXNnISIM01NIvr35TkBMQ==
1124+
11151125
component-emitter@^1.2.1:
11161126
version "1.3.0"
11171127
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0"
@@ -1122,6 +1132,11 @@ concat-map@0.0.1:
11221132
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
11231133
integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=
11241134

1135+
conventional-commit-types@^2.0.0:
1136+
version "2.3.0"
1137+
resolved "https://registry.yarnpkg.com/conventional-commit-types/-/conventional-commit-types-2.3.0.tgz#bc3c8ebba0a9e4b3ecc548f1d0674e251ab8be22"
1138+
integrity sha512-6iB39PrcGYdz0n3z31kj6/Km6mK9hm9oMRhwcLnKxE7WNoeRKZbTAobliKrbYZ5jqyCvtcVEfjCiaEzhL3AVmQ==
1139+
11251140
convert-source-map@^1.4.0, convert-source-map@^1.6.0, convert-source-map@^1.7.0:
11261141
version "1.7.0"
11271142
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.7.0.tgz#17a2cb882d7f77d3490585e2ce6c524424a3a442"
@@ -1500,6 +1515,11 @@ fill-range@^7.0.1:
15001515
dependencies:
15011516
to-regex-range "^5.0.1"
15021517

1518+
find-parent-dir@^0.3.0:
1519+
version "0.3.1"
1520+
resolved "https://registry.yarnpkg.com/find-parent-dir/-/find-parent-dir-0.3.1.tgz#c5c385b96858c3351f95d446cab866cbf9f11125"
1521+
integrity sha512-o4UcykWV/XN9wm+jMEtWLPlV8RXCZnMhQI6F6OdHeSez7iiJWePw8ijOlskJZMsaQoGR/b7dH6lO02HhaTN7+A==
1522+
15031523
find-up@^4.0.0, find-up@^4.1.0:
15041524
version "4.1.0"
15051525
resolved "https://registry.yarnpkg.com/find-up/-/find-up-4.1.0.tgz#97afe7d6cdc0bc5928584b7c8d7b16e8a9aa5d19"
@@ -1508,6 +1528,14 @@ find-up@^4.0.0, find-up@^4.1.0:
15081528
locate-path "^5.0.0"
15091529
path-exists "^4.0.0"
15101530

1531+
findup@0.1.5:
1532+
version "0.1.5"
1533+
resolved "https://registry.yarnpkg.com/findup/-/findup-0.1.5.tgz#8ad929a3393bac627957a7e5de4623b06b0e2ceb"
1534+
integrity sha512-Udxo3C9A6alt2GZ2MNsgnIvX7De0V3VGxeP/x98NSVgSlizcDHdmJza61LI7zJy4OEtSiJyE72s0/+tBl5/ZxA==
1535+
dependencies:
1536+
colors "~0.6.0-1"
1537+
commander "~2.1.0"
1538+
15111539
for-in@^1.0.2:
15121540
version "1.0.2"
15131541
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
@@ -3224,6 +3252,11 @@ saxes@^5.0.0:
32243252
dependencies:
32253253
xmlchars "^2.2.0"
32263254

3255+
semver-regex@1.0.0:
3256+
version "1.0.0"
3257+
resolved "https://registry.yarnpkg.com/semver-regex/-/semver-regex-1.0.0.tgz#92a4969065f9c70c694753d55248fc68f8f652c9"
3258+
integrity sha512-1vZcoRC+LPtHFkLUPyrabsATDSHerxW+hJBN8h04HZOZBuewbXaNROtUVdEPrTdZsWNq6sfsXDhd48GB2xTG4g==
3259+
32273260
"semver@2 || 3 || 4 || 5", semver@^5.4.1, semver@^5.5.0:
32283261
version "5.7.1"
32293262
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
@@ -3791,6 +3824,16 @@ v8-to-istanbul@^5.0.1:
37913824
convert-source-map "^1.6.0"
37923825
source-map "^0.7.3"
37933826

3827+
validate-commit-msg@^2.14.0:
3828+
version "2.14.0"
3829+
resolved "https://registry.yarnpkg.com/validate-commit-msg/-/validate-commit-msg-2.14.0.tgz#e5383691012cbb270dcc0bc2a4effebe14890eac"
3830+
integrity sha512-sETG7UmikRVseMyeayyF6L1svmNXoZiyG4TVyLYSVSYjcSuZT602T+irJKjIyE+FutGyngSLxHGLTeyFy+oyag==
3831+
dependencies:
3832+
conventional-commit-types "^2.0.0"
3833+
find-parent-dir "^0.3.0"
3834+
findup "0.1.5"
3835+
semver-regex "1.0.0"
3836+
37943837
validate-npm-package-license@^3.0.1:
37953838
version "3.0.4"
37963839
resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz#fc91f6b9c7ba15c857f4cb2c5defeec39d4f410a"

0 commit comments

Comments
 (0)