pr_review_guidelines.rst 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. .. _doc_pr_review_guidelines:
  2. Pull request review process
  3. ===========================
  4. .. note::
  5. This page is intended to provide insight into the pull request (PR) review
  6. process that we aspire to. As such, it is primarily targeted at engine
  7. maintainers who are responsible for reviewing and approving pull requests.
  8. That being said, much of the content is useful for prospective contributors
  9. wanting to know how to ensure that their PR is merged.
  10. From a high level, the ideal life cycle of a pull request looks like the
  11. following:
  12. 1. A contributor opens a PR that fixes a specific problem (optimally closing
  13. a GitHub `issue <https://github.com/godotengine/godot>`_ or implementing
  14. a `proposal <https://github.com/godotengine/godot-proposals>`_).
  15. 2. Other contributors provide feedback on the PR (including reviewing and/or
  16. approving the PR, as appropriate).
  17. 3. An engine maintainer reviews the code and provides feedback, requests
  18. changes, or approves the pull request, as appropriate.
  19. 4. Another maintainer reviews the code with a focus on code style/clarity and
  20. approves it once satisfied.
  21. 5. A team leader or a member of the `production team
  22. <https://godotengine.org/teams#production>`_ merges the pull request if
  23. satisfied that it has been sufficiently reviewed.
  24. This document will explain steps 2, 3, 4, and 5 in more detail. For a more
  25. detailed explanation of the pull request workflow please see the :ref:`pull
  26. request workflow document <doc_pr_workflow>`.
  27. .. note::
  28. In practice these steps may blend together. Oftentimes maintainers will
  29. provide comments on code style and code quality at the same time and will
  30. approve a pull request for both.
  31. Typically the first interaction on a pull request will be an engine maintainer
  32. assigning tags to the pull request and flagging it for review by someone
  33. familiar with that area of code.
  34. Engine maintainers are folks who are "members" of the Godot project repository
  35. on GitHub and/or are listed on the `Teams page <https://godotengine.org/teams>`_
  36. on the Godot website. Maintainers are responsible for a given area of the
  37. engine. Typically this means they are the people who are given more trust to
  38. approve and recommend pull requests for merging.
  39. Even if you are not a maintainer, you can still help by reviewing code,
  40. providing feedback on PRs and testing PRs locally on your machine to confirm
  41. that they work as intended. Many of the currently active maintainers started out
  42. doing this before they became maintainers.
  43. Code review and testing
  44. -----------------------
  45. The following is a list of things that contributors and engine maintainers can
  46. do to conduct a substantive code review of a pull request.
  47. .. note::
  48. If you want to conduct a code review, but can't do everything on this list,
  49. say that in your review comment. For example, it is still very helpful to
  50. provide comments on code, even if you can't build the pull request locally to
  51. test the pull request (or vice versa). Feel free to review the code, just
  52. remember to make a note at the end of your review that you have reviewed the
  53. code only and have not tested the changes locally.
  54. 1. Confirm that the problem exists
  55. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  56. PRs need to solve problems and problems need to be documented. Make sure that
  57. the pull request links and closes (or at least addresses) a bug or a proposal.
  58. If it doesn't, consider asking the contributor to update the opening message of
  59. the PR to explain the problem that the PR aims to solve in more detail.
  60. .. note::
  61. It should be clear _why_ a pull request is needed before it is merged. This
  62. assists reviewers in determining whether a PR does what it says it does and it
  63. helps contributors in the future understand why the code is the way it is.
  64. 2. Test the PR and look for regressions
  65. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  66. While strict code review and CI help to ensure that all pull requests work as
  67. intended, mistakes happen and sometimes contributors push code that creates a
  68. problem in addition to solving a problem. Maintainers will avoid merging code
  69. that contains a regression even if it solves the problem as intended.
  70. When reviewing a pull request, ensure that the PR does what it says it does
  71. (i.e. fixes the linked bug or implements the new feature) and nothing outside of
  72. the PR target area is broken by the change. You can do this by running the
  73. editor and trying out some common functions of the editor (adding objects to a
  74. scene, running GDScript, opening and closing menus etc.). Also, while reviewing
  75. the code, look for suspicious changes in other parts of the engine. Sometimes
  76. during rebasing changes slip through that contributors are not aware of.
  77. 3. Do a code review
  78. ^^^^^^^^^^^^^^^^^^^
  79. Code reviews are usually done by people who are already experienced in a given
  80. area. They may be able to provide ideas to make code faster, more organized, or
  81. more idiomatic. But, even if you are not very experienced, you may want to
  82. conduct a code review to provide feedback within the scope of what you are
  83. comfortable reviewing. Doing so is valuable for the area maintainer (as a second
  84. set of eyes on a problem is always helpful) and it is also helpful for you as it
  85. will help you get more familiar with that area of code and will expose you to
  86. how other people solve problems. In fact, reviewing the code of experienced
  87. engine maintainers is a great way to get to know the codebase.
  88. Here are some things to think about and look out for as you review the code:
  89. * **Code only touches the areas announced in the PR (and the commit
  90. message).**
  91. It can be tempting to fix random things in the code, as you see them. However,
  92. this can quickly make a pull request difficult to review and can make it hard
  93. to dig through in the commit history. Small touch-ups next to the related area
  94. are alright, but often bugs that you can find along the way are better fixed
  95. in their own PRs.
  96. * **Code properly uses Godot's own APIs and patterns.**
  97. Consistency is very important, and a solution that already exists in the
  98. codebase is preferable to an ad-hoc solution.
  99. * **Are core areas affected by the change?**
  100. Sometimes a PR that is supposed to solve a local problem can have a
  101. far-reaching effect way outside of its scope. Usually it is best to keep code
  102. changes local to where the problem arises. If you think that the solution
  103. requires changes outside the scope of the problem, it is usually best to seek
  104. the opinion of a team leader who may have another idea for how to solve the
  105. problem.
  106. 4. Iterate with the contributor and improve the PR
  107. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  108. Maintainers should provide feedback and suggestions for improvement if they spot
  109. things in the code that they would like changed. Preferably, suggestions should
  110. come in order of importance: first, address overall code design and the approach
  111. to solving the problem, then make sure the code is complying with the engine's
  112. best practices, and lastly, do the :ref:`code style review <doc_code_style_review>`.
  113. .. note::
  114. **Communicate barriers to merging early in the review process.**
  115. If the PR has clear blockers or will likely not get merged for whatever other
  116. reason, that fact should be communicated as early and clearly as possible. We
  117. want to avoid stringing people along because it feels bad to say "sorry, no".
  118. As you review pull requests, keep the Godot `Code of Conduct
  119. <https://godotengine.org/code-of-conduct>`_ in mind. Especially the following:
  120. * Politeness is expected at all times. Be kind and courteous.
  121. * Always assume positive intent from others.
  122. * Feedback is always welcome, but keep your criticism constructive.
  123. Here are some things to avoid as you iterate on a pull request with a
  124. contributor:
  125. * **Needless double reviews.**
  126. In other words, review the full PR at once and avoid coming back endless times
  127. to point out issues that you could have noted in the first review. Of course,
  128. this can't always be avoided, but we should try to catch everything at once.
  129. * **Being overly nitpicky.**
  130. Code quality can be flexible depending on the area of the engine you are
  131. working in. In general, our standard for code quality is much higher in core
  132. areas and in performance-sensitive areas than it is in editor code for
  133. example.
  134. * **Expanding the scope of a pull request.**
  135. Providing context or related/similar issues or proposals that may be fixed
  136. similarly can be helpful, but adding a "may as well fix that thing over there
  137. as well while at it" or "could we add to this as well?" isn't always fair to
  138. the contributor. Use your judgement when deciding whether additional fixes are
  139. within scope, but try to keep the scope as close to the original pull request
  140. as possible.
  141. And ultimately, don't feel pressured to deal with the PR all alone. Feel free to
  142. ask for a helping hand on the `Godot Contributors Chat
  143. <https://chat.godotengine.org>`_, in the appropriate channel or in #general.
  144. Other teams may already be tagged for review, so you can also wait or ask for
  145. their assistance.
  146. 5. Approve the pull request
  147. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  148. After reviewing the code, if you think that the code is ready to be merged into
  149. the engine, then go ahead and "approve" it. Make sure to also comment and
  150. specify the nature of your review (i.e. say whether you ran the code locally,
  151. whether you reviewed for style as well as correctness, etc.). Even if you are
  152. not an engine maintainer, approving a pull request signals to others that the
  153. code is good and likely solves the problem the PR says it does. Approving a pull
  154. request as a non-engine maintainer does not guarantee that the code will be
  155. merged, other people will still review it, so don't be shy.
  156. .. _doc_code_style_review:
  157. Code style review
  158. -----------------
  159. Generally speaking, we aim to conduct a code review before a style/clarity
  160. review as contributors typically want to know if their general approach is
  161. acceptable before putting in the effort to make nitpicky changes to style. In
  162. other words, maintainers shouldn't ask contributors to change the style of code
  163. that may need to be rewritten in subsequent reviews. Similarly, maintainers
  164. should avoid asking for contributors to rebase PRs if the PR has not been
  165. reviewed.
  166. That being said, not everyone feels confident enough to provide a review on code
  167. correctness, in that case, providing comments on code style and clarity ahead of
  168. a more substantive code review is totally appropriate and more than welcome.
  169. In practice the code style review can be done as part of the substantive code
  170. review. The important thing is that both the substantive code and the code style
  171. need to be reviewed and considered before a pull request is merged.
  172. When reviewing code style pay particular attention to ensuring that the pull
  173. request follows the :ref:`doc_code_style_guidelines`. While ``clang-format`` and
  174. various CI checks can catch a lot of inconsistencies, they are far from perfect
  175. and are unable to detect some issues. For example, you should check that:
  176. * The style of header includes is respected.
  177. * Identifiers use ``snake_case`` and follow our naming conventions.
  178. * Method parameters start with ``p_*`` or ``r_*`` (if they are used to return
  179. a value).
  180. * Braces are used appropriately, even for one-liner conditionals.
  181. * Code is properly spaced (exactly one empty line between methods, no
  182. unnecessary empty lines inside of method bodies).
  183. .. note::
  184. This list is not complete and doesn't aim to be complete. Refer to
  185. the linked style guide document for a complete set of rules. Keep
  186. in mind that ``clang-format`` may not catch things you hope it would,
  187. so pay attention and try to build a sense of what exactly it can and
  188. cannot detect.
  189. Merging pull requests
  190. ---------------------
  191. In general, pull requests should only be merged by members of the production
  192. team or team leaders for pull requests in their area of the engine. For example,
  193. the networking team leader could merge a networking pull request that doesn't
  194. substantially change non-networking sections of code.
  195. In practice it is best to wait for a member of the production team to merge the
  196. pull request as they keep a close eye on the entire codebase and will likely
  197. have a better sense of what other recent/upcoming changes this pull request may
  198. conflict with (or any other reason that it may make sense to delay the pull
  199. request). Feel free to leave a comment saying that the PR should be ready to
  200. merge.
  201. The following are the steps to take before merging a pull request. The degree to
  202. which you adhere to these steps can be flexible for simple/straightforward pull
  203. requests, but they should be carefully taken for complex or risky pull requests.
  204. As a contributor you can help move a pull request forward by doing some of these
  205. steps yourself.
  206. 1. Get feedback from the right people/teams
  207. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  208. Production team members should ensure that the right people look at a pull
  209. request before it is merged. In some cases this may require multiple people to
  210. weigh in. In other cases, only one substantive approval is needed before the
  211. code can be merged.
  212. In general, try not to merge things based on one review alone, especially if it
  213. is your own. Get a second opinion from another maintainer, and make sure all the
  214. teams that may be impacted have been reasonably represented by the reviewers.
  215. For example, if a pull request adds to the documentation, it's often useful to
  216. let the area maintainers check it for factual correctness and let documentation
  217. maintainers check it for formatting, style, and grammar.
  218. A good rule of thumb is that at least one subject matter expert should have
  219. approved the pull request for correctness, and at least one other maintainer
  220. should have approved the pull request for code style. Either of those people
  221. could be the person merging the pull request.
  222. Make sure that the reviews and approvals were left by people competent in that
  223. specific engine area. It is possible that even a long-standing member of the
  224. Godot organization left a review without having the relevant expertise.
  225. .. note::
  226. An easy way to find PRs that may be ready for merging is filtering by
  227. approved PRs and sorting by recently updated. For example, in the main Godot
  228. repository, you can use `this link
  229. <https://github.com/godotengine/godot/pulls?q=is%3Apr+is%3Aopen+review%3Aapproved+sort%3Aupdated-desc>`_.
  230. 2. Get feedback from the community
  231. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  232. If a pull request is having trouble attracting reviewers, you may need to reach
  233. out more broadly to ask for help reviewing. Consider asking:
  234. * the person who reported the bug if the pull request fixes the bug for them,
  235. * contributors who have recently edited that file if they could take a look, or
  236. * a more experienced maintainer from another area if they could provide feedback.
  237. 3. Git checklist
  238. ^^^^^^^^^^^^^^^^
  239. * **Make sure that the PR comes in one commit.**
  240. When each commit is self-contained and could be used to build a clean and
  241. working version of the engine, it may be okay to merge a pull request with
  242. multiple commits, but in general, we require that all pull requests only have
  243. one commit. This helps us keep the Git history clean.
  244. * **Fixes made during the review process must be squashed into
  245. the main commit.**
  246. For multi-commit PRs check that those fixes are amended in the relevant
  247. commits, and are not just applied on top of everything.
  248. * **Make sure that the PR has no merge conflicts.**
  249. Contributors may need to rebase their changes on top of the relevant branch
  250. (e.g. ``master`` or ``3.x``) and manually fix merge conflicts. Even if there
  251. are no merge conflicts, contributors may need to rebase especially old PRs as
  252. the GitHub conflict checker may not catch all conflicts, or the CI may have
  253. changed since it was originally run.
  254. * **Check for proper commit attribution.**
  255. If a contributor uses an author signature that is not listed in their GitHub
  256. account, GitHub won't link the merged pull request to their account. This
  257. keeps them from getting proper credit in the GitHub history and makes them
  258. appear like a new contributor on the GitHub UI even after several
  259. contributions.
  260. Ultimately, it's up to the user if they want to fix it, but they can do so by
  261. authoring the Git commit with the same email they use for their GitHub
  262. account, or by adding the email they used for the Git commit to their GitHub
  263. profile.
  264. * **Check for proper commit messages.**
  265. While we don't have a very strict ruleset for commit messages, we still
  266. require them to be short yet descriptive and use proper English. As a
  267. maintainer you've probably written them enough times to know how to make one,
  268. but for a general template think about *"Fix <issue> in <part of codebase>"*.
  269. For a more detailed recommendation see the `contributing.md
  270. <https://github.com/godotengine/godot/blob/master/CONTRIBUTING.md#format-your-commit-messages-with-readability-in-mind>`_
  271. page in the main Godot repository.
  272. 4. GitHub checklist
  273. ^^^^^^^^^^^^^^^^^^^
  274. * **Validate the target branch of the PR.**
  275. Most Godot development happens around in the ``master`` branch. Therefore most
  276. pull requests must be made against it. From there pull requests can then be
  277. backported to other branches. Be wary of people making PRs on the version they
  278. are using (e.g, ``3.3``) and guide them to make a change against a
  279. higher-order branch (e.g. ``3.x``). If the change is not applicable for the
  280. ``master`` branch, the initial PR can be made against the current maintenance
  281. branch, such as ``3.x``. It's okay for people to make multiple PRs for each
  282. target branch, especially if the changes cannot be easily backported.
  283. Cherry-picking is also an option, if possible. Use the appropriate labels if
  284. the PR can be cherrypicked (e.g. ``cherrypick:3.x``).
  285. .. note::
  286. It is possible to change the target branch of the PR, that has already been
  287. submitted, but be aware of the consequences. As it cannot be synchronized
  288. with the push, the target branch change will inevitable tag the entire list
  289. of maintainers for review. It may also render the CI incapable of running
  290. properly. A push should help with that, but if nothing else, recommend
  291. opening a new, fresh PR.
  292. * **Make sure that the appropriate milestone is assigned.**
  293. This will make it more obvious which version would include the submitted
  294. changes, should the pull request be merged now. Note, that the milestone is
  295. not a binding contract and does not guarantee that this version is definitely
  296. going to include the PR. If the pull request is not merged before the version
  297. is released, the milestone will be moved (and the PR itself may require a
  298. target branch change).
  299. Similarly, when merging a PR with a higher milestone than the current version,
  300. or a "wildcard" milestone (e.g. "4.x"), ensure to update the milestone to the
  301. current version.
  302. * **Make sure that the opening message of the PR contains the
  303. magic words "Closes #..." or "Fixes #...".**
  304. These link the PR and the referenced issue together and allow GitHub to
  305. auto-close the latter when you merge the changes. Note, that this only works
  306. for the PRs that target the ``master`` branch. For others you need to pay
  307. attention and close the related issues manually. Do it with *"Fixed by #..."*
  308. or *"Resolved by #..."* comment to clearly indicate the act for future
  309. contributors.
  310. * **For the issues that get closed by the PR add the closest
  311. relevant milestone.**
  312. In other words, if the PR is targeting the ``master`` branch, but is then also
  313. cherrypicked for ``3.x``, the next ``3.x`` release would be the appropriate
  314. milestone for the closed issue.
  315. 5. Merge the pull request
  316. ^^^^^^^^^^^^^^^^^^^^^^^^^
  317. If it is appropriate for you to be merging a pull request (i.e. you are on the
  318. production team or you are the team leader for that area), you are confident
  319. that the pull request has been sufficiently reviewed, and once you carry out
  320. these steps you can go ahead and merge the pull request.