fix: use dynamic branch references instead of hardcoded origin/main#477
fix: use dynamic branch references instead of hardcoded origin/main#477
Conversation
Summary of ChangesHello @Shironex, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the application's flexibility and accuracy in handling Git branches and Pull Requests. It addresses several instances where Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 📝 WalkthroughWalkthroughThe PR introduces fallback GitHub PR fetching on the server when metadata-driven PR info is unavailable, and enhances the UI to improve PR visibility across worktrees with better default branch handling and branch-aware logic throughout the PR creation flow. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
There was a problem hiding this comment.
Code Review
This pull request effectively removes hardcoded references to the main branch, replacing them with dynamic branch lookups. The changes are well-executed across the UI and server, covering conflict resolution, PR creation dialogs, and branch-specific card counts. The introduction of automatic PR detection from GitHub is a great enhancement for keeping the application state in sync. The code is clean and the fixes are correctly implemented. I have one suggestion to improve the robustness of the new PR detection feature.
|
|
||
| // Fetch open PRs from GitHub | ||
| const { stdout } = await execAsync( | ||
| 'gh pr list --state open --json number,title,url,state,headRefName,createdAt --limit 100', |
There was a problem hiding this comment.
The gh pr list command has a hardcoded limit of 100 pull requests. For repositories with a large number of open PRs, this might not be sufficient to detect all of them. Consider increasing this limit to a higher number, like 1000, to make this feature more robust. For a more complete solution, you could implement pagination using the --paginate flag, although that would require more complex logic to handle the streamed JSON output.
| 'gh pr list --state open --json number,title,url,state,headRefName,createdAt --limit 100', | |
| 'gh pr list --state open --json number,title,url,state,headRefName,createdAt --limit 1000', |
|
@coderabbitai review it |
|
@Shironex: I'll review the changes in this PR for you. ✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @apps/server/src/routes/worktree/routes/list.ts:
- Around line 290-305: Make the GitHub PR fetch conditional on includeDetails:
only call fetchGitHubPRs(projectPath) when includeDetails is true (like the
existing change-status logic), and otherwise set githubPRs to an empty Map or
undefined-safe value so the later loop that assigns worktree.pr from
githubPRs.get(worktree.branch) does not throw; update the variable used in the
for-loop (githubPRs) accordingly and ensure the fallback branch-checking logic
still works when fetchGitHubPRs was skipped.
🧹 Nitpick comments (1)
apps/server/src/routes/worktree/routes/list.ts (1)
139-142: Consider adding a timeout for the gh CLI call.The
gh pr listcommand could hang if there are network issues or GitHub API slowdowns, potentially blocking the entire/listendpoint response.🔧 Suggested improvement
// Fetch open PRs from GitHub const { stdout } = await execAsync( 'gh pr list --state open --json number,title,url,state,headRefName,createdAt --limit 100', - { cwd: projectPath, env: execEnv } + { cwd: projectPath, env: execEnv, timeout: 15000 } );
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
apps/server/src/routes/worktree/routes/list.tsapps/ui/src/components/views/board-view.tsxapps/ui/src/components/views/board-view/dialogs/create-pr-dialog.tsxapps/ui/src/components/views/board-view/worktree-panel/components/worktree-actions-dropdown.tsx
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Always import from shared packages (@automaker/*), never from old relative paths
Files:
apps/ui/src/components/views/board-view/dialogs/create-pr-dialog.tsxapps/ui/src/components/views/board-view/worktree-panel/components/worktree-actions-dropdown.tsxapps/server/src/routes/worktree/routes/list.tsapps/ui/src/components/views/board-view.tsx
**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Use
resolveModelString()from @automaker/model-resolver to convert model aliases (haiku, sonnet, opus) to full model names
Files:
apps/ui/src/components/views/board-view/dialogs/create-pr-dialog.tsxapps/ui/src/components/views/board-view/worktree-panel/components/worktree-actions-dropdown.tsxapps/server/src/routes/worktree/routes/list.tsapps/ui/src/components/views/board-view.tsx
apps/server/src/**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Use
createEventEmitter()fromlib/events.tsfor all server operations to emit events that stream to frontend via WebSocket
Files:
apps/server/src/routes/worktree/routes/list.ts
🧠 Learnings (2)
📚 Learning: 2025-12-30T01:02:07.114Z
Learnt from: illia1f
Repo: AutoMaker-Org/automaker PR: 324
File: apps/ui/src/components/views/board-view/components/kanban-card/kanban-card.tsx:122-131
Timestamp: 2025-12-30T01:02:07.114Z
Learning: Tailwind CSS v4 uses postfix syntax for the important modifier: append ! at the end of the utility class (e.g., backdrop-blur-[0px]! or hover:bg-red-500!). The older v3 style used a prefix (!) at the start (e.g., !backdrop-blur-[0px]); prefer the postfix form for consistency across TSX files.
Applied to files:
apps/ui/src/components/views/board-view/dialogs/create-pr-dialog.tsxapps/ui/src/components/views/board-view/worktree-panel/components/worktree-actions-dropdown.tsxapps/ui/src/components/views/board-view.tsx
📚 Learning: 2025-12-28T05:07:48.147Z
Learnt from: CR
Repo: AutoMaker-Org/automaker PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-28T05:07:48.147Z
Learning: Each feature executes in an isolated git worktree created via automaker/git-utils to protect the main branch during AI agent execution
Applied to files:
apps/server/src/routes/worktree/routes/list.tsapps/ui/src/components/views/board-view.tsx
🧬 Code graph analysis (1)
apps/server/src/routes/worktree/routes/list.ts (4)
apps/server/src/lib/worktree-metadata.ts (1)
WorktreePRInfo(12-18)apps/ui/src/components/views/board-view/worktree-panel/types.ts (1)
WorktreePRInfo(1-7)apps/server/src/routes/worktree/common.ts (3)
isGhCliAvailable(117-125)execAsync(12-12)execEnv(96-99)apps/server/src/routes/common.ts (1)
getErrorMessage(26-28)
🔇 Additional comments (7)
apps/ui/src/components/views/board-view/worktree-panel/components/worktree-actions-dropdown.tsx (1)
335-371: LGTM! PR visibility enabled for all worktrees.The condition change correctly removes the
!worktree.isMainfilter, allowing PR status badges and the "Address PR Comments" option to appear for the main/primary branch when a PR exists. This aligns with the PR objective to enable PR-related actions for all branches with associated PRs.apps/server/src/routes/worktree/routes/list.ts (1)
124-168: LGTM! Clean implementation of fallback PR detection.The
fetchGitHubPRsfunction correctly:
- Checks gh CLI availability before attempting to use it
- Uses appropriate error handling with silent degradation
- Returns a well-typed map for branch-to-PR lookup
The fallback logic at lines 296-305 correctly prioritizes stored metadata over GitHub API data.
apps/ui/src/components/views/board-view/dialogs/create-pr-dialog.tsx (2)
33-34: LGTM! Clean implementation of dynamic base branch defaulting.The
defaultBaseBranchprop is well-designed:
- Optional with sensible fallback (
'main')- Properly documented with JSDoc
- Correctly initializes state and resets on dialog open/close
Also applies to: 43-43, 47-47
59-88: LGTM! Effect dependencies are complete.The useEffect correctly includes
defaultBaseBranchin the dependency array, ensuring the dialog state resets properly when the selected worktree changes (which updates the default base branch).apps/ui/src/components/views/board-view.tsx (3)
415-429: LGTM! Proper fallback to primary worktree branch.The
branchCardCountscomputation now correctly uses the primary worktree's branch as the default for features without an explicitbranchName, rather than hardcoding'main'. This ensures accurate card counts when the repository uses a different default branch (e.g.,master,develop, or release branches likev0.11.0rc).
729-733: LGTM! Core fix for dynamic branch references in conflict resolution.This change addresses the main issue in the PR: the
handleResolveConflictsfunction now correctly usesorigin/${worktree.branch}instead of the hardcodedorigin/main. The description text is also updated to clearly communicate which branches are being merged.
1711-1716: LGTM! CreatePRDialog now defaults to the correct base branch.Passing
selectedWorktreeBranchensures the PR creation dialog defaults to the currently selected worktree's branch context, which is particularly useful for release branches where PRs should target that branch rather thanmain.
| // Fetch open PRs from GitHub to detect PRs created outside the app | ||
| const githubPRs = await fetchGitHubPRs(projectPath); | ||
|
|
||
| // Add PR info from metadata or GitHub for each worktree | ||
| for (const worktree of worktrees) { | ||
| const metadata = allMetadata.get(worktree.branch); | ||
| if (metadata?.pr) { | ||
| // Use stored metadata (more complete info) | ||
| worktree.pr = metadata.pr; | ||
| } else { | ||
| // Fall back to GitHub PR detection | ||
| const githubPR = githubPRs.get(worktree.branch); | ||
| if (githubPR) { | ||
| worktree.pr = githubPR; | ||
| } | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check if there are other patterns in the codebase where gh CLI calls are parallelized or conditionally executed
rg -n "gh pr list|gh api" --type ts -C2 apps/server/Repository: AutoMaker-Org/automaker
Length of output: 4701
🏁 Script executed:
#!/bin/bash
# Get the full context of the list.ts file around lines 290-305
wc -l apps/server/src/routes/worktree/routes/list.tsRepository: AutoMaker-Org/automaker
Length of output: 117
🏁 Script executed:
#!/bin/bash
# Check the function signature and look for includeDetails parameter
cat -n apps/server/src/routes/worktree/routes/list.ts | head -50Repository: AutoMaker-Org/automaker
Length of output: 2205
🏁 Script executed:
#!/bin/bash
# Find the fetchGitHubPRs function definition
rg -n "fetchGitHubPRs" --type ts -A 15 apps/server/Repository: AutoMaker-Org/automaker
Length of output: 2766
🏁 Script executed:
#!/bin/bash
# Check if there's an includeDetails or similar conditional parameter
rg -n "includeDetails" --type ts apps/server/Repository: AutoMaker-Org/automaker
Length of output: 471
🏁 Script executed:
#!/bin/bash
# Get the full context of the list endpoint, especially around line 260-310
cat -n apps/server/src/routes/worktree/routes/list.ts | sed -n '260,310p'Repository: AutoMaker-Org/automaker
Length of output: 2110
🏁 Script executed:
#!/bin/bash
# Get the router function definition and return statement to see endpoint structure
cat -n apps/server/src/routes/worktree/routes/list.ts | sed -n '160,180p'Repository: AutoMaker-Org/automaker
Length of output: 764
Make GitHub PR fetch conditional on includeDetails for better endpoint performance.
The fetchGitHubPRs call at line 291 executes unconditionally for every list request, even when PR information is not needed. The codebase already demonstrates a similar pattern for the change status fetch (lines 270–288), which is only performed when includeDetails is true. Apply the same conditional logic to the GitHub PR fetch for consistency and to reduce latency on repositories with many worktrees.
🤖 Prompt for AI Agents
In @apps/server/src/routes/worktree/routes/list.ts around lines 290 - 305, Make
the GitHub PR fetch conditional on includeDetails: only call
fetchGitHubPRs(projectPath) when includeDetails is true (like the existing
change-status logic), and otherwise set githubPRs to an empty Map or
undefined-safe value so the later loop that assigns worktree.pr from
githubPRs.get(worktree.branch) does not throw; update the variable used in the
for-loop (githubPRs) accordingly and ensure the fallback branch-checking logic
still works when fetchGitHubPRs was skipped.
- Fix handleResolveConflicts to use origin/${worktree.branch} instead of
hardcoded origin/main for pull and resolve conflicts
- Add defaultBaseBranch prop to CreatePRDialog to use selected branch
- Fix branchCardCounts to use primary worktree branch as default
- Enable PR status and Address PR Comments for main branch tab
- Add automatic PR detection from GitHub for branches without stored metadata
This allows users working on release branches (like v0.11.0rc) to properly
pull from their branch's remote and see PR status for any branch.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
c00cfcb to
51e4e84
Compare
Summary
handleResolveConflictsto useorigin/${worktree.branch}instead of hardcodedorigin/maindefaultBaseBranchprop toCreatePRDialogto default to selected branchbranchCardCountsto use primary worktree branch as default for features without branchNameProblem
Previously, several places had hardcoded
origin/mainor'main'references:origin/mainregardless of current branchmain'main'as fallback instead of actual primary branchSolution
defaultBaseBranchprop to dialogs!worktree.isMainfilter from PR displayTest plan
v0.11.0rc) with an open PR🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.