Skip to content

feat: add --pr option to batch commands for git worktree support#5

Open
fixcik wants to merge 3 commits intomasterfrom
feat/worktree-support
Open

feat: add --pr option to batch commands for git worktree support#5
fixcik wants to merge 3 commits intomasterfrom
feat/worktree-support

Conversation

@fixcik
Copy link
Owner

@fixcik fixcik commented Feb 6, 2026

Summary

  • Add --pr <url> and --owner/--repo/--number options to all batch commands (mark, reply, resolve, react)
  • Enables usage from git worktrees where auto-detection via gh pr view may fail
  • Falls back to auto-detection when options are not provided (backward compatible)
  • Add addPROptions() CLI helper to avoid duplication across 4 commands
  • Update README with "Working from Git Worktrees" section

Test plan

  • npm run check passes (typecheck + lint + 155 tests)
  • npm run build succeeds
  • resolve --help / mark --help show --pr, --owner, --repo, --number options
  • Manual test: gh-pr-threads resolve <id> --pr <url> from a non-repo directory

Summary by CodeRabbit

  • New Features

    • Mark, Reply, Resolve, and React commands now accept --pr, --owner, --repo, and --number options for explicit PR context specification.
  • Documentation

    • Added comprehensive Claude Code usage guide covering architecture, development workflow, and design patterns.
    • Expanded README with Git worktrees workflow examples and Mark Command usage patterns with available statuses.
  • Chores

    • Updated .gitignore with worktree-related ignore patterns.

Batch commands (mark, reply, resolve, react) now accept --pr <url> and
--owner/--repo/--number options for explicit PR specification instead of
relying solely on auto-detection via `gh pr view`. This enables usage
from git worktrees where auto-detection may fail.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 6, 2026

📝 Walkthrough

Walkthrough

This PR introduces a PROptions interface to propagate explicit PR context through CLI commands and shared utilities. A new parsePRInfo utility function parses PR information from URLs or provided options. Commands (Mark, Reply, Resolve, React) are updated to accept and forward PR options to context preparation functions. Documentation is expanded for Git worktrees and command examples.

Changes

Cohort / File(s) Summary
Documentation & Configuration
.gitignore, CLAUDE.md, README.md
Added Git worktrees ignore pattern, comprehensive Claude development guide, and documentation on PR specification via --pr flag with examples.
CLI Enhancement
src/cli.ts
Introduced addPROptions helper function to attach PR-related options (--pr, --owner, --repo, --number) to commands; updated Mark, Reply, Resolve, and React subcommands to construct and propagate prOptions to handlers.
Command Signature Updates
src/commands/mark.ts, reply.ts, react.ts, resolve.ts
Added optional prOptions?: PROptions parameter to all four command functions and threaded it through to prepareBatchCommandContext or prepareThreadCommandContext calls; imported PROptions type from shared module.
Shared Utilities Core
src/commands/shared.ts
Introduced PROptions interface for optional PR context (pr, owner, repo, number); updated prepareBatchCommandContext and prepareThreadCommandContext signatures to accept prOptions and use parsePRInfo for PR resolution; expanded BatchCommandContext to track resolvedIds and invalidIds.
PR Parsing Utility
src/utils/pr.test.ts
Added new parsePRInfo function to parse PR information from URL or explicit options (owner/repo/number), with fallback to auto-detection via git; covers URL precedence, partial options, and error handling.
Test Coverage
src/commands/shared.test.ts
Updated test setup to mock parsePRInfo instead of detectPR; added new test cases validating PR URL parsing, explicit owner/repo/number options, and auto-detection fallback behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~35 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through PRs with glee,
Threading options through the tree,
ParsePRInfo sings a parsing song,
Context flows where it belongs!
--pr flags and worktrees too,
Your pull requests shine brand new!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a --pr option to batch commands to support git worktree usage, which aligns directly with the PR's primary objective.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)

✅ Unit Test PR creation complete.

  • Create PR with unit tests
  • Commit unit tests in branch feat/worktree-support
  • Post copyable unit tests in a comment

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

Add comprehensive CLAUDE.md file with:
- Project overview and architecture documentation
- Development commands and testing guidelines
- Code style conventions and best practices
- Git workflow with worktrees support
- Documentation update planning rules

Update .gitignore:
- Add .worktrees/ directory for feature development isolation

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@fixcik
Copy link
Owner Author

fixcik commented Feb 6, 2026

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Feb 6, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@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

🤖 Fix all issues with AI agents
In `@src/cli.ts`:
- Around line 16-22: The PR number parsing currently uses parseInt which yields
NaN for invalid input and later gets treated as falsy in parsePRInfo, causing
silent fallback; update addPROptions to use a custom parser for the --number
option that converts the input to a number, verifies Number.isInteger and not
NaN, and throws a clear error (so the CLI fails fast) when validation fails, and
also add a defensive check in parsePRInfo to explicitly detect NaN/invalid
numbers from the parsed options and throw or surface an error instead of
treating it as 0; refer to addPROptions and parsePRInfo to locate the changes.
🧹 Nitpick comments (1)
CLAUDE.md (1)

199-203: Tighten phrasing: “CLI interface” → “CLI”.

Minor redundancy tweak for readability.

✏️ Proposed wording tweak
-1. **Changes in API or CLI interface** - require README.md update:
+1. **Changes in API or CLI** - require README.md update:

Comment on lines 16 to 22
function addPROptions(cmd: Command): Command {
return cmd
.option('--pr <url>', 'PR URL (auto-detects from current repo if omitted)')
.option('--owner <owner>', 'Repository owner')
.option('--repo <repo>', 'Repository name')
.option('--number <number>', 'PR number', parseInt);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, locate the file and verify it exists
find . -name "cli.ts" -type f

Repository: fixcik/gh-pr-threads

Length of output: 76


🏁 Script executed:

# Read the addPROptions function and surrounding context
cat -n src/cli.ts | head -50

Repository: fixcik/gh-pr-threads

Length of output: 2644


🏁 Script executed:

# Search for where --number option is used or parsed downstream
rg "options\.number|prOptions" src/

Repository: fixcik/gh-pr-threads

Length of output: 2089


🏁 Script executed:

# Check how Commander.js handles NaN values in option coercion
rg "parseInt" src/

Repository: fixcik/gh-pr-threads

Length of output: 655


🏁 Script executed:

# Check parsePRInfo function to see how options.number is handled
cat -n src/utils/pr.ts

Repository: fixcik/gh-pr-threads

Length of output: 2697


🏁 Script executed:

# Check prepareBatchCommandContext in shared.ts
cat -n src/commands/shared.ts | head -80

Repository: fixcik/gh-pr-threads

Length of output: 2797


Validate --number to prevent silent fallback to auto-detect on invalid input.

Lines 21 and 44 use parseInt, which returns NaN for non-numeric input. In parsePRInfo (src/utils/pr.ts:64), NaN is falsy and becomes 0, causing the condition on line 66 to fail and silently fall back to detectCurrentPR(). This means an invalid PR number is ignored without warning, potentially targeting the wrong PR for modifications.

Suggested fix (fail fast on invalid PR numbers)
+function parsePrNumber(value: string): number {
+  const n = Number.parseInt(value, 10);
+  if (!Number.isInteger(n) || n <= 0) {
+    throw new Error('PR number must be a positive integer');
+  }
+  return n;
+}
+
 function addPROptions(cmd: Command): Command {
   return cmd
     .option('--pr <url>', 'PR URL (auto-detects from current repo if omitted)')
     .option('--owner <owner>', 'Repository owner')
     .option('--repo <repo>', 'Repository name')
-    .option('--number <number>', 'PR number', parseInt);
+    .option('--number <number>', 'PR number', parsePrNumber);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function addPROptions(cmd: Command): Command {
return cmd
.option('--pr <url>', 'PR URL (auto-detects from current repo if omitted)')
.option('--owner <owner>', 'Repository owner')
.option('--repo <repo>', 'Repository name')
.option('--number <number>', 'PR number', parseInt);
}
function parsePrNumber(value: string): number {
const n = Number.parseInt(value, 10);
if (!Number.isInteger(n) || n <= 0) {
throw new Error('PR number must be a positive integer');
}
return n;
}
function addPROptions(cmd: Command): Command {
return cmd
.option('--pr <url>', 'PR URL (auto-detects from current repo if omitted)')
.option('--owner <owner>', 'Repository owner')
.option('--repo <repo>', 'Repository name')
.option('--number <number>', 'PR number', parsePrNumber);
}
🤖 Prompt for AI Agents
In `@src/cli.ts` around lines 16 - 22, The PR number parsing currently uses
parseInt which yields NaN for invalid input and later gets treated as falsy in
parsePRInfo, causing silent fallback; update addPROptions to use a custom parser
for the --number option that converts the input to a number, verifies
Number.isInteger and not NaN, and throws a clear error (so the CLI fails fast)
when validation fails, and also add a defensive check in parsePRInfo to
explicitly detect NaN/invalid numbers from the parsed options and throw or
surface an error instead of treating it as 0; refer to addPROptions and
parsePRInfo to locate the changes.

@coderabbitai
Copy link

coderabbitai bot commented Feb 6, 2026

Note

Unit test generation is a public access feature. Expect some limitations and changes as we gather feedback and continue to improve it.


Generating unit tests... This may take up to 20 minutes.

Instead of silently falling back to auto-detect when --number receives
non-numeric input (parseInt returns NaN → treated as falsy), now exits
with a clear error message.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 6, 2026

✅ Created PR with unit tests: #6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant