|
| 1 | +--- |
| 2 | +name: review_pr |
| 3 | +type: task |
| 4 | +version: 1.0.1 |
| 5 | +agent: CodeActAgent |
| 6 | +triggers: |
| 7 | + - review pr |
| 8 | + - review pull request |
| 9 | + - pr review |
| 10 | + - code review |
| 11 | +inputs: |
| 12 | + - name: PR_NUMBER |
| 13 | + description: 'The number of the pull request to review (e.g., 158)' |
| 14 | + required: true |
| 15 | +--- |
| 16 | + |
| 17 | +# PR Review Task |
| 18 | + |
| 19 | +This task guides you through reviewing pull requests in ${{ SELECTED_REPO }} according to project standards. |
| 20 | + |
| 21 | +## Finding file changes |
| 22 | +When reviewing file changes, instead of diffing with default branch such as `main` please diff against the base branch of the PR. |
| 23 | + |
| 24 | +## Review Steps and Guidelines for Each Step |
| 25 | + |
| 26 | +A high quality code review addresses 3 aspects: |
| 27 | + |
| 28 | +1. is it the appropriate problem (goal)? (Pass 1) |
| 29 | +2. is it the concise and optimal solution? (Pass 2) |
| 30 | +3. is it the high quality implementation? (Pass 3) |
| 31 | + |
| 32 | +For each pass, if needed, you will submit a PR-level comment and multiple line-level suggested changes via Github API. |
| 33 | + |
| 34 | +When everything is done, you will submit a Github pull request review to approve the PR via Github API. |
| 35 | + |
| 36 | +### **Review Pass 1: Is it the appropriate problem (goal)?**: |
| 37 | +- Review the PR description and linked issues, |
| 38 | +- Summarize the files changes and see if the PR description matches the changes |
| 39 | +- If the PR description is not aligned with the changes, ask the author to clarify the goal of the PR |
| 40 | +- If the PR description is aligned with the changes, proceed based on the understanding of the goal and the overall repository, |
| 41 | +comment on whether the goal is the right goal. The right goal of a PR should be |
| 42 | + - aligned with the overall repository goals, |
| 43 | + - not duplicating an existing functionality |
| 44 | + - should leverage the existing code and architecture unless it's intended for a upgrade/replacement/refactor |
| 45 | + - should not reinvent the wheel: suggest using popular open source libraries if they exist |
| 46 | + - should not over engineer: suggest using simple solutions if they exist |
| 47 | + - should not over generalize such as extracting a piece of code logic into a library / component when they are only being used in one place |
| 48 | + - should have proper sizing (not too big, not too small). |
| 49 | + |
| 50 | +Send *PR-level comment* to ask for clarification on the goal of the PR. ONLY proceed to next Review Pass if the goal is appropriate, otherwise wait for the author to respond. |
| 51 | + |
| 52 | +### **Review Pass 2: Is it the concise and optimal solution?**: |
| 53 | + - Understand whether the commit is a small change that fixes a bug or a larger change that implements a new feature/component or refactors code. |
| 54 | + - If it's a small change, skip architectural feedback, proceed to next step. |
| 55 | + - If it's a larger change, provide feedback on the architectural choices made. |
| 56 | + - Summarize the key goal and the solution to that key goal implemented in the PR |
| 57 | + - Check if the author provided documentations about major design decisions |
| 58 | + - Summarize the design decisions made by author |
| 59 | + - Check completenesss: suggest alternative approaches if applicable, and create a table to compare the pros and cons of each approach |
| 60 | + |
| 61 | +Send *PR-level comment* to ask for clarification on the solution of the PR. ONLY proceed to next Review Pass if the solution is concise and optimal, otherwise wait for the author to respond. |
| 62 | + |
| 63 | +### **Review Pass 3: Is it the high quality implementation?**: |
| 64 | +- Verify changes follow `.coderabbit.yaml` rules |
| 65 | +- Suggest the right implementation if the current implementation is not the right one |
| 66 | +- Suggest improvements to the code structure, naming conventions, and documentation |
| 67 | +- Check for proper error handling |
| 68 | +- Ensure consistent formatting |
| 69 | +- Check completeness: suggest other part of the code that needs to be updated to complete the implementation. |
| 70 | + |
| 71 | +- **Documentation**: |
| 72 | + - Verify README/docstring updates |
| 73 | + - Check for new configuration needs |
| 74 | + |
| 75 | +- **Testing**: |
| 76 | + - Confirm adequate test coverage |
| 77 | + - If unit tests should be added, suggest the right tests to add |
| 78 | + - Verify tests pass |
| 79 | + |
| 80 | +Send *line-level suggested change* to ask for fixing the implementation of the PR. ONLY proceed to next Review Pass if the implementation is high quality, otherwise wait for the author to respond. |
| 81 | + |
| 82 | +## Using Github API |
| 83 | + |
| 84 | +Please note: use markdown in the comment or reply for better readability if it's more than a plain text. |
| 85 | + |
| 86 | +### This is how you send *PR-level comment* with Github API |
| 87 | + |
| 88 | +```bash |
| 89 | +curl -L \ |
| 90 | + -X POST \ |
| 91 | + -H "Accept: application/vnd.github+json" \ |
| 92 | + -H "Authorization: Bearer <YOUR-TOKEN>" \ |
| 93 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 94 | + https://api.github.com/repos/OWNER/REPO/pulls/PULL_NUMBER/comments \ |
| 95 | +-d '{ "body": "[COMMENT]", "commit_id": "'$(git rev-parse HEAD)'", "path": "[FILE_PATH]", "start_line": [START_LINE_NUMBER],"start_side":"[START_SIDE]","line": [LINE_NUMBER],"side":"[SIDE]"}' |
| 96 | +``` |
| 97 | + |
| 98 | +Note: even for PR-level comment, you still need to provide the `commit_id`, `path`, and `line` to specify the comment location so that the comment will be shown in the PR page in the most relevant location. |
| 99 | + |
| 100 | +### This is how you send a *line-level suggested change* with github API |
| 101 | + |
| 102 | +```bash |
| 103 | +curl -L \ |
| 104 | + -X POST \ |
| 105 | + -H "Accept: application/vnd.github+json" \ |
| 106 | + -H "Authorization: Bearer <YOUR-TOKEN>" \ |
| 107 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 108 | + https://api.github.com/repos/OWNER/REPO/pulls/PULL_NUMBER/comments \ |
| 109 | +-d '{ "body": "suggestion\n[SUGGESTED_CODE_WITH_ESCAPED_NEWLINES]\n", "commit_id": "'$(git rev-parse HEAD)'", "path": "[FILE_PATH]", "start_line": [START_LINE_NUMBER],"start_side":"[START_SIDE]","line": [LINE_NUMBER],"side":"[SIDE]"}' |
| 110 | +``` |
| 111 | + |
| 112 | +### This is how you make a reply to a review comment |
| 113 | + |
| 114 | +```bash |
| 115 | +curl -L \ |
| 116 | + -X POST \ |
| 117 | + -H "Accept: application/vnd.github+json" \ |
| 118 | + -H "Authorization: Bearer <YOUR-TOKEN>" \ |
| 119 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 120 | + https://api.github.com/repos/OWNER/REPO/pulls/PULL_NUMBER/comments/COMMENT_ID/replies \ |
| 121 | + -d '{"body":"[REPLY]"}' |
| 122 | +``` |
| 123 | + |
| 124 | +### This is how you request changes to a PR |
| 125 | + |
| 126 | +```bash |
| 127 | +# Example, use your own data |
| 128 | +curl -L \ |
| 129 | + -X POST \ |
| 130 | + -H "Accept: application/vnd.github+json" \ |
| 131 | + -H "Authorization: Bearer <YOUR-TOKEN>" \ |
| 132 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 133 | + https://api.github.com/repos/OWNER/REPO/pulls/PULL_NUMBER/reviews \ |
| 134 | + -d '{"commit_id":"ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091","body":"This is close to perfect! Please address the suggested inline change.","event":"REQUEST_CHANGES","comments":[{"path":"file.md","position":6,"body":"Please add more information here, and fix this typo."}]}' |
| 135 | +``` |
| 136 | + |
| 137 | +### This is how you approve a PR |
| 138 | + |
| 139 | +```bash |
| 140 | +# Example, use your own data |
| 141 | +curl -L \ |
| 142 | + -X POST \ |
| 143 | + -H "Accept: application/vnd.github+json" \ |
| 144 | + -H "Authorization: Bearer <YOUR-TOKEN>" \ |
| 145 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 146 | + https://api.github.com/repos/OWNER/REPO/pulls/PULL_NUMBER/reviews \ |
| 147 | + -d '{"commit_id":"ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091","body":"Great stuff!","event":"APPROVE","comments":[...]}' |
| 148 | +``` |
| 149 | + |
| 150 | +## Reference Documents |
| 151 | +- `./coderabbit.yaml` for review standards |
| 152 | +- [Github API: Create a review comment](https://docs.github.com/en/rest/pulls/comments?apiVersion=2022-11-28#create-a-review-comment) |
| 153 | +- [Github API: Create a reply for a review comment](https://docs.github.com/en/rest/pulls/comments?apiVersion=2022-11-28#create-a-reply-for-a-review-comment) |
| 154 | +- [Create a review](https://docs.github.com/en/rest/pulls/reviews?apiVersion=2022-11-28#create-a-review) |
0 commit comments