|
| 1 | +# PR Review |
| 2 | + |
| 3 | +## Tools |
| 4 | + |
| 5 | +A better way to do a code-review of a PR is to do it in your IDE. |
| 6 | +Here are two scripts which allow you to perform the review and create local changes which can be appended to the PR. |
| 7 | + |
| 8 | +### 1. Loading PR |
| 9 | + |
| 10 | +Run this command to load the changes into your local repository where your IDE is running. |
| 11 | + |
| 12 | +``` |
| 13 | +$ ./scripts/github/review-pr 24623 |
| 14 | +``` |
| 15 | + |
| 16 | +This will result in output: |
| 17 | + |
| 18 | +``` |
| 19 | +Already on 'master' |
| 20 | +Your branch is up to date with 'origin/master'. |
| 21 | +Fetching pull request #24623 with 1 SHA(s) into branch range: pr/24623_base..pr/24623_top |
| 22 | +====================================================================================== |
| 23 | +cef93a51b (pr/24623_top) ci: scripts to review PRs locally |
| 24 | +====================================================================================== |
| 25 | +Switched to a new branch 'pr/24623' |
| 26 | +On branch pr/24623 |
| 27 | +Untracked files: |
| 28 | + (use "git add <file>..." to include in what will be committed) |
| 29 | +
|
| 30 | + docs/PR_REVIEW.md |
| 31 | + scripts/github/push-pr |
| 32 | + scripts/github/review-pr |
| 33 | +
|
| 34 | +nothing added to commit but untracked files present (use "git add" to track) |
| 35 | +``` |
| 36 | + |
| 37 | +Note that the script created `pr/24623_top` and `pr/24623_base` branches which denote SHAs where the PR start and end. |
| 38 | + |
| 39 | +``` |
| 40 | +cef93a51b (pr/24623_top) ci: scripts to review PRs locally |
| 41 | +637805a0c (pr/24623_base) docs: update `lowercase` pipe example in "AngularJS to Angular" guide (#24588) |
| 42 | +``` |
| 43 | + |
| 44 | +Knowing `pr/24623_top` and `pr/24623_base` makes it convenient to refer to different SHAs in PR when rebasing or reseting. |
| 45 | + |
| 46 | +### 2. Review PR |
| 47 | + |
| 48 | +Because the script has reset the `HEAD` of the PR the changes show up as unstaged files. |
| 49 | + |
| 50 | +``` |
| 51 | +$ git status |
| 52 | +On branch pr/24623 |
| 53 | +Untracked files: |
| 54 | + (use "git add <file>..." to include in what will be committed) |
| 55 | +
|
| 56 | + docs/PR_REVIEW.md |
| 57 | + scripts/github/push-pr |
| 58 | + scripts/github/review-pr |
| 59 | +
|
| 60 | +nothing added to commit but untracked files present (use "git add" to track) |
| 61 | +``` |
| 62 | + |
| 63 | +Use your IDE to review the untracked files as needed. |
| 64 | +A good trick is to use your IDE to stage the files which were already reviewed. |
| 65 | +When all files are staged the review is done. |
| 66 | + |
| 67 | +### 3. Creating Edits |
| 68 | + |
| 69 | +At any point you can edit any line in the repository. |
| 70 | +The idea is to create edits locally and push them to the PR later. |
| 71 | +This is useful because it is often times easier to make minor changes locally than to request the PR author to change and repush through a comment (often times the comment is larger than the change.) |
| 72 | + |
| 73 | +Example of a local edit. |
| 74 | +``` |
| 75 | +echo "# here is a change" >> docs/PR_REVIEW.md |
| 76 | +``` |
| 77 | + |
| 78 | +### 4. Creating a Commit From Local Edits |
| 79 | + |
| 80 | +Since the HEAD has been reset to `pr/24623_base` so that changes show up in `git status` we have to reverse the reset to only see our local changes. |
| 81 | +To do that reset the `HEAD` to `pr/24623_top`. |
| 82 | + |
| 83 | +``` |
| 84 | +$ git reset pr/24623_top |
| 85 | +``` |
| 86 | + |
| 87 | +Doing so will remove all PR changes and only leave your local modifications which you have done. |
| 88 | +You can verify by running `git status` and `git diff` to see only your changes (PR changes have been removed.) |
| 89 | + |
| 90 | +``` |
| 91 | +$ git status |
| 92 | +On branch pr/24623 |
| 93 | +Changes not staged for commit: |
| 94 | + (use "git add <file>..." to update what will be committed) |
| 95 | + (use "git checkout -- <file>..." to discard changes in working directory) |
| 96 | +
|
| 97 | + modified: docs/PR_REVIEW.md |
| 98 | +
|
| 99 | +no changes added to commit (use "git add" and/or "git commit -a") |
| 100 | +``` |
| 101 | +``` |
| 102 | +$ git diff |
| 103 | +diff --git a/docs/PR_REVIEW.md b/docs/PR_REVIEW.md |
| 104 | +index 184b5aeca..83517fbe0 100644 |
| 105 | +--- a/docs/PR_REVIEW.md |
| 106 | ++++ b/docs/PR_REVIEW.md |
| 107 | +@@ -8,4 +8,4 @@ A better way to do code review of the PR is to do it in your IDE. Here are two s |
| 108 | +existing text |
| 109 | +- |
| 110 | +\ No newline at end of file |
| 111 | ++# here is a change |
| 112 | +``` |
| 113 | + |
| 114 | +Next step is to turn your local changes into a `fixup!` commit. |
| 115 | +Run `git commit --all --fixup HEAD` to create a `fixup!` commit. |
| 116 | + |
| 117 | +NOTE: If you added new files they must be added using `git add .` or they will not be picked up by the `git commit --all` flag. |
| 118 | + |
| 119 | +``` |
| 120 | +$ git commit --all --fixup HEAD |
| 121 | +[pr/24623 45ae87ce4] fixup! ci: scripts to review PRs locally |
| 122 | + 1 file changed, 1 insertion(+), 1 deletion(-) |
| 123 | +``` |
| 124 | + |
| 125 | +You can verify that the `fixup!` commit with your local modifications was created. |
| 126 | +``` |
| 127 | +$ git log --oneline |
| 128 | +45ae87ce4 (HEAD -> pr/24623) fixup! ci: scripts to review PRs locally |
| 129 | +cef93a51b (pr/24623_top) ci: scripts to review PRs locally |
| 130 | +``` |
| 131 | + |
| 132 | +### 5. Pushing local edits back to the PR |
| 133 | + |
| 134 | +The last step is to push your local changes back into the PR. |
| 135 | +Use `./scripts/github/push-pr` script for that. |
| 136 | + |
| 137 | +``` |
| 138 | +$ ./scripts/github/push-pr |
| 139 | +Assuming PR #24623 |
| 140 | +>>> git push [email protected]:mhevery/angular.git HEAD:review_pr_script |
| 141 | +Counting objects: 4, done. |
| 142 | +Delta compression using up to 8 threads. |
| 143 | +Compressing objects: 100% (4/4), done. |
| 144 | +Writing objects: 100% (4/4), 392 bytes | 392.00 KiB/s, done. |
| 145 | +Total 4 (delta 3), reused 0 (delta 0) |
| 146 | +remote: Resolving deltas: 100% (3/3), completed with 3 local objects. |
| 147 | +To github.com:mhevery/angular.git |
| 148 | + cef93a51b..45ae87ce4 HEAD -> review_pr_script |
| 149 | +``` |
| 150 | + |
| 151 | +NOTE: Notice that we did not have to specify the PR number since the script can guess it from the branch name. |
| 152 | + |
| 153 | +If you visit https://github.com/angular/angular/pull/24623/commits you will see that your `fixup!` commit has been added to the PR. |
| 154 | +This greatly simplifies the work for many minor changes to the PR. |
| 155 | + |
0 commit comments