Skip to content

Commit c3f76fb

Browse files
Orta Theroxorta
authored andcommitted
Adds danger_js with an initial rule for warning about large PRs
Signed-off-by: Anandaroop Roy <roop@artsymail.com>
1 parent dd8b387 commit c3f76fb

File tree

5 files changed

+323
-5
lines changed

5 files changed

+323
-5
lines changed

dangerfile.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright (c) 2013-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
'use strict';
11+
12+
const { danger, markdown, warn } = require('danger');
13+
14+
// Tags big PRs
15+
var bigPRThreshold = 600;
16+
if (danger.git.modified_files + danger.git.added_files + danger.git.deleted_files > bigPRThreshold) {
17+
const title = ':exclamation: Big PR';
18+
const files = danger.git.modified_files + danger.git.added_files + danger.git.deleted_files;
19+
const idea = `This PR is extremely unlikely to get reviewed because it touches ${files} files.`;
20+
warn(`${title} - <i>${idea}</i>`);
21+
22+
markdown('@facebook-github-bot large-pr');
23+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"coveralls": "^2.11.6",
4848
"create-react-class": "^15.6.2",
4949
"cross-env": "^5.1.1",
50+
"danger": "^2.1.5",
5051
"del": "^2.0.2",
5152
"derequire": "^2.0.3",
5253
"escape-string-regexp": "^1.0.5",

scripts/circleci/test_entry_point.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fi
2424
if [ $((2 % CIRCLE_NODE_TOTAL)) -eq "$CIRCLE_NODE_INDEX" ]; then
2525
COMMANDS_TO_RUN+=('./scripts/circleci/build.sh')
2626
COMMANDS_TO_RUN+=('yarn test-build --runInBand')
27+
COMMANDS_TO_RUN+=('node ./scripts/tasks/danger')
2728
COMMANDS_TO_RUN+=('yarn test-build-prod --runInBand')
2829
COMMANDS_TO_RUN+=('./scripts/circleci/upload_build.sh')
2930
fi

scripts/tasks/danger.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright (c) 2013-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
'use strict';
9+
10+
var path = require('path');
11+
var spawn = require('child_process').spawn;
12+
13+
var extension = process.platform === 'win32' ? '.cmd' : '';
14+
15+
// This came from React Native's circle.yaml
16+
const token = 'e622517d9f1136ea8900' + '07c6373666312cdfaa69';
17+
spawn(path.join('node_modules', '.bin', 'danger' + extension), [], {
18+
// Allow colors to pass through
19+
stdio: 'inherit',
20+
env: {
21+
...process.env,
22+
DANGER_GITHUB_API_TOKEN: token,
23+
},
24+
}).on('close', function(code) {
25+
if (code !== 0) {
26+
console.error('Danger failed');
27+
} else {
28+
console.log('Danger passed');
29+
}
30+
31+
process.exit(code);
32+
});

0 commit comments

Comments
 (0)