Skip to content

fix: use dynamic branch references instead of hardcoded origin/main#477

Merged
Shironex merged 2 commits intov0.11.0rcfrom
fix/dynamic-branch-references
Jan 13, 2026
Merged

fix: use dynamic branch references instead of hardcoded origin/main#477
Shironex merged 2 commits intov0.11.0rcfrom
fix/dynamic-branch-references

Conversation

@Shironex
Copy link
Collaborator

@Shironex Shironex commented Jan 13, 2026

Summary

  • Fix handleResolveConflicts to use origin/${worktree.branch} instead of hardcoded origin/main
  • Add defaultBaseBranch prop to CreatePRDialog to default to selected branch
  • Fix branchCardCounts to use primary worktree branch as default for features without branchName
  • Enable PR status badge and "Address PR Comments" option for main/primary branch tab
  • Add automatic PR detection from GitHub for branches without stored metadata

Problem

Previously, several places had hardcoded origin/main or 'main' references:

  1. "Pull & Resolve Conflicts" always merged from origin/main regardless of current branch
  2. Create PR dialog always defaulted base branch to main
  3. Branch card counts used 'main' as fallback instead of actual primary branch
  4. PR status and "Address PR Comments" were hidden for the main branch tab
  5. PRs created outside the app (e.g., directly on GitHub) were not detected

Solution

  • Use dynamic branch references based on the selected worktree/branch
  • Pass defaultBaseBranch prop to dialogs
  • Fetch open PRs from GitHub API to detect PRs for any branch
  • Remove !worktree.isMain filter from PR display

Test plan

  • Create a release branch (e.g., v0.11.0rc) with an open PR
  • Verify PR status badge shows on the branch tab
  • Verify "Address PR Comments" option appears in dropdown
  • Verify "Pull & Resolve Conflicts" mentions the correct branch
  • Verify Create PR dialog defaults to correct base branch

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • GitHub PR information now fetched and integrated into worktree listings with graceful fallback handling.
    • PR creation dialog now defaults to the current worktree's branch as the base branch.
  • Bug Fixes

    • PR-related actions now correctly display for the main branch when a PR exists.

✏️ Tip: You can customize this high-level summary in your review settings.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 main or origin/main were hardcoded, replacing them with dynamic references based on the current worktree or primary branch. Additionally, it introduces automatic detection of GitHub PRs, improving the visibility of PRs created externally and ensuring a more consistent user experience across all branches.

Highlights

  • Dynamic Branch References: Replaced hardcoded origin/main with dynamic origin/${worktree.branch} for conflict resolution descriptions, ensuring accuracy across all branches.
  • Configurable Base Branch for PRs: The "Create PR" dialog now accepts a defaultBaseBranch prop, allowing it to pre-fill the base branch based on the selected worktree's primary branch instead of always defaulting to main.
  • Improved Branch Card Counts: The calculation for unarchived card counts now correctly uses the primary worktree branch as a fallback for features without an explicit branch name, rather than a hardcoded main.
  • Enhanced PR Visibility: PR status badges and the "Address PR Comments" option are now enabled for all branches, including the main/primary branch, by removing a restrictive !worktree.isMain filter.
  • Automatic GitHub PR Detection: Introduced a new mechanism to fetch open PRs directly from GitHub using the gh CLI, allowing the application to detect PRs created outside the app and display their status.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Jan 13, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit 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.

📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
Server PR Fetching
apps/server/src/routes/worktree/routes/list.ts
Adds fetchGitHubPRs() function to build a map of open GitHub PRs indexed by branch name; invoked during list handler flow to populate PR info as fallback when metadata.pr is missing. Gracefully degrades if gh CLI is unavailable.
UI PR & Branch Logic
apps/ui/src/components/views/board-view.tsx
Moves branch counting computation later in the component flow to depend on hookFeatures and worktrees; changes default branch resolution to use primary/main branch when feature.branchName is missing; updates handleResolveConflicts to target remote branch instead of hardcoded origin/main; passes defaultBaseBranch prop to CreatePRDialog derived from selected worktree context.
PR Dialog Default Branch
apps/ui/src/components/views/board-view/dialogs/create-pr-dialog.tsx
Introduces optional defaultBaseBranch prop (defaults to 'main') to control PR base branch; initializes and resets baseBranch state from defaultBaseBranch when dialog opens or worktree changes.
Worktree PR Actions Visibility
apps/ui/src/components/views/board-view/worktree-panel/components/worktree-actions-dropdown.tsx
Removes constraint that PR actions only render when branch is not main; now renders PR-related UI block whenever hasPR && worktree.pr exists.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Bug, Enhancement, Ready-To-Merge

Poem

🐰 A rabbit hops through branches bright,
Now PRs shine in worktree light,
GitHub whispers when metadata's gone,
Base branches flow from dawn to dawn,
Actions dance on every frond! 🌿

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 accurately and concisely summarizes the main objective of the PR: replacing hardcoded branch references with dynamic ones based on the selected worktree branch.

✏️ 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.

❤️ Share

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

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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',
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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.

Suggested change
'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',

@Shironex
Copy link
Collaborator Author

@coderabbitai review it

@coderabbitai
Copy link

coderabbitai bot commented Jan 13, 2026

@Shironex: I'll review the changes in this PR for you.

✅ 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 @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 list command could hang if there are network issues or GitHub API slowdowns, potentially blocking the entire /list endpoint 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

📥 Commits

Reviewing files that changed from the base of the PR and between 32f6c6d and c00cfcb.

📒 Files selected for processing (4)
  • apps/server/src/routes/worktree/routes/list.ts
  • apps/ui/src/components/views/board-view.tsx
  • apps/ui/src/components/views/board-view/dialogs/create-pr-dialog.tsx
  • apps/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.tsx
  • apps/ui/src/components/views/board-view/worktree-panel/components/worktree-actions-dropdown.tsx
  • apps/server/src/routes/worktree/routes/list.ts
  • apps/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.tsx
  • apps/ui/src/components/views/board-view/worktree-panel/components/worktree-actions-dropdown.tsx
  • apps/server/src/routes/worktree/routes/list.ts
  • apps/ui/src/components/views/board-view.tsx
apps/server/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use createEventEmitter() from lib/events.ts for 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.tsx
  • apps/ui/src/components/views/board-view/worktree-panel/components/worktree-actions-dropdown.tsx
  • apps/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.ts
  • apps/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.isMain filter, 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 fetchGitHubPRs function 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 defaultBaseBranch prop 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 defaultBaseBranch in 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 branchCardCounts computation now correctly uses the primary worktree's branch as the default for features without an explicit branchName, rather than hardcoding 'main'. This ensures accurate card counts when the repository uses a different default branch (e.g., master, develop, or release branches like v0.11.0rc).


729-733: LGTM! Core fix for dynamic branch references in conflict resolution.

This change addresses the main issue in the PR: the handleResolveConflicts function now correctly uses origin/${worktree.branch} instead of the hardcoded origin/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 selectedWorktreeBranch ensures 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 than main.

Comment on lines 290 to 305
// 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;
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 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.ts

Repository: 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 -50

Repository: 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>
@Shironex Shironex force-pushed the fix/dynamic-branch-references branch from c00cfcb to 51e4e84 Compare January 13, 2026 23:48
@Shironex Shironex merged commit 219af28 into v0.11.0rc Jan 13, 2026
6 checks passed
@Shironex Shironex deleted the fix/dynamic-branch-references branch January 13, 2026 23:59
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