• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Pull Requests
2
3There are two fundamental components of the Pull Request process: one concrete
4and technical, and one more process oriented. The concrete and technical
5component involves the specific details of setting up your local environment
6so that you can make the actual changes. This is where we will start.
7
8* [Dependencies](#dependencies)
9* [Setting up your local environment](#setting-up-your-local-environment)
10  * [Step 1: Fork](#step-1-fork)
11  * [Step 2: Branch](#step-2-branch)
12* [The Process of Making Changes](#the-process-of-making-changes)
13  * [Step 3: Code](#step-3-code)
14  * [Step 4: Commit](#step-4-commit)
15    * [Commit message guidelines](#commit-message-guidelines)
16  * [Step 5: Rebase](#step-5-rebase)
17  * [Step 6: Test](#step-6-test)
18  * [Step 7: Push](#step-7-push)
19  * [Step 8: Opening the Pull Request](#step-8-opening-the-pull-request)
20  * [Step 9: Discuss and Update](#step-9-discuss-and-update)
21    * [Approval and Request Changes Workflow](#approval-and-request-changes-workflow)
22  * [Step 10: Landing](#step-10-landing)
23* [Reviewing Pull Requests](#reviewing-pull-requests)
24  * [Review a bit at a time](#review-a-bit-at-a-time)
25  * [Be aware of the person behind the code](#be-aware-of-the-person-behind-the-code)
26  * [Respect the minimum wait time for comments](#respect-the-minimum-wait-time-for-comments)
27  * [Abandoned or Stalled Pull Requests](#abandoned-or-stalled-pull-requests)
28  * [Approving a change](#approving-a-change)
29  * [Accept that there are different opinions about what belongs in Node.js](#accept-that-there-are-different-opinions-about-what-belongs-in-nodejs)
30  * [Performance is not everything](#performance-is-not-everything)
31  * [Continuous Integration Testing](#continuous-integration-testing)
32* [Notes](#notes)
33  * [Commit Squashing](#commit-squashing)
34  * [Getting Approvals for your Pull Request](#getting-approvals-for-your-pull-request)
35  * [CI Testing](#ci-testing)
36  * [Waiting Until the Pull Request Gets Landed](#waiting-until-the-pull-request-gets-landed)
37  * [Check Out the Collaborator Guide](#check-out-the-collaborator-guide)
38
39## Dependencies
40
41Node.js has several bundled dependencies in the *deps/* and the *tools/*
42directories that are not part of the project proper. Changes to files in those
43directories should be sent to their respective projects. Do not send a patch to
44Node.js. We cannot accept such patches.
45
46In case of doubt, open an issue in the
47[issue tracker](https://github.com/nodejs/node/issues/) or contact one of the
48[project Collaborators](https://github.com/nodejs/node/#current-project-team-members).
49
50Node.js has many channels on the
51[OpenJS Foundation Slack](https://slack-invite.openjsf.org/). Interesting
52channels are:
53[#nodejs](https://openjs-foundation.slack.com/archives/CK9Q4MB53) for general
54help, questions and discussions.
55[#nodejs-dev](https://openjs-foundation.slack.com/archives/C019Y2T6STH) for
56development of Node.js core specifically.
57
58Node.js also has two IRC channels:
59[#Node.js](https://webchat.freenode.net/?channels=node.js) for general help and
60questions, and
61[#node-dev](https://webchat.freenode.net/?channels=node-dev) for development of
62Node.js core specifically.
63
64## Setting up your local environment
65
66To get started, you will need to have `git` installed locally. Depending on
67your operating system, there are also a number of other dependencies required.
68These are detailed in the [Building guide][].
69
70Depending on your environment you might want to grab IDE specific settings from
71[IDE configs](https://github.com/nodejs/node-code-ide-configs).
72
73Once you have `git` and are sure you have all of the necessary dependencies,
74it's time to create a fork.
75
76### Step 1: Fork
77
78Fork the project [on GitHub](https://github.com/nodejs/node) and clone your fork
79locally.
80
81```text
82$ git clone git@github.com:username/node.git
83$ cd node
84$ git remote add upstream https://github.com/nodejs/node.git
85$ git fetch upstream
86```
87
88Configure `git` so that it knows who you are:
89
90```text
91$ git config user.name "J. Random User"
92$ git config user.email "j.random.user@example.com"
93```
94
95You can use any name/email address you prefer here. We only use the
96metadata generated by `git` using this configuration for properly attributing
97your changes to you in the `AUTHORS` file and the changelog.
98
99If you would like for the GitHub UI to link the commit to your account
100and award you the `Contributor` label after the changes have been merged,
101make sure this local email is also added to your
102[GitHub email list](https://github.com/settings/emails).
103
104### Step 2: Branch
105
106As a best practice to keep your development environment as organized as
107possible, create local branches to work within. These should also be created
108directly off of the `master` branch.
109
110```text
111$ git checkout -b my-branch -t upstream/master
112```
113
114## The Process of Making Changes
115
116### Step 3: Code
117
118The vast majority of Pull Requests opened against the `nodejs/node`
119repository includes changes to one or more of the following:
120
121* the C/C++ code contained in the `src` directory
122* the JavaScript code contained in the `lib` directory
123* the documentation in `doc/api`
124* tests within the `test` directory.
125
126If you are modifying code, please be sure to run `make lint` from time to
127time to ensure that the changes follow the Node.js code style guide.
128
129Any documentation you write (including code comments and API documentation)
130should follow the [Style Guide](../doc-style-guide.md). Code samples
131included in the API docs will also be checked when running `make lint` (or
132`vcbuild.bat lint` on Windows). If you are adding to or deprecating an API,
133use `REPLACEME` for the version number in the documentation YAML.
134
135For contributing C++ code, you may want to look at the
136[C++ Style Guide](../cpp-style-guide.md), as well as the
137[README of `src/`](../../../src/README.md) for an overview over Node.js
138C++ internals.
139
140### Step 4: Commit
141
142It is a best practice to keep your changes as logically grouped
143as possible within individual commits. There is no limit to the number of
144commits any single Pull Request may have, and many contributors find it easier
145to review changes that are split across multiple commits.
146
147```text
148$ git add my/changed/files
149$ git commit
150```
151
152Multiple commits often get squashed when they are landed. See the
153notes about [commit squashing](#commit-squashing).
154
155#### Commit message guidelines
156
157A good commit message should describe what changed and why.
158
1591. The first line should:
160   * contain a short description of the change (preferably 50 characters or
161     less, and no more than 72 characters)
162   * be entirely in lowercase with the exception of proper nouns, acronyms, and
163   the words that refer to code, like function/variable names
164   * be prefixed with the name of the changed subsystem and start with an
165   imperative verb. Check the output of `git log --oneline files/you/changed` to
166   find out what subsystems your changes touch.
167
168   Examples:
169   * `net: add localAddress and localPort to Socket`
170   * `src: fix typos in async_wrap.h`
171
1722. Keep the second line blank.
1733. Wrap all other lines at 72 columns (except for long URLs).
174
1754. If your patch fixes an open issue, you can add a reference to it at the end
176   of the log. Use the `Fixes:` prefix and the full issue URL. For other
177   references use `Refs:`.
178
179   Examples:
180   * `Fixes: https://github.com/nodejs/node/issues/1337`
181   * `Refs: https://eslint.org/docs/rules/space-in-parens.html`
182   * `Refs: https://github.com/nodejs/node/pull/3615`
183
1845. If your commit introduces a breaking change (`semver-major`), it should
185contain an explanation about the reason of the breaking change, which
186situation would trigger the breaking change and what is the exact change.
187
188Sample complete commit message:
189
190```text
191subsystem: explain the commit in one line
192
193The body of the commit message should be one or more paragraphs, explaining
194things in more detail. Please word-wrap to keep columns to 72 characters or
195less.
196
197Fixes: https://github.com/nodejs/node/issues/1337
198Refs: https://eslint.org/docs/rules/space-in-parens.html
199```
200
201If you are new to contributing to Node.js, please try to do your best at
202conforming to these guidelines, but do not worry if you get something wrong.
203One of the existing contributors will help get things situated and the
204contributor landing the Pull Request will ensure that everything follows
205the project guidelines.
206
207### Step 5: Rebase
208
209As a best practice, once you have committed your changes, it is a good idea
210to use `git rebase` (not `git merge`) to synchronize your work with the main
211repository.
212
213```text
214$ git fetch upstream
215$ git rebase upstream/master
216```
217
218This ensures that your working branch has the latest changes from `nodejs/node`
219master.
220
221### Step 6: Test
222
223Bug fixes and features should always come with tests. A
224[guide for writing tests in Node.js][] has been
225provided to make the process easier. Looking at other tests to see how they
226should be structured can also help.
227
228The `test` directory within the `nodejs/node` repository is complex and it is
229often not clear where a new test file should go. When in doubt, add new tests
230to the `test/parallel/` directory and the right location will be sorted out
231later.
232
233Before submitting your changes in a Pull Request, always run the full Node.js
234test suite. To run the tests (including code linting) on Unix / macOS:
235
236```text
237$ ./configure && make -j4 test
238```
239
240And on Windows:
241
242```text
243> vcbuild test
244```
245
246(See the [running tests][] section of Building guide for more details.)
247
248### Step 7: Push
249
250Once you are sure your commits are ready to go, with passing tests and linting,
251begin the process of opening a Pull Request by pushing your working branch to
252your fork on GitHub.
253
254```text
255$ git push origin my-branch
256```
257
258### Step 8: Opening the Pull Request
259
260From within GitHub, opening a new Pull Request will present you with a template
261that should be filled out:
262
263```markdown
264<!--
265Thank you for your Pull Request. Please provide a description above and review
266the requirements below.
267
268Bug fixes and new features should include tests and possibly benchmarks.
269
270Contributors guide: https://github.com/nodejs/node/blob/master/CONTRIBUTING.md
271-->
272
273#### Checklist
274<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->
275
276- [ ] `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes
277- [ ] tests and/or benchmarks are included
278- [ ] documentation is changed or added
279- [ ] commit message follows [commit guidelines](https://github.com/nodejs/node/blob/master/doc/guides/contributing/pull-requests.md#commit-message-guidelines)
280```
281
282Please try to do your best at filling out the details, but feel free to skip
283parts if you're not sure what to put.
284
285Once opened, Pull Requests are usually reviewed within a few days.
286
287### Step 9: Discuss and update
288
289You will probably get feedback or requests for changes to your Pull Request.
290This is a big part of the submission process so don't be discouraged! Some
291contributors may sign off on the Pull Request right away, others may have
292more detailed comments or feedback. This is a necessary part of the process
293in order to evaluate whether the changes are correct and necessary.
294
295To make changes to an existing Pull Request, make the changes to your local
296branch, add a new commit with those changes, and push those to your fork.
297GitHub will automatically update the Pull Request.
298
299```text
300$ git add my/changed/files
301$ git commit
302$ git push origin my-branch
303```
304
305It is also frequently necessary to synchronize your Pull Request with other
306changes that have landed in `master` by using `git rebase`:
307
308```text
309$ git fetch --all
310$ git rebase upstream/master
311$ git push --force-with-lease origin my-branch
312```
313
314**Important:** The `git push --force-with-lease` command is one of the few ways
315to delete history in `git`. Before you use it, make sure you understand the
316risks. If in doubt, you can always ask for guidance in the Pull Request or on
317[IRC in the #node-dev channel][].
318
319If you happen to make a mistake in any of your commits, do not worry. You can
320amend the last commit (for example if you want to change the commit log).
321
322```text
323$ git add any/changed/files
324$ git commit --amend
325$ git push --force-with-lease origin my-branch
326```
327
328There are a number of more advanced mechanisms for managing commits using
329`git rebase` that can be used, but are beyond the scope of this guide.
330
331Feel free to post a comment in the Pull Request to ping reviewers if you are
332awaiting an answer on something. If you encounter words or acronyms that
333seem unfamiliar, refer to this
334[glossary](https://sites.google.com/a/chromium.org/dev/glossary).
335
336#### Approval and Request Changes Workflow
337
338All Pull Requests require "sign off" in order to land. Whenever a contributor
339reviews a Pull Request they may find specific details that they would like to
340see changed or fixed. These may be as simple as fixing a typo, or may involve
341substantive changes to the code you have written. While such requests are
342intended to be helpful, they may come across as abrupt or unhelpful, especially
343requests to change things that do not include concrete suggestions on *how* to
344change them.
345
346Try not to be discouraged. If you feel that a particular review is unfair,
347say so, or contact one of the other contributors in the project and seek their
348input. Often such comments are the result of the reviewer having only taken a
349short amount of time to review and are not ill-intended. Such issues can often
350be resolved with a bit of patience. That said, reviewers should be expected to
351be helpful in their feedback, and feedback that is simply vague, dismissive and
352unhelpful is likely safe to ignore.
353
354### Step 10: Landing
355
356In order to land, a Pull Request needs to be reviewed and [approved][] by
357at least two Node.js Collaborators (one Collaborator approval is enough if the
358pull request has been open for more than 7 days) and pass a
359[CI (Continuous Integration) test run][]. After that, as long as there are no
360objections from other contributors, the Pull Request can be merged. If you find
361your Pull Request waiting longer than you expect, see the
362[notes about the waiting time](#waiting-until-the-pull-request-gets-landed).
363
364When a collaborator lands your Pull Request, they will post
365a comment to the Pull Request page mentioning the commit(s) it
366landed as. GitHub often shows the Pull Request as `Closed` at this
367point, but don't worry. If you look at the branch you raised your
368Pull Request against (probably `master`), you should see a commit with
369your name on it. Congratulations and thanks for your contribution!
370
371## Reviewing Pull Requests
372
373All Node.js contributors who choose to review and provide feedback on Pull
374Requests have a responsibility to both the project and the individual making the
375contribution. Reviews and feedback must be helpful, insightful, and geared
376towards improving the contribution as opposed to simply blocking it. If there
377are reasons why you feel the PR should not land, explain what those are. Do not
378expect to be able to block a Pull Request from advancing simply because you say
379"No" without giving an explanation. Be open to having your mind changed. Be open
380to working with the contributor to make the Pull Request better.
381
382Reviews that are dismissive or disrespectful of the contributor or any other
383reviewers are strictly counter to the [Code of Conduct][].
384
385When reviewing a Pull Request, the primary goals are for the codebase to improve
386and for the person submitting the request to succeed. Even if a Pull Request
387does not land, the submitters should come away from the experience feeling like
388their effort was not wasted or unappreciated. Every Pull Request from a new
389contributor is an opportunity to grow the community.
390
391### Review a bit at a time.
392
393Do not overwhelm new contributors.
394
395It is tempting to micro-optimize and make everything about relative performance,
396perfect grammar, or exact style matches. Do not succumb to that temptation.
397
398Focus first on the most significant aspects of the change:
399
4001. Does this change make sense for Node.js?
4012. Does this change make Node.js better, even if only incrementally?
4023. Are there clear bugs or larger scale issues that need attending to?
4034. Is the commit message readable and correct? If it contains a breaking change
404   is it clear enough?
405
406When changes are necessary, *request* them, do not *demand* them, and do not
407assume that the submitter already knows how to add a test or run a benchmark.
408
409Specific performance optimization techniques, coding styles and conventions
410change over time. The first impression you give to a new contributor never does.
411
412Nits (requests for small changes that are not essential) are fine, but try to
413avoid stalling the Pull Request. Most nits can typically be fixed by the
414Node.js Collaborator landing the Pull Request but they can also be an
415opportunity for the contributor to learn a bit more about the project.
416
417It is always good to clearly indicate nits when you comment: e.g.
418`Nit: change foo() to bar(). But this is not blocking.`
419
420If your comments were addressed but were not folded automatically after new
421commits or if they proved to be mistaken, please, [hide them][hiding-a-comment]
422with the appropriate reason to keep the conversation flow concise and relevant.
423
424### Be aware of the person behind the code
425
426Be aware that *how* you communicate requests and reviews in your feedback can
427have a significant impact on the success of the Pull Request. Yes, we may land
428a particular change that makes Node.js better, but the individual might just
429not want to have anything to do with Node.js ever again. The goal is not just
430having good code.
431
432### Respect the minimum wait time for comments
433
434There is a minimum waiting time which we try to respect for non-trivial
435changes, so that people who may have important input in such a distributed
436project are able to respond.
437
438For non-trivial changes, Pull Requests must be left open for at least 48 hours.
439In most cases, when the PR is relatively small and focused on a narrow set of
440changes, that will provide more than enough time to adequately review. Sometimes
441changes take far longer to review, or need more specialized review from subject
442matter experts. When in doubt, do not rush.
443
444Trivial changes, typically limited to small formatting changes or fixes to
445documentation, may be landed within the minimum 48 hour window.
446
447### Abandoned or Stalled Pull Requests
448
449If a Pull Request appears to be abandoned or stalled, it is polite to first
450check with the contributor to see if they intend to continue the work before
451checking if they would mind if you took it over (especially if it just has
452nits left). When doing so, it is courteous to give the original contributor
453credit for the work they started (either by preserving their name and email
454address in the commit log, or by using an `Author:` meta-data tag in the
455commit.
456
457### Approving a change
458
459Any Node.js core Collaborator (any GitHub user with commit rights in the
460`nodejs/node` repository) is authorized to approve any other contributor's
461work. Collaborators are not permitted to approve their own Pull Requests.
462
463Collaborators indicate that they have reviewed and approve of the changes in
464a Pull Request either by using GitHub's Approval Workflow, which is preferred,
465or by leaving an `LGTM` ("Looks Good To Me") comment.
466
467When explicitly using the "Changes requested" component of the GitHub Approval
468Workflow, show empathy. That is, do not be rude or abrupt with your feedback
469and offer concrete suggestions for improvement, if possible. If you're not
470sure *how* a particular change can be improved, say so.
471
472Most importantly, after leaving such requests, it is courteous to make yourself
473available later to check whether your comments have been addressed.
474
475If you see that requested changes have been made, you can clear another
476collaborator's `Changes requested` review.
477
478Change requests that are vague, dismissive, or unconstructive may also be
479dismissed if requests for greater clarification go unanswered within a
480reasonable period of time.
481
482If you do not believe that the Pull Request should land at all, use
483`Changes requested` to indicate that you are considering some of your comments
484to block the PR from landing. When doing so, explain *why* you believe the
485Pull Request should not land along with an explanation of what may be an
486acceptable alternative course, if any.
487
488### Accept that there are different opinions about what belongs in Node.js
489
490Opinions on this vary, even among the members of the Technical Steering
491Committee.
492
493One general rule of thumb is that if Node.js itself needs it (due to historic
494or functional reasons), then it belongs in Node.js. For instance, `url`
495parsing is in Node.js because of HTTP protocol support.
496
497Also, functionality that either cannot be implemented outside of core in any
498reasonable way, or only with significant pain.
499
500It is not uncommon for contributors to suggest new features they feel would
501make Node.js better. These may or may not make sense to add, but as with all
502changes, be courteous in how you communicate your stance on these. Comments
503that make the contributor feel like they should have "known better" or
504ridiculed for even trying run counter to the [Code of Conduct][].
505
506### Performance is not everything
507
508Node.js has always optimized for speed of execution. If a particular change
509can be shown to make some part of Node.js faster, it's quite likely to be
510accepted. Claims that a particular Pull Request will make things faster will
511almost always be met by requests for performance [benchmark results][] that
512demonstrate the improvement.
513
514That said, performance is not the only factor to consider. Node.js also
515optimizes in favor of not breaking existing code in the ecosystem, and not
516changing working functional code just for the sake of changing.
517
518If a particular Pull Request introduces a performance or functional
519regression, rather than simply rejecting the Pull Request, take the time to
520work *with* the contributor on improving the change. Offer feedback and
521advice on what would make the Pull Request acceptable, and do not assume that
522the contributor should already know how to do that. Be explicit in your
523feedback.
524
525### Continuous Integration Testing
526
527All Pull Requests that contain changes to code must be run through
528continuous integration (CI) testing at [https://ci.nodejs.org/][].
529
530Only Node.js core Collaborators with commit rights to the `nodejs/node`
531repository may start a CI testing run. The specific details of how to do
532this are included in the new Collaborator [Onboarding guide][].
533
534Ideally, the code change will pass ("be green") on all platform configurations
535supported by Node.js (there are over 30 platform configurations currently).
536This means that all tests pass and there are no linting errors. In reality,
537however, it is not uncommon for the CI infrastructure itself to fail on
538specific platforms or for so-called "flaky" tests to fail ("be red"). It is
539vital to visually inspect the results of all failed ("red") tests to determine
540whether the failure was caused by the changes in the Pull Request.
541
542## Notes
543
544### Commit Squashing
545
546In most cases, do not squash commits that you add to your Pull Request during
547the review process. When the commits in your Pull Request land, they may be
548squashed into one commit per logical change. Metadata will be added to the
549commit message (including links to the Pull Request, links to relevant issues,
550and the names of the reviewers). The commit history of your Pull Request,
551however, will stay intact on the Pull Request page.
552
553For the size of "one logical change",
554[0b5191f](https://github.com/nodejs/node/commit/0b5191f15d0f311c804d542b67e2e922d98834f8)
555can be a good example. It touches the implementation, the documentation,
556and the tests, but is still one logical change. All tests should always pass
557when each individual commit lands on the master branch.
558
559### Getting Approvals for Your Pull Request
560
561A Pull Request is approved either by saying LGTM, which stands for
562"Looks Good To Me", or by using GitHub's Approve button.
563GitHub's Pull Request review feature can be used during the process.
564For more information, check out
565[the video tutorial](https://www.youtube.com/watch?v=HW0RPaJqm4g)
566or [the official documentation](https://help.github.com/articles/reviewing-changes-in-pull-requests/).
567
568After you push new changes to your branch, you need to get
569approval for these new changes again, even if GitHub shows "Approved"
570because the reviewers have hit the buttons before.
571
572### CI Testing
573
574Every Pull Request needs to be tested
575to make sure that it works on the platforms that Node.js
576supports. This is done by running the code through the CI system.
577
578Only a Collaborator can start a CI run. Usually one of them will do it
579for you as approvals for the Pull Request come in.
580If not, you can ask a Collaborator to start a CI run.
581
582### Waiting Until the Pull Request Gets Landed
583
584A Pull Request needs to stay open for at least 48 hours from when it is
585submitted, even after it gets approved and passes the CI. This is to make sure
586that everyone has a chance to weigh in. If the changes are trivial,
587collaborators may decide it doesn't need to wait. A Pull Request may well take
588longer to be merged in. All these precautions are important because Node.js is
589widely used, so don't be discouraged!
590
591### Check Out the Collaborator Guide
592
593If you want to know more about the code review and the landing process, see the
594[Collaborator Guide][].
595
596[Building guide]: ../../../BUILDING.md
597[CI (Continuous Integration) test run]: #ci-testing
598[Code of Conduct]: https://github.com/nodejs/admin/blob/master/CODE_OF_CONDUCT.md
599[Collaborator Guide]: ../collaborator-guide.md
600[IRC in the #node-dev channel]: https://webchat.freenode.net?channels=node-dev&uio=d4
601[Onboarding guide]: ../../../onboarding.md
602[approved]: #getting-approvals-for-your-pull-request
603[benchmark results]: ../writing-and-running-benchmarks.md
604[guide for writing tests in Node.js]: ../writing-tests.md
605[hiding-a-comment]: https://help.github.com/articles/managing-disruptive-comments/#hiding-a-comment
606[https://ci.nodejs.org/]: https://ci.nodejs.org/
607[running tests]: ../../../BUILDING.md#running-tests
608