feat(pr): enable auto-merge (squash) na pr create
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) <noreply@anthropic.com>
This commit is contained in:
parent
35460b09de
commit
c1abcb8f82
1 changed files with 19 additions and 2 deletions
|
|
@ -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 }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue