feat(pr): add GitHub auto-merge support to PR merge section#1298
Conversation
Add the ability to enable and disable GitHub's auto-merge feature directly from the Emdash PR merge UI. When a PR is blocked by pending checks or branch protections, users can now click "Enable auto-merge" to have GitHub automatically merge the PR once all requirements pass. - Add `autoMergeRequest` field to PR status queries (local + remote) - Add `git:enable-auto-merge` and `git:disable-auto-merge` IPC handlers - Show "Enable auto-merge" button when PR is blocked by checks - Show amber "Auto-merge" badge with cancel option when enabled - Support all three merge strategies (merge, squash, rebase) - Works with both local and remote SSH projects Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@HajekTim is attempting to deploy a commit to the General Action Team on Vercel. A member of the Team first needs to authorize it. |
Greptile SummaryThis PR introduces GitHub auto-merge support into the Emdash PR merge UI, allowing users to enable/disable auto-merge via the
Confidence Score: 3/5
|
| Filename | Overview |
|---|---|
| src/renderer/components/MergePrSection.tsx | Adds auto-merge UI (badge, enable button, cancel button). Contains a logic bug where refreshPr() inside the outer try block can cause a misleading failure toast on a successful operation. Minor UX gap: active merge strategy not displayed in the auto-merge badge. |
| src/main/ipc/gitIpc.ts | Adds IPC handlers for git:enable-auto-merge and git:disable-auto-merge, with proper remote/local path handling and error propagation. The redundant double-cast of args is harmless. Strategy mapping and prNumber validation are correct. |
| src/main/preload.ts | Adds enableAutoMerge and disableAutoMerge bridge methods. Types and IPC channel names match the new handlers correctly. |
| src/renderer/lib/prStatus.ts | Adds AutoMergeRequest type and autoMergeRequest optional field to PrStatus. Clean, minimal change. |
| src/renderer/types/electron-api.d.ts | Adds type declarations for enableAutoMerge, disableAutoMerge, and the autoMergeRequest field. The autoMergeRequest shape is inlined here rather than imported from prStatus.ts, which is a minor duplication but consistent with the existing file style. |
Sequence Diagram
sequenceDiagram
participant UI as MergePrSection (Renderer)
participant Bridge as preload.ts (contextBridge)
participant IPC as gitIpc.ts (Main)
participant GH as gh CLI
Note over UI: PR is BLOCKED / HAS_HOOKS / UNSTABLE
UI->>Bridge: enableAutoMerge({ taskPath, prNumber, strategy })
Bridge->>IPC: ipcRenderer.invoke('git:enable-auto-merge', args)
IPC->>GH: gh pr merge [prNumber] --auto --squash|--rebase|--merge
GH-->>IPC: stdout / stderr
IPC-->>Bridge: { success: true } | { success: false, error }
Bridge-->>UI: result
alt success
UI->>UI: toast("Auto-merge enabled")
UI->>Bridge: getPrStatus({ taskPath })
Bridge->>IPC: ipcRenderer.invoke('git:get-pr-status', args)
IPC->>GH: gh pr view --json ...,autoMergeRequest -q .
GH-->>IPC: PR JSON with autoMergeRequest object
IPC-->>Bridge: { success: true, pr: { autoMergeRequest: {...} } }
Bridge-->>UI: updated PrStatus → badge flips to "Auto-merge"
else failure
UI->>UI: toast("Failed to enable auto-merge", error)
end
Note over UI: User clicks "Cancel"
UI->>Bridge: disableAutoMerge({ taskPath, prNumber })
Bridge->>IPC: ipcRenderer.invoke('git:disable-auto-merge', args)
IPC->>GH: gh pr merge [prNumber] --disable-auto
GH-->>IPC: stdout / stderr
IPC-->>Bridge: { success: true } | { success: false, error }
Bridge-->>UI: result
UI->>UI: refreshPr() → autoMergeRequest becomes null → badge reverts
Last reviewed commit: 7fe2857
| }); | ||
| } | ||
| } | ||
| await refreshPr(); |
There was a problem hiding this comment.
refreshPr() inside try block can mask a successful operation
refreshPr() is placed unconditionally inside the try block, after both the enable and disable branches. If refreshPr() throws (e.g., a transient network error), control falls to the catch block which displays "Auto-merge toggle failed" — even though the enableAutoMerge / disableAutoMerge call itself succeeded. The user ends up seeing a failure toast for an operation that worked.
Compare this with doMerge above, where refreshPr() is only called on success and inside no outer try that also covers the refresh.
Move refreshPr() outside the main try/catch, or wrap it in its own try/catch so its failure is handled separately:
| await refreshPr(); | |
| await refreshPr().catch(() => {}); |
| {isAutoMergeEnabled ? ( | ||
| <Badge variant="outline"> | ||
| <Timer className="h-3 w-3 text-amber-500" /> | ||
| Auto-merge | ||
| </Badge> |
There was a problem hiding this comment.
Auto-merge badge omits the active merge strategy
The autoMergeRequest object returned from GitHub includes a mergeMethod field (e.g., "SQUASH", "REBASE", "MERGE"), and that data is already present in activePr.autoMergeRequest. The badge currently shows a generic "Auto-merge" label, leaving users unsure which strategy will actually be applied.
Consider surfacing the strategy, for example:
<Badge variant="outline">
<Timer className="h-3 w-3 text-amber-500" />
Auto-merge ({activePr.autoMergeRequest?.mergeMethod?.toLowerCase() ?? 'merge'})
</Badge>This also makes it clear when the externally-set method differs from the one selected in the local dropdown.
- Fix logic bug: move refreshPr() outside try/catch in toggleAutoMerge so a refresh failure doesn't mask a successful enable/disable - Surface autoMergeRequest.mergeMethod in the UI badge and description so users can see which strategy (merge/squash/rebase) will be used - Import AutoMergeRequest type in electron-api.d.ts instead of re-inlining the shape, eliminating type duplication Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Thanks, @HajekTim |
Summary
Changes
src/renderer/lib/prStatus.tsAutoMergeRequesttype andautoMergeRequestfield toPrStatussrc/main/ipc/gitIpc.tsautoMergeRequestto PR status query fields; addedgit:enable-auto-mergeandgit:disable-auto-mergeIPC handlerssrc/main/preload.tsenableAutoMergeanddisableAutoMergeIPC bridge methodssrc/renderer/types/electron-api.d.tsautoMergeRequestin PR statussrc/renderer/components/MergePrSection.tsxTest plan
Note: Requires "Allow auto-merge" to be enabled in the GitHub repo settings (Settings → General → Pull Requests).
🤖 Generated with Claude Code