Skip to content

feat(pr): add GitHub auto-merge support to PR merge section#1298

Merged
arnestrickmann merged 2 commits intogeneralaction:mainfrom
HajekTim:emdash/add-automerge-support-1d1
Mar 6, 2026
Merged

feat(pr): add GitHub auto-merge support to PR merge section#1298
arnestrickmann merged 2 commits intogeneralaction:mainfrom
HajekTim:emdash/add-automerge-support-1d1

Conversation

@HajekTim
Copy link
Contributor

@HajekTim HajekTim commented Mar 5, 2026

Summary

  • Adds GitHub auto-merge support to the PR merge UI, so users can enable auto-merge directly from Emdash when status checks are still running
  • When a PR is blocked by pending checks or branch protections, an "Enable auto-merge" button appears below the merge button
  • When auto-merge is already enabled (either via Emdash or GitHub), shows an amber "Auto-merge" badge with a "Cancel" button to disable it
  • Supports all three merge strategies (merge, squash, rebase) and works with both local and remote SSH projects

Changes

File What
src/renderer/lib/prStatus.ts Added AutoMergeRequest type and autoMergeRequest field to PrStatus
src/main/ipc/gitIpc.ts Added autoMergeRequest to PR status query fields; added git:enable-auto-merge and git:disable-auto-merge IPC handlers
src/main/preload.ts Added enableAutoMerge and disableAutoMerge IPC bridge methods
src/renderer/types/electron-api.d.ts Added types for new API methods and autoMergeRequest in PR status
src/renderer/components/MergePrSection.tsx Added auto-merge UI (enable button, status badge, cancel button)

Test plan

  • Open a project with a PR that has required status checks (branch protection rules)
  • Push to the PR while checks are still running — merge section should show "Blocked" status
  • Verify "Enable auto-merge" button appears below the disabled merge button
  • Click "Enable auto-merge" — should switch to amber "Auto-merge" badge with "Cancel" button
  • Verify on GitHub.com that auto-merge is actually enabled on the PR
  • Click "Cancel" to disable auto-merge and verify it reverts on GitHub
  • Test with different merge strategies (squash, rebase) via the dropdown before enabling
  • Verify auto-merge badge appears when auto-merge was enabled externally (e.g. via GitHub web)
  • Test error case: repo without "Allow auto-merge" enabled in settings — should show error toast

Note: Requires "Allow auto-merge" to be enabled in the GitHub repo settings (Settings → General → Pull Requests).

🤖 Generated with Claude Code

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>
@vercel
Copy link

vercel bot commented Mar 5, 2026

@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-apps
Copy link
Contributor

greptile-apps bot commented Mar 5, 2026

Greptile Summary

This PR introduces GitHub auto-merge support into the Emdash PR merge UI, allowing users to enable/disable auto-merge via the gh pr merge --auto / --disable-auto CLI flags directly from the app. Two new IPC handlers (git:enable-auto-merge, git:disable-auto-merge) are added and wired through the preload bridge; the renderer conditionally shows an "Enable auto-merge" button (when the PR is blocked by checks/protections) or an "Auto-merge" status badge with a "Cancel" button (when auto-merge is already active).

  • The feature is well-scoped and correctly handles both local and remote SSH projects.
  • Logic bug: In toggleAutoMerge, refreshPr() is called inside the outer try block that also wraps the enable/disable operation. If refreshPr() throws, the catch block fires and shows "Auto-merge toggle failed" even though the actual enable/disable API call succeeded — this is inconsistent with doMerge which calls refreshPr() only on success and doesn't expose it to the outer catch.
  • UX gap: The "Auto-merge" badge in the header doesn't surface autoMergeRequest.mergeMethod from GitHub, so users can't tell which merge strategy (merge/squash/rebase) will be applied at merge time.
  • The AutoMergeRequest shape is defined in prStatus.ts but re-inlined in electron-api.d.ts rather than imported, creating minor duplication that would need to be kept in sync if the type evolves.

Confidence Score: 3/5

  • Safe to merge after fixing the refreshPr() exception-masking bug in toggleAutoMerge.
  • The feature is well-structured and the IPC layer is correct. A logic bug in the renderer's toggleAutoMerge can make a successful auto-merge enable/disable appear as a failure if the subsequent PR refresh throws, which could erode user trust in the UI. This should be addressed before ship.
  • src/renderer/components/MergePrSection.tsx — the toggleAutoMerge function needs refreshPr() to be isolated from the main try/catch.

Important Files Changed

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
Loading

Last reviewed commit: 7fe2857

});
}
}
await refreshPr();
Copy link
Contributor

Choose a reason for hiding this comment

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

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:

Suggested change
await refreshPr();
await refreshPr().catch(() => {});

Comment on lines +315 to +319
{isAutoMergeEnabled ? (
<Badge variant="outline">
<Timer className="h-3 w-3 text-amber-500" />
Auto-merge
</Badge>
Copy link
Contributor

Choose a reason for hiding this comment

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

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>
@arnestrickmann
Copy link
Contributor

Thanks, @HajekTim
Good addition.

@arnestrickmann arnestrickmann merged commit 21253e6 into generalaction:main Mar 6, 2026
2 of 3 checks passed
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.

2 participants