Skip to content
This repository was archived by the owner on Oct 1, 2018. It is now read-only.

Commit 8830979

Browse files
authored
Merge pull request #30 from kwonoj/chore-danger
chore(danger): setup danger bot
2 parents 8a3b231 + 9161541 commit 8830979

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

.travis.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
sudo: required
2+
23
dist: trusty
4+
35
addons:
46
apt:
57
sources:
68
- google-chrome
79
packages:
810
- google-chrome-stable
11+
912
language: node_js
13+
1014
node_js:
11-
- "7"
15+
- "7"
16+
1217
before_script:
1318
- export DISPLAY=:99.0
1419
- sh -e /etc/init.d/xvfb start
20+
21+
before_install:
22+
- npm install -g npm@5
23+
1524
script:
16-
- ng lint
17-
- ng test --single-run
18-
- ng build -prod
19-
- ng e2e
25+
- if [ -n "DANGER_GITHUB_API_TOKEN" ]; then echo {} > ./.babelrc && npx danger; fi
26+
- ng lint
27+
- ng test --single-run
28+
- ng build -prod
29+
- ng e2e

dangerfile.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const validateMessage = require('validate-commit-msg');
4+
5+
let errorCount = 0;
6+
7+
// Warn when PR size is large
8+
const bigPRThreshold = 600;
9+
if (danger.github.pr.additions + danger.github.pr.deletions > bigPRThreshold) {
10+
warn(':exclamation: Big PR (' + ++errorCount + ')');
11+
markdown('> (' + errorCount + ') : Pull Request size seems relatively large. If Pull Request contains multiple changes, split each into separate PR will helps faster, easier review.');
12+
}
13+
14+
// Check test exclusion (.only) is included
15+
const modifiedSpecFiles = danger.git.modified_files.filter(function (filePath) {
16+
return filePath.match(/.spec.(js|jsx|ts|tsx)$/gi);
17+
});
18+
19+
const testFilesIncludeExclusion = modifiedSpecFiles.reduce(function (acc, value) {
20+
const content = fs.readFileSync(value).toString();
21+
const invalid =
22+
_.includes(content, 'it.only') || _.includes(content, 'describe.only')
23+
_.includes(content, 'fit(') || _.includes(content, 'fdescribe(');
24+
if (invalid) {
25+
acc.push(path.basename(value));
26+
}
27+
return acc;
28+
}, []);
29+
30+
if (testFilesIncludeExclusion.length > 0) {
31+
fail('an \`only\` was left in tests (' + testFilesIncludeExclusion + ')');
32+
}
33+
34+
//validate commit message in PR if it conforms conventional change log, notify if it doesn't.
35+
const messageConventionValid = danger.git.commits.reduce(function (acc, value) {
36+
const valid = validateMessage(value.message);
37+
return valid && acc;
38+
}, true);
39+
40+
if (!messageConventionValid) {
41+
warn('commit message does not follows conventional change log (' + ++errorCount + ')');
42+
markdown('> (' + errorCount + ') : RxJS uses conventional change log to generate changelog automatically. It seems some of commit messages are not following those, please check [contributing guideline](https://github.com/ReactiveX/rxjs/blob/master/CONTRIBUTING.md#commit-message-format) and update commit messages.');
43+
}

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@
3737
"@angular/service-worker": "1.0.0-beta.16",
3838
"@types/jasmine": "2.5.53",
3939
"@types/jasminewd2": "2.0.2",
40+
"@types/lodash": "4.14.77",
4041
"@types/node": "6.0.60",
4142
"angular2-template-loader": "0.6.2",
4243
"codelyzer": "3.1.1",
44+
"danger": "1.2.0",
4345
"electron": "1.6.11",
4446
"jasmine-core": "2.6.2",
4547
"jasmine-spec-reporter": "4.1.0",
@@ -49,10 +51,12 @@
4951
"karma-coverage-istanbul-reporter": "1.2.1",
5052
"karma-jasmine": "1.1.0",
5153
"karma-jasmine-html-reporter": "0.2.2",
54+
"lodash": "4.17.4",
5255
"protractor": "5.1.2",
5356
"ts-node": "3.2.0",
5457
"tslint": "5.3.2",
5558
"typescript": "2.3.3",
59+
"validate-commit-msg": "2.14.0",
5660
"wallaby-webpack": "*"
5761
}
5862
}

0 commit comments

Comments
 (0)