Skip to content

Refactor Claude "update pull request" command#776

Merged
forstmeier merged 3 commits intomasterfrom
refactor-update-pull-request-claude-command
Mar 2, 2026
Merged

Refactor Claude "update pull request" command#776
forstmeier merged 3 commits intomasterfrom
refactor-update-pull-request-claude-command

Conversation

@forstmeier
Copy link
Copy Markdown
Collaborator

@forstmeier forstmeier commented Mar 2, 2026

Overview

Changes

  • refactor/cleanup command logic

Context

I realize that this is a tool that basically I only use so it could probably be moved into my personal Claude settings but I can do that later.

Summary by CodeRabbit

  • Documentation
    • Reorganized and clarified PR workflow with renamed steps (e.g., “Commit and Push Changes”), re-sequenced plan/iteration flow, and explicit verification requirements.
    • Streamlined environment/setup guidance and strengthened validation/error messaging for missing or invalid PR data.
    • Consolidated PR data retrieval and enhanced extraction to produce structured output files and concise summaries for easier review and response.

@forstmeier forstmeier requested review from chrisaddy and Copilot March 2, 2026 02:06
@forstmeier forstmeier self-assigned this Mar 2, 2026
@forstmeier forstmeier added the markdown Markdown code updates label Mar 2, 2026
@github-project-automation github-project-automation Bot moved this to In Progress in Overview Mar 2, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 2, 2026

📝 Walkthrough

Walkthrough

Reworks the .claude/commands/update-pull-request.md workflow: consolidates and renames steps, replaces scattered jq parsing with a single GraphQL fetch saved as pr_data.json, extracts structured files (metadata.json, review_threads.json, outdated_threads.json, pr_comments.json, check_failures.json), and tightens scratchpad/OWNER/REPO handling and validation.

Changes

Cohort / File(s) Summary
Update-Pull-Request Workflow
.claude/commands/update-pull-request.md
Completely rewrites the command instructions: renames steps (e.g., "Commit Changes" → "Commit and Push Changes"), replaces conditional scratchpad paths with deterministic mktemp creation and stricter permissions, derives OWNER/REPO from git remote, removes prior SCRATCHPAD validation, and updates messaging/errors.
PR Data Fetch & Extraction
.claude/commands/update-pull-request.md
Consolidates PR data retrieval into one GraphQL query saving pr_data.json; adds validation that pr_data.json exists and is valid JSON; replaces scattered jq parsing with an extraction producing metadata.json, review_threads.json, outdated_threads.json, pr_comments.json, and check_failures.json, and prints a summary of produced files.
Analysis / Plan / Response Flow
.claude/commands/update-pull-request.md
Renames and reorders sections (e.g., "Analyze Check Failures" → "2. Analyze PR State"); updates guidance for grouping feedback and iterating plans; changes response/resolution workflow to use review_threads.json thread IDs and structured mapping for auto-resolution; removes previous commit-delay guidance and aligns with new commit/push cadence.
Validation & Error Messaging
.claude/commands/update-pull-request.md
Adds clearer GraphQL response structure checks, explicit error messages referencing PR number/auth status, tighter JSON validation, and improved echo statements throughout.
Minor Text/Formatting
.claude/commands/update-pull-request.md
Multiple wording, formatting, and example-command updates to reflect new filenames and flows.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes the main change: a refactoring of the Claude 'update pull request' command. It is concise, clear, and specific.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor-update-pull-request-claude-command

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the .claude “update pull request” command to streamline the workflow for fetching PR data, analyzing feedback/check failures, planning fixes, and then committing/pushing before responding and resolving threads.

Changes:

  • Consolidates PR data setup/fetch into a single bash block and standardizes JSON extraction into focused scratchpad files.
  • Reorganizes workflow steps (analyze PR state → plan → implement → verify → commit+push → respond/resolve).
  • Adds explicit handling for outdated review threads and updates response/resolution guidance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .claude/commands/update-pull-request.md Outdated
Comment thread .claude/commands/update-pull-request.md Outdated
Comment thread .claude/commands/update-pull-request.md Outdated
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 2, 2026

Greptile Summary

This PR refactors the Claude "update pull request" command with several improvements:

Key improvements:

  • Better workflow logic: Reordered steps so commits/pushes happen BEFORE responding to and resolving comments. This ensures that when responses say "Fixed in latest commit", the commit is actually visible on the PR branch. Previously, threads were resolved before pushing, which was illogical.
  • Clearer structure: Consolidated related analysis steps (check failures, feedback grouping, outdated threads) into a single "Analyze PR State" step, reducing from 11 steps to 9 and improving readability.
  • Simplified code: Removed conditional SCRATCHPAD logic and export statements; always creates fresh scratchpad. Consolidated validation checks into simpler conditionals.
  • Documentation improvements: Updated step names (Commit ChangesCommit and Push Changes), clarified notes about CI execution timing, added explicit iteration instructions.

The refactor maintains all functionality while improving both code clarity and logical flow. No issues found.

Confidence Score: 5/5

  • This PR is safe to merge with no concerns - it's a clean refactor that improves code quality and workflow logic
  • Score reflects high-quality refactoring work that improves clarity and correctness without introducing any bugs or regressions. The workflow reordering is a genuine improvement, code simplifications make maintenance easier, and all documentation updates are accurate
  • No files require special attention

Important Files Changed

Filename Overview
.claude/commands/update-pull-request.md Refactored PR update workflow with improved logic (commit/push before respond/resolve), consolidated steps, simplified environment setup, and clearer documentation - all changes improve clarity and correctness

Last reviewed commit: b140a6f

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.claude/commands/update-pull-request.md (1)

28-130: ⚠️ Potential issue | 🔴 Critical

Critical: Environment variables won't persist for later steps.

Step 1 correctly combines all initial setup into a single bash execution (following line 25's guidance), but the SCRATCHPAD, OWNER, and REPO variables set here won't be available in subsequent bash tool invocations in steps 2, 6, 8, etc.

Multiple later sections reference these variables (lines 226-241, 246, 256, 362) and will fail when the variables are undefined.

🔧 Proposed solution: Persist variables to files

Add this at the end of the step 1 bash block (after line 129):

  echo "PR data fetched to ${SCRATCHPAD}/pr_data.json"
+
+ # Persist variables for later bash invocations
+ echo "${SCRATCHPAD}" > ~/.claude-update-pr-scratchpad
+ echo "${OWNER}" > "${SCRATCHPAD}/owner"
+ echo "${REPO}" > "${SCRATCHPAD}/repo"

Then update later sections to source these values. For example, in step 2 (line 226), add:

  ```bash
+ SCRATCHPAD=$(cat ~/.claude-update-pr-scratchpad)
+ OWNER=$(cat "${SCRATCHPAD}/owner")
+ REPO=$(cat "${SCRATCHPAD}/repo")
+
  echo "=== Check Failures ==="
  jq -r '.[] | "[\(.conclusion)] \(.name) - \(.detailsUrl)"' "${SCRATCHPAD}/check_failures.json"

Apply similar sourcing at the start of each bash block that uses these variables (lines 246, 256, 302-318, 329-382).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.claude/commands/update-pull-request.md around lines 28 - 130, The shell
step sets SCRATCHPAD, OWNER and REPO but those environment variables do not
persist across separate bash tool invocations; persist them to disk at the end
of the initial step by writing the SCRATCHPAD path to a well-known file (e.g.
~/.claude-update-pr-scratchpad) and creating files inside ${SCRATCHPAD} for
owner and repo (e.g. ${SCRATCHPAD}/owner and ${SCRATCHPAD}/repo), and then
update all later bash blocks that reference SCRATCHPAD, OWNER or REPO to
rehydrate them by reading those files (e.g. SCRATCHPAD=$(cat
~/.claude-update-pr-scratchpad); OWNER=$(cat "${SCRATCHPAD}/owner"); REPO=$(cat
"${SCRATCHPAD}/repo")). Ensure this change is applied where the script reads
check_failures.json, review/comment handling, and any other blocks that use
SCRATCHPAD/OWNER/REPO so they no longer assume the upstream environment
variables remain set.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.claude/commands/update-pull-request.md:
- Line 384: The sentence "Map each comment back to its parent thread using the
data structure from step 2 parsing" is misleading because the structured JSON
files are created in step 1; update the wording to reference the JSON creation
step and the actual filenames (e.g., review_threads.json) instead of "step 2
parsing" so it reads like: map each comment back to its parent thread using the
structured JSON produced in step 1 (review_threads.json, etc.), and ensure any
mention of "step 2" reflects that step 2 analyzes those files rather than
creating them.

---

Outside diff comments:
In @.claude/commands/update-pull-request.md:
- Around line 28-130: The shell step sets SCRATCHPAD, OWNER and REPO but those
environment variables do not persist across separate bash tool invocations;
persist them to disk at the end of the initial step by writing the SCRATCHPAD
path to a well-known file (e.g. ~/.claude-update-pr-scratchpad) and creating
files inside ${SCRATCHPAD} for owner and repo (e.g. ${SCRATCHPAD}/owner and
${SCRATCHPAD}/repo), and then update all later bash blocks that reference
SCRATCHPAD, OWNER or REPO to rehydrate them by reading those files (e.g.
SCRATCHPAD=$(cat ~/.claude-update-pr-scratchpad); OWNER=$(cat
"${SCRATCHPAD}/owner"); REPO=$(cat "${SCRATCHPAD}/repo")). Ensure this change is
applied where the script reads check_failures.json, review/comment handling, and
any other blocks that use SCRATCHPAD/OWNER/REPO so they no longer assume the
upstream environment variables remain set.

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f692a26 and b80163f.

📒 Files selected for processing (1)
  • .claude/commands/update-pull-request.md

Comment thread .claude/commands/update-pull-request.md Outdated
…776 review

Three documentation corrections based on automated reviewer feedback:

1. Line 251: Corrected outdated_threads.json field description. The jq extraction
   intentionally omits databaseId and position (not needed for resolution), so the
   previous "Same fields" claim was inaccurate. Now accurately states the fields
   that are included: thread ID and comment metadata (body, author, file path).

2. Line 384: Fixed wrong step number reference. Structured JSON files are created
   in step 1 (fetch PR data), not step 2 (analyze). Updated to reference step 1
   and specifically name review_threads.json for clarity.

3. Lines 25-26: Improved env var persistence note. Previous text only said to
   combine setup+fetch into one block, but subsequent separate bash blocks also
   reference SCRATCHPAD, OWNER, and REPO without guidance. Now explicitly instructs
   re-declaring those variables at the top of each subsequent bash block.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.claude/commands/update-pull-request.md:
- Around line 31-37: The umask is saved to _old_umask, changed to 077 for
mktemp, then immediately restored with umask "${_old_umask}"; since the
directory permissions are determined at creation, remove the restoration line if
there are no later operations in this function/block that rely on the original
umask—i.e., delete the umask "${_old_umask}" statement and keep
SCRATCHPAD="$(mktemp -d ...)" with umask 077 (or leave the save/restore as-is if
you prefer defensive coding).

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b80163f and 661c6de.

📒 Files selected for processing (1)
  • .claude/commands/update-pull-request.md

Comment thread .claude/commands/update-pull-request.md
Copilot AI review requested due to automatic review settings March 2, 2026 02:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .claude/commands/update-pull-request.md
Comment thread .claude/commands/update-pull-request.md
@forstmeier forstmeier merged commit 10d908c into master Mar 2, 2026
11 checks passed
@forstmeier forstmeier deleted the refactor-update-pull-request-claude-command branch March 2, 2026 20:29
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Overview Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

markdown Markdown code updates

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants