|
| 1 | +--- |
| 2 | +title: "Pull Request Review Guidelines" |
| 3 | +weight: 13 |
| 4 | +slug: "review-guidelines" |
| 5 | +--- |
| 6 | +- [Tips for getting your PR reviewed](#tips-for-getting-your-pr-reviewed) |
| 7 | + - [Use Tokens to signal the state of your PR](#use-tokens-to-signal-the-state-of-your-pr) |
| 8 | + - [Reduce the scope of your PR](#reduce-the-scope-of-your-pr) |
| 9 | + - [Split your PR into logical smaller commits](#split-your-pr-into-logical-smaller-commits) |
| 10 | + - [Squash or remove unnecessary commits](#squash-or-remove-unnecessary-commits) |
| 11 | + - [Explain your changes (comments)](#explain-your-changes-comments) |
| 12 | + - [Ensure you properly test your changes](#ensure-you-properly-test-your-changes) |
| 13 | + - [Commit messages should be thorough and detailed](#commit-messages-should-be-thorough-and-detailed) |
| 14 | + - [Pull Request comments should summarize the PR](#pull-request-comments-should-summarize-the-pr) |
| 15 | + - [Minor changes (typos / link fixes)](#minor-changes-typos--link-fixes) |
| 16 | +- [Tips for code reviewers](#tips-for-code-reviewers) |
| 17 | + - [Managing time](#managing-time) |
| 18 | + - [Block time off to review](#block-time-off-to-review) |
| 19 | + - [Taking a break or stepping away](#taking-a-break-or-stepping-away) |
| 20 | + - [Loop in others when domain specific knowledge is needed](#loop-in-others-when-domain-specific-knowledge-is-needed) |
| 21 | + - [Asking questions](#asking-questions) |
| 22 | + - [Asking for changes](#asking-for-changes) |
| 23 | + - [Commit Hygiene](#commit-hygiene) |
| 24 | + - [Be clear on progress and time](#be-clear-on-progress-and-time) |
| 25 | + - [Checking out a PR](#checking-out-a-pr) |
| 26 | +- [Additional Resources](#additional-resources) |
| 27 | + |
| 28 | + |
| 29 | +## Tips for getting your PR reviewed |
| 30 | + |
| 31 | + |
| 32 | +### Use Tokens to signal the state of your PR |
| 33 | + |
| 34 | +Token phrases like `WIP` or `do not merge` signal to reviewers that the PR is |
| 35 | +potentially in a state that is not complete. This can save significant time for |
| 36 | +reviewers on prioritizing which PR should be reviewed. They can either hold off |
| 37 | +on reviewing altogether or will review the PR with the knowledge that it is not |
| 38 | +complete. |
| 39 | + |
| 40 | + |
| 41 | +### Reduce the scope of your PR |
| 42 | + |
| 43 | +Extremely large PRs take significant amounts of time to both review and evaluate |
| 44 | +for potential upstream/downstream impacts. If it is possible to achieve the |
| 45 | +desired goal over multiple smaller, more concise PR ("Pre-factor"), it decreases |
| 46 | +risk and will have a greater chance of being accepted. |
| 47 | + |
| 48 | + |
| 49 | +### Split your PR into logical smaller commits |
| 50 | + |
| 51 | +Multiple smaller commits that contain the logical pieces of work simplify the |
| 52 | +review process for others to review your code. These commits should be able to |
| 53 | +stand on their own and not necessarily depend on other things. |
| 54 | + |
| 55 | +**Example: Markdown** |
| 56 | + |
| 57 | +A PR that applies both formatting changes and content changes. If taken together |
| 58 | +in a single commit, it will appear to your reviewer that the entire document has |
| 59 | +changed and will require more time to compare and separate the actual content |
| 60 | +changes from the style changes. |
| 61 | + |
| 62 | +If content and style changes were made in separate commits, they could be reviewed |
| 63 | +independently for their changes. |
| 64 | + |
| 65 | +**Example: Generated code** |
| 66 | + |
| 67 | +A PR that has both authored code and generated code can be difficult to parse. |
| 68 | +If the authored code and generated code are in separate commits, the generated |
| 69 | +code can largely be ignored by the reviewer, and they can focus their time on |
| 70 | +the authored code. |
| 71 | + |
| 72 | +### Squash or remove unnecessary commits |
| 73 | + |
| 74 | +Often you may rapidly commit small changes or fixes. These are even more common |
| 75 | +when accepting suggestions through the GitHub UI where each change is done as an |
| 76 | +independent small commit. [Squashing] these down into a logical commit will both |
| 77 | +help your reviewer when performing a final pass, and provide for a clean git |
| 78 | +commit history. |
| 79 | + |
| 80 | + |
| 81 | +### Explain your changes (comments) |
| 82 | + |
| 83 | +Comments should be used for **ANY** non-obvious changes. They should explain why |
| 84 | +something was done and the intent behind it; leave no surprises for the next |
| 85 | +person to view or touch your code. If you spent time debugging, testing, or |
| 86 | +searching for prior art on a means to do something - document it in the comments. |
| 87 | + |
| 88 | +If you leave a `TODO`, it should explain why it needs to be revisited along with |
| 89 | +any relevant information that could help the next person looking to update that |
| 90 | +part of the code. Consider following insertion of a `TODO` with creating a new |
| 91 | +_help wanted_ issue, if appropriate. |
| 92 | + |
| 93 | +This is also true for things that should **NOT** be updated or updated with great |
| 94 | +care. It should document why it cannot be further reduced or changed. For an |
| 95 | +example of this, see the _"[KEEP THE SPACE SHUTTLE FLYING]"_ portion of the |
| 96 | +persistent volume controller as an example. |
| 97 | + |
| 98 | + |
| 99 | +### Ensure you properly test your changes |
| 100 | + |
| 101 | +Code submitted without tests will almost always be rejected at first pass. If an |
| 102 | +area you're updating did not previously have them, adding them in your PR will |
| 103 | +be appreciated and helps improve the overall health of the project. |
| 104 | + |
| 105 | +If something you change has the potential to impact the performance or scalability |
| 106 | +of the project, include a benchmark. These are essential to demonstrate the |
| 107 | +efficacy of your change and will help in preventing potential regressions. |
| 108 | + |
| 109 | + |
| 110 | +### Commit messages should be thorough and detailed |
| 111 | + |
| 112 | +PR comments are not represented in the commit history. Important details |
| 113 | +regarding your changes should be kept in your commit message. |
| 114 | + |
| 115 | +The commit message subject line should be no more than 72 characters and |
| 116 | +summarize the changes being made. |
| 117 | + |
| 118 | +Use the body of the commit message to describe **WHY** the change is being made. |
| 119 | +Describing why something has changed is more important than how. You are |
| 120 | +providing context to both your reviewer and the next person that has to touch |
| 121 | +your code. |
| 122 | + |
| 123 | +For more guidance on commit messages, see our [commit message guidelines]. |
| 124 | + |
| 125 | + |
| 126 | +### Pull Request comments should summarize the PR |
| 127 | + |
| 128 | +The GitHub pull request should contain a summary of the changes being made as |
| 129 | +well as links to all the relevant information related to the PR itself. These |
| 130 | +are things such as issues it closes, KEPs, and any other relevant documentation. |
| 131 | + |
| 132 | +Accurately filling out the issue template and applying the necessary labels |
| 133 | +will greatly speed up the initial triage of your PR. |
| 134 | + |
| 135 | +If there is a portion of your PR that should be explained or linked that is not |
| 136 | +committed as a comment, you can review your own PR, applying additional context |
| 137 | +or links. |
| 138 | + |
| 139 | + |
| 140 | +### Minor changes (typos / link fixes) |
| 141 | + |
| 142 | +While these sort of fixes are appreciated, try and fix multiple instances at the |
| 143 | +same time if possible, instead of issuing subsequent individual PRs for each fix. |
| 144 | + |
| 145 | +--- |
| 146 | + |
| 147 | +## Tips for code reviewers |
| 148 | + |
| 149 | +### Managing time |
| 150 | + |
| 151 | +#### Block time off to review |
| 152 | + |
| 153 | +Often it can be hard to find dedicated, uninterrupted time to review PRs. If you |
| 154 | +can, allocate some time and block it off on your calendar to help stay on top of |
| 155 | +the incoming queue. |
| 156 | + |
| 157 | +#### Taking a break or stepping away |
| 158 | + |
| 159 | +If you are taking a break, going on vacation, or stepping away for a bit -- you |
| 160 | +can set your [GitHub status] to busy; this will signal [Blunderbuss] to not |
| 161 | +automatically assign you to reviews (It does not block manual assignment). |
| 162 | + |
| 163 | +If for an extended period of time, or if you need to focus on other areas, |
| 164 | +consider setting yourself as an `[emeritus_approver]` in some of the areas your |
| 165 | +an approver. |
| 166 | + |
| 167 | + |
| 168 | +### Loop in others when domain specific knowledge is needed |
| 169 | + |
| 170 | +Kubernetes has an incredibly large and complex code base with sections that may |
| 171 | +require domain-specific knowledge. If you are unsure or uncomfortable reviewing |
| 172 | +a portion of a PR, it is better to decline a review and reassign to an owner or |
| 173 | +contributor with more expertise in that area. |
| 174 | + |
| 175 | +If you are brought in for your knowledge in a specific area, try and provide |
| 176 | +meaningful comments to serve as breadcrumbs in the future to help others gain a |
| 177 | +better understanding of that area. |
| 178 | + |
| 179 | + |
| 180 | +### Asking questions |
| 181 | + |
| 182 | +You are encouraged to ask questions and seek an understanding of what the PR is |
| 183 | +doing; however, your question might be answered further into the review. You can |
| 184 | +stage your questions, and before you submit your review, revisit your own comments |
| 185 | +to see if they're still relevant or update them after gaining further context. |
| 186 | + |
| 187 | +Often a question may turn into a request for further comments or changes to |
| 188 | +explain what is happening at that specific point. |
| 189 | + |
| 190 | +In your questions, try and be empathetic when phrasing. Instead of: |
| 191 | + |
| 192 | +_"Why did you do this?"_ |
| 193 | + |
| 194 | +try |
| 195 | + |
| 196 | +_"Am I understanding this correctly? Can you explain why...?"_ |
| 197 | + |
| 198 | +Remember a review is a discussion, often with multiple parties -- be reasonable. |
| 199 | +Try to focus and summarize in ways which constructively move the conversation |
| 200 | +forward instead of retreading ground. |
| 201 | + |
| 202 | +### Asking for changes |
| 203 | + |
| 204 | +It's okay to ask for changes to be made on a PR. In your comments, you should be |
| 205 | +clear on what is a 'nit' or small thing to be improved and a **required** change |
| 206 | +needed to accept the PR. |
| 207 | + |
| 208 | +Be clear and state upfront architectural or larger changes. These should be |
| 209 | +resolved first before addressing any further nits. |
| 210 | + |
| 211 | +It's also okay to say _"No"_ to a PR. As a community, we want to respect people's |
| 212 | +time and efforts, but sometimes things just don't make sense to accept. As |
| 213 | +reviewers, you are the stewards of the code-base and sometimes that means pushing |
| 214 | +back on potential changes. |
| 215 | + |
| 216 | + |
| 217 | +#### Commit Hygiene |
| 218 | + |
| 219 | +It can be seen as trivial, but you can ask the PR author to break apart their |
| 220 | +PR into smaller chunks, or change a commit message to be more informative. They |
| 221 | +are the _"permanent record"_ of the change and should accurately describe both |
| 222 | +what and why it is being done. |
| 223 | + |
| 224 | + |
| 225 | +### Be clear on progress and time |
| 226 | + |
| 227 | +Be upfront with the PR author about where the state of their PR is and what |
| 228 | +needs to be completed for it to be accepted. |
| 229 | + |
| 230 | +No one likes it if their PR misses a release, but it is a fact of life. Try and |
| 231 | +be upfront about it. Don't push a PR through out of guilt or deadlines. Remember, |
| 232 | +you are a steward of the codebase. |
| 233 | + |
| 234 | + |
| 235 | +### Checking out a PR |
| 236 | + |
| 237 | +If a PR is too complex to review through the GitHub UI, you can pull it down |
| 238 | +locally to evaluate. You can do so using the following command: |
| 239 | + |
| 240 | +``` |
| 241 | +git fetch origin pull/<PR ID>/head:<BRANCHNAME> |
| 242 | +git checkout <BRANCHNAME> |
| 243 | +``` |
| 244 | + |
| 245 | +**Example:** |
| 246 | +``` |
| 247 | +git fetch upstream pull/1245/head:foo |
| 248 | +git checkout foo |
| 249 | +``` |
| 250 | + |
| 251 | + |
| 252 | +## Additional Resources |
| 253 | + |
| 254 | +- [Keeping the Bar High - How to be a bad ass Code Reviewer, Tim Hockin] - A |
| 255 | + presentation by Tim from the Kubernetes Contributor Summit in San Diego. It is |
| 256 | + largely what this document is based off of. |
| 257 | +- [Kubernetes Code Reviewing with Tim Hockin] - Some notes and tips from Tim on |
| 258 | + how to effective at reviewing Kubernetes Code. |
| 259 | +- [Live API Review, Jordan Liggitt] - A presentation by Jordan from the Kubernetes |
| 260 | + Contributor Summit in San Diego covering the sort of things they look for when |
| 261 | + performing an API review for a new feature. |
| 262 | +- [The Gentle Art of Patch Review, Sage Sharp] - A blog post from Sage Sharp on |
| 263 | + some methods of approaching PR review |
| 264 | + |
| 265 | + |
| 266 | + |
| 267 | +[squashing]: ./github-workflow.md#squash-commits |
| 268 | +[KEEP THE SPACE SHUTTLE FLYING]: https://github.com/kubernetes/kubernetes/blob/master/pkg/controller/volume/persistentvolume/pv_controller.go#L57-L117 |
| 269 | +[commit message guidelines]: ./pull-requests.md#7-commit-message-guidelines |
| 270 | +[GitHub Status]: https://help.github.com/en/github/setting-up-and-managing-your-github-profile/personalizing-your-profile#setting-a-status |
| 271 | +[Blunderbuss]: https://git.k8s.io/test-infra/prow/plugins/approve/approvers/README.md#blunderbuss-and-reviewers |
| 272 | +[emeritus_approver]: ./owners.md#emeritus |
| 273 | +[Keeping the Bar High - How to be a bad ass Code Reviewer, Tim Hockin]: https://www.youtube.com/watch?v=OZVv7-o8i40 |
| 274 | +[Kubernetes Code Reviewing with Tim Hockin]: https://docs.google.com/document/d/15y8nIgWMzptHcYIeqf4vLJPttE3Fj_ht4I6Nj4ghDLA/edit#heading=h.3dchnigrxf5y |
| 275 | +[Live API Review, Jordan Liggitt]: https://www.youtube.com/watch?v=faRARV3C7Fk |
| 276 | +[The Gentle Art of Patch Review, Sage Sharp]: https://sage.thesharps.us/2014/09/01/the-gentle-art-of-patch-review/ |
| 277 | + |
0 commit comments