feat(desktop): add PR merge from sidebar#1162
Conversation
Allows users to merge pull requests directly from the sidebar dropdown menu with support for squash, merge commit, and rebase strategies.
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughThis 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
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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.
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 appropriateTRPCErrorcodes.Two minor suggestions:
Consider adding the
--yesflag to skip confirmation prompts in CI/non-interactive environments: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") ) {
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
Summary
gh pr merge) under the hood with automatic branch deletionTest plan
Summary by CodeRabbit