From c1abcb8f821c57011b0bd180a3945655061e2689 Mon Sep 17 00:00:00 2001 From: Madhura68 Date: Wed, 6 May 2026 00:34:30 +0200 Subject: [PATCH] feat(pr): enable auto-merge (squash) na pr create MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Best-effort gh pr merge --auto --squash direct na succesvolle gh pr create. PR mergt zodra alle vereiste CI-checks groen zijn, zonder handmatige actie van de gebruiker. Faal-tolerant: als auto-merge niet werkt (repo heeft "Allow auto-merge" uit, of token-scope ontbreekt), wordt alleen een warning gelogd. createPullRequest blijft de PR-URL teruggeven — auto-merge kan handmatig aangezet worden. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/git/pr.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/git/pr.ts b/src/git/pr.ts index 2f98b92..ffc0554 100644 --- a/src/git/pr.ts +++ b/src/git/pr.ts @@ -11,6 +11,7 @@ export async function createPullRequest(opts: { }): Promise<{ url: string } | { error: string }> { const { worktreePath, branchName, title, body } = opts + let url: string try { const { stdout } = await exec( 'gh', @@ -19,11 +20,10 @@ export async function createPullRequest(opts: { ) // gh prints the PR URL as the last non-empty line const lines = stdout.trim().split('\n').filter(Boolean) - const url = lines[lines.length - 1]?.trim() ?? '' + url = lines[lines.length - 1]?.trim() ?? '' if (!url.startsWith('http')) { return { error: `gh pr create produced unexpected output: ${stdout.slice(0, 200)}` } } - return { url } } catch (err: unknown) { const msg = (err as { message?: string }).message ?? String(err) const isNotFound = @@ -35,4 +35,21 @@ export async function createPullRequest(opts: { } return { error: `gh pr create failed: ${msg.slice(0, 300)}` } } + + // Best-effort: enable auto-merge (squash) on the freshly created PR. If the + // repo doesn't have "Allow auto-merge" turned on, or the token lacks scope, + // gh exits non-zero and we just log. The PR is still valid; auto-merge can + // be turned on manually. We do NOT fail the whole createPullRequest call — + // the URL was successfully obtained which is the contract this returns. + try { + await exec('gh', ['pr', 'merge', '--auto', '--squash', url], { cwd: worktreePath }) + } catch (err) { + const stderr = + (err as { stderr?: string }).stderr ?? (err as Error).message ?? '' + console.warn( + `[createPullRequest] auto-merge enable failed for ${url}: ${stderr.slice(0, 200)}`, + ) + } + + return { url } }