Skip to content

Commit 4e2cfdf

Browse files
authored
Enhance PR review workflow with line-specific comments and reaction indicators (#1958)
# READ CAREFULLY THEN REMOVE Remove bullet points that are not relevant. PLEASE REFRAIN FROM USING AI TO WRITE YOUR CODE AND PR DESCRIPTION. IF YOU DO USE AI TO WRITE YOUR CODE PLEASE PROVIDE A DESCRIPTION AND REVIEW IT CAREFULLY. MAKE SURE YOU UNDERSTAND THE CODE YOU ARE SUBMITTING USING AI. - Pull requests that do not follow these guidelines will be closed without review or comment. - If you use AI to write your PR description your pr will be close without review or comment. - If you are unsure about anything, feel free to ask for clarification. ## Description Please provide a clear description of your changes. --- ## Type of Change Please delete options that are not relevant. - [ ] 🐛 Bug fix (non-breaking change which fixes an issue) - [ ] ✨ New feature (non-breaking change which adds functionality) - [ ] 💥 Breaking change (fix or feature with breaking changes) - [ ] 📝 Documentation update - [ ] 🎨 UI/UX improvement - [ ] 🔒 Security enhancement - [ ] ⚡ Performance improvement ## Areas Affected Please check all that apply: - [ ] Email Integration (Gmail, IMAP, etc.) - [ ] User Interface/Experience - [ ] Authentication/Authorization - [ ] Data Storage/Management - [ ] API Endpoints - [ ] Documentation - [ ] Testing Infrastructure - [ ] Development Workflow - [ ] Deployment/Infrastructure ## Testing Done Describe the tests you've done: - [ ] Unit tests added/updated - [ ] Integration tests added/updated - [ ] Manual testing performed - [ ] Cross-browser testing (if UI changes) - [ ] Mobile responsiveness verified (if UI changes) ## Security Considerations For changes involving data or authentication: - [ ] No sensitive data is exposed - [ ] Authentication checks are in place - [ ] Input validation is implemented - [ ] Rate limiting is considered (if applicable) ## Checklist - [ ] I have read the [CONTRIBUTING](https://github.com/Mail-0/Zero/blob/staging/.github/CONTRIBUTING.md) document - [ ] My code follows the project's style guidelines - [ ] I have performed a self-review of my code - [ ] I have commented my code, particularly in complex areas - [ ] I have updated the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix/feature works - [ ] All tests pass locally - [ ] Any dependent changes are merged and published ## Additional Notes Add any other context about the pull request here. ## Screenshots/Recordings Add screenshots or recordings here if applicable. --- _By submitting this pull request, I confirm that my contribution is made under the terms of the project's license._ <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Improved the PR review workflow by adding line-specific comments and reaction indicators to make feedback clearer and easier to track. - **New Features** - Added support for posting review comments on exact lines in changed files. - Added 👀 and ✅ reactions to show when review starts and completes. <!-- End of auto-generated description by cubic. -->
1 parent 2400243 commit 4e2cfdf

File tree

2 files changed

+136
-37
lines changed

2 files changed

+136
-37
lines changed

.github/workflows/ampcode-pr-review.yml

Lines changed: 129 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
matrix:
2424
review-chunk: [1]
2525
max-parallel: 3
26-
26+
2727
steps:
2828
- name: Checkout PR branch
2929
uses: actions/checkout@v4
@@ -57,28 +57,43 @@ jobs:
5757
echo "EOF" >> $GITHUB_OUTPUT
5858
echo "Changed files count: $(echo "$CHANGED_FILES" | wc -l)"
5959
60+
- name: Add Review Started Reaction
61+
if: steps.changed-files.outputs.changed_files != ''
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
run: |
65+
# Add a reaction to indicate review has started
66+
curl -X POST \
67+
-H "Authorization: token $GITHUB_TOKEN" \
68+
-H "Accept: application/vnd.github.v3+json" \
69+
-H "Content-Type: application/json" \
70+
-d '{"content":"eyes"}' \
71+
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/reactions"
72+
73+
echo "Added 👀 reaction to indicate review has started"
74+
6075
- name: Run Ampcode Review
6176
if: steps.changed-files.outputs.changed_files != ''
6277
env:
6378
AMP_API_KEY: ${{ secrets.AMPCODE_API_KEY }}
6479
run: |
6580
echo "Running ampcode review on changed files..."
66-
81+
6782
# Create a temporary file with the changed files list
6883
echo "${{ steps.changed-files.outputs.changed_files }}" > changed_files.txt
69-
70-
# Run ampcode review on the changed files
71-
REVIEW_OUTPUT=$(amp -x "Review the following files for code quality, potential bugs, security issues, performance concerns, and best practices. Focus on providing specific, actionable feedback with line numbers when possible. Files to review: $(cat changed_files.txt | tr '\n' ' ')" 2>&1 || echo "Ampcode review failed")
72-
84+
85+
# Run ampcode review on the changed files with specific instructions for line-level feedback
86+
REVIEW_OUTPUT=$(amp -x "Review the following files for code quality, potential bugs, security issues, performance concerns, and best practices. For each issue found, provide the specific file path and line number where the issue occurs. Format your response as: FILE:line_number:issue_description. Focus on providing specific, actionable feedback with exact line numbers. Files to review: $(cat changed_files.txt | tr '\n' ' ')" 2>&1 || echo "Ampcode review failed")
87+
7388
# Save review output to file
7489
echo "$REVIEW_OUTPUT" > ampcode_review.txt
75-
90+
7691
# Display review output for debugging
7792
echo "=== Ampcode Review Output ==="
7893
cat ampcode_review.txt
7994
echo "=== End Review Output ==="
8095
81-
- name: Parse and Post Review Comments
96+
- name: Parse and Post Line-Specific Comments
8297
if: steps.changed-files.outputs.changed_files != ''
8398
env:
8499
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -88,39 +103,123 @@ jobs:
88103
echo "No review output found or file is empty"
89104
exit 0
90105
fi
91-
106+
92107
# Read the review output
93108
REVIEW_CONTENT=$(cat ampcode_review.txt)
94-
95-
# Create a comprehensive PR review comment using proper JSON escaping
96-
# Use jq to properly escape the review content for JSON
97-
ESCAPED_CONTENT=$(echo "$REVIEW_CONTENT" | jq -Rs .)
98-
99-
# Create the JSON payload with proper escaping
100-
jq -n \
101-
--arg content "$REVIEW_CONTENT" \
102-
--arg run_id "${{ github.run_id }}" \
103-
--arg repo "${{ github.repository }}" \
104-
'{
105-
"body": ("## 🤖 Automated Code Review by Ampcode\n\n**Review Summary:**\n\nI'\''ve analyzed the changes in this PR using AI-powered code review. Here are my findings:\n\n### 📋 Review Results\n\n```\n" + $content + "\n```\n\n### 🔍 Key Areas Reviewed\n- Code quality and best practices\n- Potential bugs and security issues\n- Performance considerations\n- Maintainability and readability\n\n### 📝 Notes\n- This is an automated review generated by Ampcode AI\n- Please review the suggestions and apply them as appropriate\n- For questions about specific recommendations, feel free to ask!\n\n---\n*Generated by [Ampcode](https://ampcode.com) • [View Workflow](https://github.com/" + $repo + "/actions/runs/" + $run_id + ")*"),
106-
"event": "COMMENT"
107-
}' > review_comment.json
108-
109-
# Post the review comment
109+
110+
# Parse the review content for line-specific comments
111+
# Look for patterns like "file.ts:123:issue description"
112+
echo "$REVIEW_CONTENT" | grep -E '^[^:]+:[0-9]+:' > line_comments.txt || true
113+
114+
# If no line-specific comments found, create a general comment
115+
if [ ! -s line_comments.txt ]; then
116+
echo "No line-specific comments found, creating general review comment"
117+
118+
# Create a general PR review comment
119+
jq -n \
120+
--arg content "$REVIEW_CONTENT" \
121+
--arg run_id "${{ github.run_id }}" \
122+
--arg repo "${{ github.repository }}" \
123+
'{
124+
"body": ("## 🤖 Automated Code Review by Ampcode\n\n**Review Summary:**\n\nI'\''ve analyzed the changes in this PR using AI-powered code review. Here are my findings:\n\n### 📋 Review Results\n\n```\n" + $content + "\n```\n\n### 🔍 Key Areas Reviewed\n- Code quality and best practices\n- Potential bugs and security issues\n- Performance considerations\n- Maintainability and readability\n\n### 📝 Notes\n- This is an automated review generated by Ampcode AI\n- Please review the suggestions and apply them as appropriate\n- For questions about specific recommendations, feel free to ask!\n\n---\n*Generated by [Ampcode](https://ampcode.com) • [View Workflow](https://github.com/" + $repo + "/actions/runs/" + $run_id + ")*"),
125+
"event": "COMMENT"
126+
}' > review_comment.json
127+
128+
# Post the general review comment
129+
curl -X POST \
130+
-H "Authorization: token $GITHUB_TOKEN" \
131+
-H "Accept: application/vnd.github.v3+json" \
132+
-H "Content-Type: application/json" \
133+
-d @review_comment.json \
134+
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews"
135+
136+
echo "General review comment posted successfully"
137+
exit 0
138+
fi
139+
140+
# Process line-specific comments
141+
echo "Processing line-specific comments..."
142+
143+
# Initialize arrays for the review
144+
declare -a comments=()
145+
comment_count=0
146+
147+
# Read line comments and create GitHub review comments
148+
while IFS= read -r line; do
149+
# Parse the line: file:line:comment
150+
file_path=$(echo "$line" | cut -d: -f1)
151+
line_number=$(echo "$line" | cut -d: -f2)
152+
comment_text=$(echo "$line" | cut -d: -f3-)
153+
154+
# Skip if file doesn't exist or line number is invalid
155+
if [ ! -f "$file_path" ] || ! [[ "$line_number" =~ ^[0-9]+$ ]]; then
156+
echo "Skipping invalid comment: $line"
157+
continue
158+
fi
159+
160+
# Create the comment object
161+
comment_obj=$(jq -n \
162+
--arg path "$file_path" \
163+
--arg line "$line_number" \
164+
--arg body "🤖 **Ampcode Review:** $comment_text" \
165+
'{
166+
"path": $path,
167+
"line": ($line | tonumber),
168+
"body": $body
169+
}')
170+
171+
comments+=("$comment_obj")
172+
comment_count=$((comment_count + 1))
173+
174+
echo "Added comment for $file_path:$line_number"
175+
done < line_comments.txt
176+
177+
# If we have comments, create the review
178+
if [ $comment_count -gt 0 ]; then
179+
# Create the review payload
180+
jq -n \
181+
--arg body "## 🤖 Automated Code Review by Ampcode\n\nI've reviewed the changes and found $comment_count issue(s) that need attention. Please review the inline comments below.\n\n---\n*Generated by [Ampcode](https://ampcode.com) • [View Workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})*" \
182+
--arg event "REQUEST_CHANGES" \
183+
--argjson comments "$(printf '%s\n' "${comments[@]}" | jq -s .)" \
184+
'{
185+
"body": $body,
186+
"event": $event,
187+
"comments": $comments
188+
}' > review_payload.json
189+
190+
# Post the review with line-specific comments
191+
curl -X POST \
192+
-H "Authorization: token $GITHUB_TOKEN" \
193+
-H "Accept: application/vnd.github.v3+json" \
194+
-H "Content-Type: application/json" \
195+
-d @review_payload.json \
196+
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews"
197+
198+
echo "Posted review with $comment_count line-specific comments"
199+
else
200+
echo "No valid line-specific comments to post"
201+
fi
202+
203+
- name: Add Review Completed Reaction
204+
if: always() && steps.changed-files.outputs.changed_files != ''
205+
env:
206+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
207+
run: |
208+
# Add a reaction to indicate review has completed
110209
curl -X POST \
111210
-H "Authorization: token $GITHUB_TOKEN" \
112211
-H "Accept: application/vnd.github.v3+json" \
113212
-H "Content-Type: application/json" \
114-
-d @review_comment.json \
115-
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/reviews"
116-
117-
echo "Review comment posted successfully"
213+
-d '{"content":"white_check_mark"}' \
214+
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/reactions"
215+
216+
echo "Added ✅ reaction to indicate review has completed"
118217
119218
- name: Cleanup
120219
if: always()
121220
run: |
122221
# Clean up temporary files
123-
rm -f changed_files.txt ampcode_review.txt review_comment.json
222+
rm -f changed_files.txt ampcode_review.txt review_comment.json review_payload.json line_comments.txt
124223
echo "Cleanup completed"
125224
126225
- name: Summary

.github/workflows/close-stale-issues.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Close Stale Issues
22

33
on:
44
schedule:
5-
- cron: "0 0 * * *"
5+
- cron: '0 0 * * *'
66

77
jobs:
88
stale:
@@ -13,9 +13,9 @@ jobs:
1313
steps:
1414
- uses: actions/stale@v9
1515
with:
16-
days-before-stale: 3
17-
days-before-close: 0
18-
only-issues: true
19-
stale-issue-label: "stale"
20-
stale-issue-message: "This issue is stale (3+ days) and will be closed."
21-
close-issue-message: "Closing stale issue."
16+
days-before-issue-stale: 3
17+
days-before-issue-close: 0
18+
days-before-pr-stale: -1
19+
stale-issue-label: 'stale'
20+
stale-issue-message: 'This issue is stale (3+ days) and will be closed.'
21+
close-issue-message: 'Closing stale issue.'

0 commit comments

Comments
 (0)