Skip to content

feat(desktop): add PR merge from sidebar#1162

Merged
Kitenite merged 2 commits into
mainfrom
kitenite/merge-from-sidebar
Feb 3, 2026
Merged

feat(desktop): add PR merge from sidebar#1162
Kitenite merged 2 commits into
mainfrom
kitenite/merge-from-sidebar

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Feb 3, 2026

Summary

  • Adds ability to merge PRs directly from the sidebar changes tab dropdown menu
  • Supports three merge strategies: squash and merge, create merge commit, and rebase and merge
  • Uses GitHub CLI (gh pr merge) under the hood with automatic branch deletion

Test plan

  • Open the sidebar changes tab on a branch with an open PR
  • Click the dropdown and verify "Merge Pull Request" submenu appears
  • Test each merge strategy option
  • Verify branch is deleted after merge
  • Verify error handling when PR cannot be merged (conflicts, required checks)

Summary by CodeRabbit

  • New Features
    • Added pull request merge capability with three merge strategies: squash, merge, and rebase.
    • Introduced a new merge button in the changes view displaying PR status with a dropdown menu for strategy selection.
    • Merge actions include automatic branch cleanup and error handling for merge conflicts or unmergeable PRs.

Allows users to merge pull requests directly from the sidebar dropdown menu with support for squash, merge commit, and rebase strategies.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 3, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This PR adds GitHub PR merging functionality by introducing a backend TRPC mutation for merging PRs with multiple strategies (squash, merge, rebase) and a new frontend PRButton component that displays PR status and provides a merge dropdown menu, replacing the previous PRStatusLink implementation.

Changes

Cohort / File(s) Summary
PR Merge Backend
apps/desktop/src/lib/trpc/routers/changes/git-operations.ts
Introduces mergePR mutation accepting worktreePath, merge strategy (squash/merge/rebase), and optional branch deletion. Executes gh pr merge commands and provides strategy-specific error handling with appropriate TRPC error codes.
PR UI Components
apps/desktop/src/renderer/screens/.../ChangesHeader/ChangesHeader.tsx, ChangesHeader/components/PRButton/PRButton.tsx, ChangesHeader/components/PRButton/index.ts
Replaces PRStatusLink with new PRButton component that displays PR status and merge options via dropdown menu. Updates ChangesHeader props to include worktreePath, viewMode, stash controls, and workspace context. New PRButton component integrates mergePR mutation and toast notifications.
Minor Updates
apps/desktop/src/renderer/screens/.../CommitInput/CommitInput.tsx
Removed comment line with no functional changes.

Sequence Diagram

sequenceDiagram
    actor User
    participant PRButton as PRButton Component
    participant TRPC as TRPC Client
    participant Backend as Git Operations
    participant Shell as Shell Executor
    participant GH as GitHub CLI

    User->>PRButton: Click merge option
    PRButton->>TRPC: Call mergePR mutation
    TRPC->>Backend: Execute with worktreePath & strategy
    Backend->>Shell: Execute gh pr merge command
    Shell->>GH: Run GitHub CLI
    GH-->>Shell: Success with metadata
    Shell-->>Backend: Command result
    Backend-->>TRPC: Return { success: true, mergedAt }
    TRPC-->>PRButton: Mutation resolved
    PRButton->>PRButton: Show success toast
    PRButton->>User: Call onRefresh callback
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 A button hops into the view,
With PR merges shiny and new!
Squash, rebase, merge with care—
GitHub magic fills the air! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description is largely incomplete, missing multiple required sections including Related Issues, Type of Change checkbox selections, Testing steps, Screenshots, and Additional Notes from the template. Fill out all required template sections: add Related Issues links, check the New feature box under Type of Change, complete the Testing section with detailed steps, and add any additional context as needed.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding PR merge functionality to the sidebar, which is the primary objective of this pull request.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kitenite/merge-from-sidebar

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

@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/desktop/src/renderer/screens/main/components/WorkspaceView/RightSidebar/ChangesView/components/CommitInput/CommitInput.tsx`:
- Around line 375-401: The merge submenu items allow repeated clicks during an
in-progress merge; update the DropdownMenuSubTrigger and each DropdownMenuItem
(the ones invoking handleMergePR("squash"|"merge"|"rebase")) to set disabled
when the merge mutation is pending (use the existing merge state, e.g.
mergeMutation.isLoading or an isMerging boolean you already maintain), so clicks
are ignored and UI shows disabled state while the operation runs.
🧹 Nitpick comments (1)
apps/desktop/src/lib/trpc/routers/changes/git-operations.ts (1)

261-308: Well-structured mutation with proper error categorization.

The implementation correctly validates input with Zod, uses security checks via assertRegisteredWorktree, and maps specific error patterns to appropriate TRPCError codes.

Two minor suggestions:

  1. Consider adding the --yes flag to skip confirmation prompts in CI/non-interactive environments:

  2. The error message matching is case-sensitive. Consider normalizing to lowercase for more robust matching:

🔧 Optional improvements
 const args = ["pr", "merge", `--${input.strategy}`];
 if (input.deleteBranch) {
   args.push("--delete-branch");
 }
+args.push("--yes"); // Skip confirmation prompt

 try {
   await execWithShellEnv("gh", args, { cwd: input.worktreePath });
   return { success: true, mergedAt: new Date().toISOString() };
 } catch (error) {
   const message =
     error instanceof Error ? error.message : String(error);
   console.error("[git/mergePR] Failed to merge PR:", message);
+  const lowerMessage = message.toLowerCase();

-  if (message.includes("no pull requests found")) {
+  if (lowerMessage.includes("no pull requests found")) {
     throw new TRPCError({
       code: "NOT_FOUND",
       message: "No pull request found for this branch",
     });
   }
   if (
-    message.includes("not mergeable") ||
-    message.includes("blocked")
+    lowerMessage.includes("not mergeable") ||
+    lowerMessage.includes("blocked")
   ) {

@Kitenite Kitenite merged commit e15c099 into main Feb 3, 2026
4 of 5 checks passed
@Kitenite Kitenite deleted the kitenite/merge-from-sidebar branch February 3, 2026 07:11
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 3, 2026

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ⚠️ Neon database branch
  • ⚠️ Electric Fly.io app

Thank you for your contribution! 🎉

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