Skip to content

Commit b0545cb

Browse files
hramosfacebook-github-bot
authored andcommitted
Adjust pull-bot configuration for new PR template (facebook#23236)
Summary: The updated Dangerfile config lets pull-bot warn when the PR lacks a Summary, on top of the existing Test Plan and Changelog warnings. It will also be a bit more lenient when it comes to the changelog, making the `-` optional after TYPE. Finally, I removed the "large PR" warning. We haven't had a problem with large PRs recently, and I feel we can deal with these on a case by case basis. [GENERAL] [Changed] Adjust pull-bot to handle new PR template. Tested against this PR (note the non-standard section titles): ``` $ yarn $ yarn danger pr facebook#23236 📋 Missing Summary - <i>Can you add a Summary? To do so, add a "## Summary" section to your PR description. This is a good place to explain the motivation for making this change.</i> - 📋 Missing Test Plan - <i>Can you add a Test Plan? To do so, add a "## Test Plan" section to your PR description. A Test Plan lets us know how these changes were tested.</i> - 📋 Missing Changelog - <i>Can you add a Changelog? To do so, add a "## Changelog" section to your PR description. A changelog entry has the following format: [`[CATEGORY] [TYPE] - Message`](http://facebook.github.io/react-native/docs/contributing#changelog).</i> Found only warnings, not failing the build ✨ Done in 4.86s. ``` Pull Request resolved: facebook#23236 Differential Revision: D13915716 Pulled By: cpojer fbshipit-source-id: 6f1c3e67140c14359fc369b36b900aedf9a3bd8a
1 parent 76328ca commit b0545cb

File tree

1 file changed

+30
-41
lines changed

1 file changed

+30
-41
lines changed

bots/dangerfile.js

+30-41
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7+
* To test Danger during development, run yarn in this directory, then run:
8+
* $ yarn danger pr <URL to GitHub PR>
9+
*
710
* @format
811
*/
912

@@ -13,9 +16,19 @@ const includes = require('lodash.includes');
1316

1417
const {danger, fail, warn} = require('danger');
1518

16-
// Fails if the description is too short.
19+
// Warns if a summary section is missing, or body is too short
20+
const includesSummary =
21+
danger.github.pr.body &&
22+
danger.github.pr.body.toLowerCase().includes('## summary');
1723
if (!danger.github.pr.body || danger.github.pr.body.length < 50) {
1824
fail(':grey_question: This pull request needs a description.');
25+
} else if (!includesSummary) {
26+
const title = ':clipboard: Missing Summary';
27+
const idea =
28+
'Can you add a Summary? ' +
29+
'To do so, add a "## Summary" section to your PR description. ' +
30+
'This is a good place to explain the motivation for making this change.';
31+
warn(`${title} - <i>${idea}</i>`);
1932
}
2033

2134
// Warns if there are changes to package.json, and tags the team.
@@ -31,60 +44,36 @@ if (packageChanged) {
3144
// Warns if a test plan is missing.
3245
const includesTestPlan =
3346
danger.github.pr.body &&
34-
danger.github.pr.body.toLowerCase().includes('test plan');
47+
danger.github.pr.body.toLowerCase().includes('## test plan');
3548
if (!includesTestPlan) {
36-
const title = ':clipboard: Test Plan';
49+
const title = ':clipboard: Missing Test Plan';
3750
const idea =
38-
'This PR appears to be missing a Test Plan. ' +
39-
'Please add a section called "test plan" describing ' +
40-
'how to verify your changes are correct.';
51+
'Can you add a Test Plan? ' +
52+
'To do so, add a "## Test Plan" section to your PR description. ' +
53+
'A Test Plan lets us know how these changes were tested.';
4154
warn(`${title} - <i>${idea}</i>`);
4255
}
4356

4457
// Regex looks for given categories, types, a file/framework/component, and a message - broken into 4 capture groups
45-
const changelogRegex = /\[\s?(ANDROID|GENERAL|IOS)\s?\]\s*?\[\s?(ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY)\s?\]\s*?\-\s*?(.*)/gi;
58+
const changelogRegex = /\[\s?(ANDROID|GENERAL|IOS)\s?\]\s*?\[\s?(ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY)\s?\]\s*?\-?\s*?(.*)/gi;
4659
const includesChangelog =
4760
danger.github.pr.body &&
48-
danger.github.pr.body.toLowerCase().includes('changelog');
61+
(danger.github.pr.body.toLowerCase().includes('## changelog') ||
62+
danger.github.pr.body.toLowerCase().includes('release notes'));
4963
const correctlyFormattedChangelog = changelogRegex.test(danger.github.pr.body);
5064

65+
const changelogInstructions =
66+
'A changelog entry has the following format: [`[CATEGORY] [TYPE] - Message`](http://facebook.github.io/react-native/docs/contributing#changelog).';
5167
if (!includesChangelog) {
52-
const title = ':clipboard: Changelog';
68+
const title = ':clipboard: Missing Changelog';
5369
const idea =
54-
'This PR appears to be missing Changelog. ' +
55-
'Please add a section called "changelog" and ' +
56-
'format it as explained in the [contributing guidelines](http://facebook.github.io/react-native/docs/contributing#changelog).';
70+
'Can you add a Changelog? ' +
71+
'To do so, add a "## Changelog" section to your PR description. ' +
72+
changelogInstructions;
5773
warn(`${title} - <i>${idea}</i>`);
5874
} else if (!correctlyFormattedChangelog) {
59-
const title = ':clipboard: Changelog';
60-
const idea =
61-
'This PR may have incorrectly formatted Changelog. Please ' +
62-
'format it as explained in the [contributing guidelines](http://facebook.github.io/react-native/docs/contributing#changelog).';
63-
warn(`${title} - <i>${idea}</i>`);
64-
}
65-
66-
// Tags big PRs
67-
var bigPRThreshold = 600;
68-
if (danger.github.pr.additions + danger.github.pr.deletions > bigPRThreshold) {
69-
const title = ':exclamation: Big PR';
70-
const idea =
71-
`This PR is unlikely to get reviewed because it touches too many lines (${danger
72-
.github.pr.additions + danger.github.pr.deletions}). ` +
73-
'Consider sending smaller Pull Requests and stack them on top of each other.';
74-
warn(`${title} - <i>${idea}</i>`);
75-
} else if (
76-
danger.git.modified_files +
77-
danger.git.added_files +
78-
danger.git.deleted_files >
79-
bigPRThreshold
80-
) {
81-
const title = ':exclamation: Big PR';
82-
const idea =
83-
`This PR is unlikely to get reviewed because it touches too many files (${danger
84-
.git.modified_files +
85-
danger.git.added_files +
86-
danger.git.deleted_files}). ` +
87-
'Consider sending smaller Pull Requests and stack them on top of each other.';
75+
const title = ':clipboard: Changelog Format';
76+
const idea = 'Did you include a Changelog? ' + changelogInstructions;
8877
warn(`${title} - <i>${idea}</i>`);
8978
}
9079

0 commit comments

Comments
 (0)