Merge pull request #23 from madhura68/feat/auto-merge-after-pr
feat: enable auto-merge (squash) after gh pr create
This commit is contained in:
commit
b48f2a5c74
1 changed files with 19 additions and 2 deletions
|
|
@ -11,6 +11,7 @@ export async function createPullRequest(opts: {
|
||||||
}): Promise<{ url: string } | { error: string }> {
|
}): Promise<{ url: string } | { error: string }> {
|
||||||
const { worktreePath, branchName, title, body } = opts
|
const { worktreePath, branchName, title, body } = opts
|
||||||
|
|
||||||
|
let url: string
|
||||||
try {
|
try {
|
||||||
const { stdout } = await exec(
|
const { stdout } = await exec(
|
||||||
'gh',
|
'gh',
|
||||||
|
|
@ -19,11 +20,10 @@ export async function createPullRequest(opts: {
|
||||||
)
|
)
|
||||||
// gh prints the PR URL as the last non-empty line
|
// gh prints the PR URL as the last non-empty line
|
||||||
const lines = stdout.trim().split('\n').filter(Boolean)
|
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')) {
|
if (!url.startsWith('http')) {
|
||||||
return { error: `gh pr create produced unexpected output: ${stdout.slice(0, 200)}` }
|
return { error: `gh pr create produced unexpected output: ${stdout.slice(0, 200)}` }
|
||||||
}
|
}
|
||||||
return { url }
|
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
const msg = (err as { message?: string }).message ?? String(err)
|
const msg = (err as { message?: string }).message ?? String(err)
|
||||||
const isNotFound =
|
const isNotFound =
|
||||||
|
|
@ -35,4 +35,21 @@ export async function createPullRequest(opts: {
|
||||||
}
|
}
|
||||||
return { error: `gh pr create failed: ${msg.slice(0, 300)}` }
|
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