-
Notifications
You must be signed in to change notification settings - Fork 311
fix(utils): batch push and add preview mode to address-reviews #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c2b9a9e
d96fb8c
c6bd367
6b69774
6ae6242
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| --- | ||
| description: Fetch and address all PR review comments | ||
| argument-hint: "[PR number (optional - uses current branch if omitted)]" | ||
| argument-hint: "[PR number (optional - uses current branch if omitted)] [--preview]" | ||
| --- | ||
|
|
||
| ## Name | ||
| utils:address-reviews | ||
|
|
||
| ## Synopsis | ||
| /utils:address-reviews [PR number (optional - uses current branch if omitted)] | ||
| /utils:address-reviews [PR number (optional - uses current branch if omitted)] [--preview] | ||
|
|
||
| ## Description | ||
| This command automates the process of addressing PR review comments by fetching all comments from a pull request, categorizing them by priority (blocking, change requests, questions, suggestions), and systematically addressing each one. It intelligently filters out outdated comments, bot-generated content, and oversized responses to optimize context usage. The command handles code changes, posts replies to reviewers, and maintains a clean git history by amending relevant commits rather than creating unnecessary new ones. | ||
|
|
@@ -109,11 +109,25 @@ This command automates the process of addressing PR review comments by fetching | |
|
|
||
| ### Step 3: Address Comments | ||
|
|
||
| #### Interactive Preview (`--preview`) | ||
|
|
||
| When `--preview` is passed, preview each comment before acting: | ||
|
|
||
| 1. Show the reviewer's comment | ||
| 2. Show your proposed action: code change diff, explanation, or decline reasoning | ||
| 3. Show the draft reply you plan to post | ||
| 4. **Wait for user approval** before proceeding — the user can: | ||
| - **Approve** as-is | ||
| - **Edit** the proposed reply or approach | ||
| - **Skip** the comment entirely | ||
|
|
||
| This applies to all comment types below. Without `--preview`, act autonomously. | ||
|
|
||
| #### Grouped Comments | ||
|
|
||
| When multiple comments relate to the same concern/fix: | ||
| - Make the code change once | ||
| - Reply to EACH comment individually (don't copy-paste, tailor each reply) | ||
| - Track replies for EACH comment individually (posted in Step 4 — don't copy-paste, tailor each reply) | ||
| - Optional reference: `Done. (Also addresses feedback from @user)` | ||
|
|
||
| #### Code Change Requests | ||
|
|
@@ -122,7 +136,7 @@ When multiple comments relate to the same concern/fix: | |
|
|
||
| **b. If requested change is valid**: | ||
| - Plan and implement changes | ||
| - Commit and Push **(ALL sub-steps are MANDATORY — do not skip any)** | ||
| - Commit locally **(do NOT push yet — all pushes are batched in Step 4)** | ||
| 1. **Review changes**: `git diff` | ||
|
|
||
| 2. **Sync with remote first**: `git pull --rebase origin <branch>` to ensure local branch is up to date. If the branch is behind or diverged, you MUST rebase before committing. | ||
|
|
@@ -139,48 +153,66 @@ When multiple comments relate to the same concern/fix: | |
| - **When unsure**: Amend (keep git history clean) | ||
| - **Multiple commits**: Use `git rebase -i origin/main` to amend the specific relevant commit | ||
|
|
||
| 5. **Create commit AND push (both required)**: | ||
| 5. **Create commit locally**: | ||
| - Follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) format | ||
| - Always include body explaining "why" | ||
| - **Amend**: `git commit --amend --no-edit && git push --force-with-lease` (or update message if scope changed) | ||
| - **New commit**: Standard commit with message, then `git push` | ||
| - **⚠️ A commit without a push is incomplete. You MUST push.** | ||
| - **Amend**: `git commit --amend --no-edit` (or update message if scope changed) | ||
| - **New commit**: Standard commit with message | ||
|
|
||
| 6. **Verify push succeeded (MANDATORY before replying)**: | ||
| - Run `git log -1 --format='%H'` locally and `git ls-remote origin <branch>` to confirm the remote has your commit | ||
| - **If they differ**: The push failed or was never executed. Do NOT post a "Done" reply. Diagnose and retry, or report the failure to the user. | ||
| - **If uncommitted changes remain** (`git status`): The commit failed. Fix it first. | ||
| - **⚠️ NEVER post a "Done" or "Fixed" reply unless the push is verified on the remote.** Posting false claims of completion erodes reviewer trust and wastes human reviewers' time. | ||
|
|
||
| - **Concise Reply template**: `Done. [1-line what changed]. [Optional 1-line why]` | ||
| - Max 2 sentences + attribution footer | ||
| - Post reply: | ||
| ``` | ||
| gh api repos/{owner}/{repo}/pulls/<PR_NUMBER>/comments/<comment_id>/replies -f body="<reply>" | ||
| ``` | ||
| If fails: `gh pr comment <PR_NUMBER> --body="@<author> <reply>"` | ||
| - Track what was done for each comment (change description, comment ID, author) so replies can be posted in Step 4 | ||
|
|
||
| **c. If declining change**: | ||
| - **Reply with technical explanation** (3-5 sentences): | ||
| - **Prepare technical explanation** (3-5 sentences): | ||
| - Why current implementation is correct | ||
| - Specific reasoning with file:line references | ||
| - Use same posting method as (b) | ||
| - Track for reply in Step 4 | ||
|
|
||
| **d. If unsure**: Ask user for clarification | ||
|
|
||
| #### Clarification Requests | ||
|
|
||
| - Provide clear, detailed answer (2-4 sentences) | ||
| - Prepare clear, detailed answer (2-4 sentences) | ||
| - Include file:line references when applicable | ||
| - Post using same method as code changes | ||
| - Track for reply in Step 4 | ||
|
|
||
| #### Informational Comments | ||
|
|
||
| - No action unless response is courteous | ||
|
|
||
| ### Step 4: Post Replies and Push | ||
|
|
||
| After ALL comments from Step 3 are processed, post replies and push in this order: | ||
|
|
||
| #### 4a. Post all replies | ||
|
|
||
| For each comment addressed in Step 3, post the reply: | ||
|
|
||
| - **Concise Reply template**: `Done. [1-line what changed]. [Optional 1-line why]` | ||
| - Max 2 sentences + attribution footer | ||
| - Post reply: | ||
| ``` | ||
| gh api repos/{owner}/{repo}/pulls/<PR_NUMBER>/comments/<comment_id>/replies -f body="<reply>" | ||
| ``` | ||
| If fails: `gh pr comment <PR_NUMBER> --body="@<author> <reply>"` | ||
|
|
||
|
Comment on lines
+194
to
+197
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, locate and read the file
find . -name "address-reviews.md" -type f 2>/dev/null | head -5Repository: openshift-eng/ai-helpers Length of output: 111 🏁 Script executed: # Read the file around lines 194-197 to see context
wc -l ./plugins/utils/commands/address-reviews.mdRepository: openshift-eng/ai-helpers Length of output: 115 🏁 Script executed: # Read lines around 194-197 with context
sed -n '185,210p' ./plugins/utils/commands/address-reviews.md | cat -nRepository: openshift-eng/ai-helpers Length of output: 999 🌐 Web query:
💡 Result: For pull request review comments (inline diff comments), GitHub’s REST API supports creating replies via:
There is no separate “list replies” REST endpoint; to fetch replies you typically:
Source
🌐 Web query:
💡 Result: PR “feedback channels” in GitHub APIs (and how they map)
Sources[1] (docs.github.com) Citations:
🏁 Script executed: # Search for the "one response mechanism" rule or similar constraints in the file
rg -i "one response|mechanism|feedback type|channel" ./plugins/utils/commands/address-reviews.md -A 2 -B 2Repository: openshift-eng/ai-helpers Length of output: 616 🏁 Script executed: # Read Step 3 to understand what types of feedback are extracted
sed -n '1,193p' ./plugins/utils/commands/address-reviews.md | tail -60 | cat -nRepository: openshift-eng/ai-helpers Length of output: 2806 🏁 Script executed: # Find Step 3 content
sed -n '1,150p' ./plugins/utils/commands/address-reviews.md | grep -n "Step 3" -A 40 | head -50Repository: openshift-eng/ai-helpers Length of output: 1793 🏁 Script executed: # Read the full Step 3 section
sed -n '110,180p' ./plugins/utils/commands/address-reviews.md | cat -nRepository: openshift-eng/ai-helpers Length of output: 3376 🌐 Web query:
💡 Result: REST API (v3): distinguish by the resource type / fields1) Pull request review comment (inline diff comment) =
2) Issue comment (works for both Issues and PR “conversation” comments) =
3) If it’s an
GraphQL API (v4): use
|
||
| **All replies must include**: `---\n*AI-assisted response via Claude Code*` | ||
|
|
||
| ### Step 4: Summary | ||
| #### 4b. Push once | ||
|
|
||
| After all replies are posted, push all committed changes in a single push: | ||
|
|
||
| ```bash | ||
| git push --force-with-lease | ||
| ``` | ||
|
|
||
| #### 4c. Verify push | ||
|
|
||
| - Run `git log -1 --format='%H'` locally and `git ls-remote origin <branch>` to confirm the remote has your commit | ||
| - **If they differ**: The push failed or was never executed. Diagnose and retry. | ||
| - **If uncommitted changes remain** (`git status`): The commit failed. Fix it before pushing. | ||
| - **If push cannot be verified**: Report the failure to the user. Do not silently proceed — replies have already been posted claiming changes were made. | ||
|
|
||
| ### Step 5: Summary | ||
|
|
||
| Show user: | ||
| - Total comments found (raw count from API) | ||
|
|
@@ -229,4 +261,5 @@ Where `<type>` is one of: `issue_comment`, `review_thread`, or `review_comment` | |
|
|
||
|
|
||
| ## Arguments: | ||
| - $1: [PR number to address reviews (optional - uses current branch if omitted)] | ||
| - $1: [PR number (optional - uses current branch if omitted)] | ||
| - --preview: Preview each comment's proposed action and reply before proceeding | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a language tag to the fenced code block.
This triggers markdownlint MD040 (
fenced-code-language).📝 Proposed fix
🧰 Tools
🪛 markdownlint-cli2 (0.22.0)
[warning] 193-193: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents