forked from ReactiveX/rxjs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
dangerfile.js
143 lines (116 loc) · 5.87 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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
var fs = require('fs');
var path = require('path');
var _ = require('lodash');
var getSize = require('get-folder-size');
var gzipSize = require('gzip-size');
var validateMessage = require('validate-commit-msg');
//simple regex matcher to detect usage of helper function and its type signature
var hotMatch = /\bhot\(/gi;
var hotSignatureMatch = /\bimport \{.*?hot.*?\} from '.*?\/helpers\/marble-testing'/gi;
var coldMatch = /\bcold\(/gi;
var coldSignatureMatch = /\bimport \{.*?cold.*?\} from '.*?\/helpers\/marble-testing'/gi;
var errorCount = 0;
// Warn when PR size is large
var bigPRThreshold = 600;
if (danger.github.pr.additions + danger.github.pr.deletions > bigPRThreshold) {
warn(':exclamation: Big PR (' + ++errorCount + ')');
markdown('> (' + errorCount + ') : Pull Request size seems relatively large. If Pull Request contains multiple changes, split each into separate PR will helps faster, easier review.');
}
// Check test exclusion (.only) is included
var modifiedSpecFiles = danger.git.modified_files.filter(function (filePath) {
return filePath.match(/-spec.(js|jsx|ts|tsx)$/gi);
});
var testFilesIncludeExclusion = modifiedSpecFiles.reduce(function (acc, value) {
var content = fs.readFileSync(value).toString();
var invalid = _.includes(content, 'it.only') || _.includes(content, 'describe.only');
if (invalid) {
acc.push(path.basename(value));
}
return acc;
}, []);
if (testFilesIncludeExclusion.length > 0) {
fail('an \`only\` was left in tests (' + testFilesIncludeExclusion + ')');
}
// Check test cases missing type signature import for test marble helper functions
var testFilesMissingTypes = modifiedSpecFiles.reduce(function (acc, value) {
var content = fs.readFileSync(value).toString();
var hotFnMatchesWithoutTypes = content.match(hotMatch) && !content.match(hotSignatureMatch);
var coldFnMatchesWithoutTypes = content.match(coldMatch) && !content.match(coldSignatureMatch);
if (hotFnMatchesWithoutTypes || coldFnMatchesWithoutTypes) {
acc.push(path.basename(value));
}
return acc;
}, []);
if (testFilesMissingTypes.length > 0) {
fail('missing type definition import in tests (' + testFilesMissingTypes + ') (' + ++errorCount + ')');
markdown('> (' + errorCount + ') : It seems updated test cases uses test scheduler interface `hot`, `cold` but miss to import type signature for those.');
}
//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);
if (!messageConventionValid) {
warn('commit message does not follows conventional change log (' + ++errorCount + ')');
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.');
}
// TODO(benlesh): update script to run against proper global files
// The name has changed to `rxjs.umd.js` from `Rx.js`
// function getKB(size) {
// return (size / 1024).toFixed(1);
// }
// function getFormattedKB(size) {
// if (size < 0) {
// return '-' + size.toString();
// } else if (size > 0) {
// return '+' + size.toString();
// }
// return size.toString();
// }
// var globalFile = 'Rx.js';
// var minFile = 'Rx.min.js';
// function sizeDiffBadge(name, value) {
// var color = 'lightgrey';
// if (value > 0) {
// color = 'red';
// } else if (value < 0) {
// color = 'green';
// }
// return 'https://img.shields.io/badge/' + name + '-' + getFormattedKB(getKB(value)) + 'KB-' + color + '.svg?style=flat-square';
// }
// //post size of build
// schedule(new Promise(function (res) {
// getSize('./dist/cjs', function (e, result) {
// var localGlobalFile = path.resolve('./dist/global', globalFile);
// var localMinFile = path.resolve('./dist/global', minFile);
// //get sizes of PR build
// var global = fs.statSync(localGlobalFile);
// var global_gzip = gzipSize.sync(fs.readFileSync(localGlobalFile, 'utf8'));
// var min = fs.statSync(localMinFile);
// var min_gzip = gzipSize.sync(fs.readFileSync(localMinFile, 'utf8'));
// //resolve path to release build
// var releasePath = path.dirname(require.resolve(require.resolve('rxjs')));
// var bundlePath = path.resolve(releasePath, 'bundles');
// var bundleGlobalFile = path.resolve(bundlePath, globalFile);
// var bundleMinFile = path.resolve(bundlePath, minFile);
// var packagePath = path.resolve(releasePath, 'package.json');
// var releaseVersion = require(packagePath).version;
// //get sizes of release build
// var bundleGlobal = fs.statSync(bundleGlobalFile);
// var bundle_global_gzip = gzipSize.sync(fs.readFileSync(bundleGlobalFile, 'utf8'));
// var bundleMin = fs.statSync(bundleMinFile);
// var bundle_min_gzip = gzipSize.sync(fs.readFileSync(bundleMinFile, 'utf8'));
// var sizeMessage = '<img src="https://img.shields.io/badge/Size%20Diff%20%28' + releaseVersion + '%29--lightgrey.svg?style=flat-square"/> ';
// sizeMessage += '<img src="' + sizeDiffBadge('Global', global.size - bundleGlobal.size) + '"/> ';
// sizeMessage += '<img src="' + sizeDiffBadge('Global(gzip)', global_gzip - bundle_global_gzip) + '"/> ';
// sizeMessage += '<img src="' + sizeDiffBadge('Min', min.size - bundleMin.size) + '"/> ';
// sizeMessage += '<img src="' + sizeDiffBadge('Min (gzip)', min_gzip - bundle_min_gzip) + '"/> ';
// message(sizeMessage);
// markdown('> CJS: **' + getKB(result) +
// '**KB, global: **' + getKB(global.size) +
// '**KB (gzipped: **' + getKB(global_gzip) +
// '**KB), min: **' + getKB(min.size) +
// '**KB (gzipped: **' + getKB(min_gzip) + '**KB)');
// res();
// });
// }));