github.com/munnerz/test-infra@v0.0.0-20190108210205-ce3d181dc989/prow/plugins/approve/approvers/README.md (about) 1 # Reviewers and Approvers 2 3 ## Questions this Doc Seeks To Answer 4 5 1. What do we need to get a PR merged into kubernetes/kubernetes? 6 2. What are reviewers, approvers, and the OWNERS files? 7 3. How does the reviewer selection mechanism work? approver selection mechanism work? 8 4. How does an approver know which PR s/he has to approve? 9 10 ## Overview 11 12 Every GitHub directory which is a unit of independent code contains a file named "OWNERS". The file lists reviewers and approvers for the directory. Approvers (or previously called assignees) are owners of the codes. 13 14 Approvers: 15 * have contributed substantially to the project 16 * can provide a final approval (`/approve`) indicating whether a change to a directory or subdirectory should be accepted 17 * Approval is done on a per directory basis and subdirectories inherit their parents directory's approvers 18 19 Reviewers: 20 * generally a larger set of current and past contributors 21 * They are responsible for a more thorough code review, discussing the implementation details and style 22 * Provide an `/lgtm` when they are satisfied with the Pull Request 23 24 An example of the OWNERS file is listed below: 25 26 reviewers: 27 * jack 28 * ken 29 * lina 30 31 approvers: 32 * jack 33 * ken 34 * lina 35 36 Note that items in the OWNERS files can be GitHub usernames, or aliases defined in OWNERS_ALIASES files. An OWNERS_ALIASES file is another co-existed file that delivers a mechanism for defining groups. However, GitHub Team names are not supported. We do not use them because there is no audit log for changes to the GitHub Teams. This way we have an audit log. 37 38 ## Blunderbuss And Reviewers 39 40 ### lgtm Label 41 42 LGTM is abbreviation for "look good to me". The **lgtm** label is normally given when the code has been thoroughly reviewed. Getting it means the PR is one step away from getting merged. Reviewers of the PR give the label to a PR by typing /lgtm in a comment, or retract it by typing /lgtm cancel. Authors of the PR cannot give the label, but they can cancel it. The bot retracts the label automatically if someone updates the PR with a new commit. 43 44 ### Blunderbuss Selection Mechanism 45 46 Blunderbuss provides statistical means to select a subset of approvers found in OWNERS files for approving a PR. A PR consists of changes on one or more files, in which each file has different number of lines of codes changed. Blunderbuss determines the magnitude of code change within a PR using total number of lines of codes changed across various files. Number of reviewers selected for each PR is 2. 47 48 Algorithm for selecting reviewers is as follows: 49 50 (1) determine potential reviewers of a file by going over all reviewers found in the OWNERS files for current and parent directories of the file (deduplication involved) 51 52 (2) assign each changed file with a weightage based on number of lines of codes changed 53 54 (3) assign each potential reviewer with a weightage by summing up weightages of all changed files in which s/he is a reviewer 55 56 (4) randomly select 2 reviewers based on their weightage 57 58 ## Approval Handler and the Approved Label 59 60 ### approved Label 61 62 A PR cannot be merged into the Kubernetes repo without the **approved** label. In order for the approved label to be applied, every file modified by the PR must be approved (via /approve) by an approver from the OWNERs files. Note, this does not necessarily require multiple approvers. The process is best illustrated in the example below. 63 64 **Approval Selection Mechanism** 65 66 First, it is important to understand that ALL approvers in an OWNERS file can approve any file in that directory AND its subdirectories. Second, it is important to understand the somewhat-competing goals of the bot when selecting approvers: 67 68 1. Provide a subset of approvers that can approve all files in the PR 69 70 2. Provide a small subset of approvers and suggest the same reviewers as blunderbuss if possible (people can be both reviewers and approvers) 71 72 3. Do not always suggest the same set of people to approver and do not consistently suggest people from the root OWNERS file 73 74 The exact algorithm for selecting approvers is somewhat complex; it is an set cover approximation with consideration for existing assignees. To read it in depth, check out the approvers source code linked at the end of the README. 75 76 **Example** 77 78  79 80 Suppose files in directories E and G are changed in a PR created by PRAuthor. Any combination of approver(s) listed below can approve the PR in order to get it merged: 81 82 (1) approvers found in OWNERS files for leaf (current) directories E and G 83 84 (2) approvers found in OWNERS files for parent directories B and C 85 86 (3) approvers found in OWNERS files for root directory A 87 88 Note someone can be both a reviewer found in OWNERS files for directory A and E. If s/he is selected as an approver and gives approval, it approves entire PR because s/he is also a reviewer for the root directory A. 89 90 **Step 1:** 91 92 K8s-bot creates a comment that suggests the selected approvers and shows a list of OWNERS file(s) where the approvers can be found. 93 94 [APPROVALNOTIFIER] This PR is **NOT APPROVED** 95 96 This pull-request has been approved by: *PRAuthor* 97 We suggest the following additional approvers: **approver1,** **approver2** 98 99 If they are not already assigned, you can assign the PR to them by writing `/assign @approver1 @approver2` in a comment when ready. 100 101 ∇ Details 102 Needs approval from an approver in each of these OWNERS Files: 103 * /A/B/E/OWNERS 104 * /A/B/G/OWNERS 105 106 You can indicate your approval by writing `/approve` in a comment 107 You can cancel your approval by writing `/approve cancel` in a comment 108 109 A selected approver such as *approver1* can be notified by typing `/assign @approver1` in a comment. 110 111 **Step 2:** 112 113 **Case (a)**: *approver1* is in the E OWNERS file. S/he writes `/approve` 114 115 K8s-bot updates comment: 116 117 [APPROVALNOTIFIER] This PR is **NOT APPROVED** 118 119 This pull-request has been approved by: *approver1, PRAuthor* 120 We suggest the following additional approver: **approver2** 121 122 If they are not already assigned, you can assign the PR to them by writing /assign @approver2 in a comment when ready. 123 124 ∇ Details 125 Needs approval from an approver in each of these OWNERS Files: 126 ~* /A/B/E/OWNERS~ [approver1] 127 * /A/B/G/OWNERS 128 129 You can indicate your approval by writing `/approve` in a comment 130 You can cancel your approval by writing `/approve cancel` in a comment 131 132 **Case (b)**: *approver3* is NOT an approver of the PR. S/he writes `/approve` 133 134 K8s-bot updates comment: 135 136 [APPROVALNOTIFIER] This PR is **NOT APPROVED** 137 138 This pull-request has been approved by:* approver3, PRAuthor* 139 We suggest the following additional approvers: **approver1,** **approver2** 140 141 If they are not already assigned, you can assign the PR to them by writing /assign @approver1 @approver2 in a comment when ready. 142 143 ∇ Details 144 Needs approval from an approver in each of these OWNERS Files: 145 * /A/B/E/OWNERS 146 * /A/B/G/OWNERS 147 148 You can indicate your approval by writing `/approve` in a comment 149 You can cancel your approval by writing `/approve cancel` in a comment 150 151 **Case (c)**: *approver1* is an approver of the PR. S/he writes `/lgtm` 152 153 K8s-bot updates comment: 154 155 [APPROVALNOTIFIER] This PR is **NOT APPROVED** 156 157 This pull-request has been approved by: *approver1, PRAuthor* 158 We suggest the following additional approver: **approver2** 159 160 If they are not already assigned, you can assign the PR to them by writing /assign @approver2 in a comment when ready. 161 162 ∇ Details 163 Needs approval from an approver in each of these OWNERS Files: 164 * ~/A/B/E/OWNERS~ [approver1] 165 * /A/B/G/OWNERS 166 167 You can indicate your approval by writing `/approve` in a comment 168 You can cancel your approval by writing `/approve cancel` in a comment 169 170 The **lgtm** label is immediately added to the PR. 171 172 **Step 3**: *approver2* writes `/approve` 173 174 K8s-bot updates comment: 175 176 [APPROVALNOTIFIER] This PR is** APPROVED** 177 178 The following people have approved this PR:* approver1**, **approver2, PRAuthor* 179 180 ∇ Details 181 Needs approval from an approver in each of these OWNERS Files: 182 * ~/A/B/E/OWNERS~ [approver1] 183 * ~/A/B/G/OWNERS~ [approver2] 184 185 You can indicate your approval by writing `/approve` in a comment 186 You can cancel your approval by writing `/approve cancel` in a comment 187 188 K8s-bot merges the PR. It needs to wait its turn in submit queue and passes tests. 189 190  191 192 **Final Notes** 193 194 Obtaining approvals from selected approvers is the last step towards merging a PR. The approvers approve a PR by typing `/approve` in a comment, or retract it by typing `/approve` cancel. 195 196 Algorithm for getting the status is as follow: 197 198 (1) run through all comments after newest commit to obtain latest intention of approvers 199 200 (2) put all approvers into an approver set 201 202 (3) determine whether a file has at least one approver in the approver set 203 204 (4) add the status to the PR if all files have been approved 205 206 If an approval is cancelled, the bot will delete the status added to the PR and remove the approver from the approver set. If someone who is not an approver in the OWNERS file types `/approve` in a comment, the PR will not be approved. If someone who is an approver in the OWNERS file and s/he does not get selected, s/he can still type `/approve` or `/lgtm` in a comment, pushing the PR forward. 207 208 **Code Implementation Links** 209 210 Blunderbuss: 211 [prow/plugins/blunderbuss/blunderbuss.go](https://git.k8s.io/test-infra/prow/plugins/blunderbuss/blunderbuss.go) 212 213 LGTM: 214 [prow/plugins/lgtm/lgtm.go](https://git.k8s.io/test-infra/prow/plugins/lgtm/lgtm.go) 215 216 Approve: 217 [prow/plugins/approve/approve.go](https://git.k8s.io/test-infra/prow/plugins/approve/approve.go) 218 219 [prow/plugins/approve/approvers/owners.go](https://git.k8s.io/test-infra/prow/plugins/approve/approvers/owners.go) 220