Skip to content

Commit 8acb4f8

Browse files
sylvansysclaude
andcommitted
fix(github-orchestration): fix gh pr create command
The `gh pr create` command doesn't support `--json` flag. Instead, parse the PR URL from stdout and extract the PR number. Also use heredoc for body to handle multiline content properly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 9fbb783 commit 8acb4f8

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

plugins/github-orchestration/shared/hooks/utils/stacked-branches.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -543,12 +543,13 @@ export async function createPRWithAutoMerge(
543543
body: string;
544544
}
545545
): Promise<{ success: boolean; prNumber?: number; prUrl?: string; error?: string }> {
546-
// Create PR
547-
const escapedTitle = options.title.replace(/"/g, '\\"');
548-
const escapedBody = options.body.replace(/"/g, '\\"').replace(/\n/g, '\\n');
549-
546+
// Create PR using heredoc for proper body handling
547+
// gh pr create outputs the PR URL on success
550548
const createResult = await execCommand(
551-
`gh pr create --head "${options.head}" --base "${options.base}" --title "${escapedTitle}" --body "${escapedBody}" --json number,url`,
549+
`gh pr create --head "${options.head}" --base "${options.base}" --title "${options.title.replace(/"/g, '\\"')}" --body "$(cat <<'PRBODYEOF'
550+
${options.body}
551+
PRBODYEOF
552+
)"`,
552553
cwd,
553554
60000
554555
);
@@ -560,20 +561,20 @@ export async function createPRWithAutoMerge(
560561
};
561562
}
562563

563-
let prNumber: number;
564-
let prUrl: string;
564+
// Parse PR URL from stdout (gh pr create prints the URL)
565+
const prUrl = createResult.stdout.trim();
565566

566-
try {
567-
const prData = JSON.parse(createResult.stdout);
568-
prNumber = prData.number;
569-
prUrl = prData.url;
570-
} catch {
567+
// Extract PR number from URL (e.g., https://github.com/owner/repo/pull/123)
568+
const prNumberMatch = prUrl.match(/\/pull\/(\d+)$/);
569+
if (!prNumberMatch) {
571570
return {
572571
success: false,
573-
error: 'Failed to parse PR creation response',
572+
error: `Failed to parse PR number from URL: ${prUrl}`,
574573
};
575574
}
576575

576+
const prNumber = parseInt(prNumberMatch[1], 10);
577+
577578
// Enable auto-merge
578579
const mergeResult = await execCommand(
579580
`gh pr merge ${prNumber} --auto --squash`,

0 commit comments

Comments
 (0)