( rootDir: string, plan: ReleasePlan, config: BumpyConfig, packageDirs: Map<string, string>, branchName?: string, )
| 721 | // ---- version-pr mode ---- |
| 722 | |
| 723 | async function createVersionPr( |
| 724 | rootDir: string, |
| 725 | plan: ReleasePlan, |
| 726 | config: BumpyConfig, |
| 727 | packageDirs: Map<string, string>, |
| 728 | branchName?: string, |
| 729 | ): Promise<void> { |
| 730 | const branch = validateBranchName(branchName || config.versionPr.branch); |
| 731 | const baseBranch = validateBranchName( |
| 732 | tryRunArgs(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], { cwd: rootDir }) || 'main', |
| 733 | ); |
| 734 | |
| 735 | // Check if a version PR already exists |
| 736 | const existingPr = tryRunArgs(['gh', 'pr', 'list', '--head', branch, '--json', 'number', '--jq', '.[0].number'], { |
| 737 | cwd: rootDir, |
| 738 | }); |
| 739 | |
| 740 | // Create or update the branch |
| 741 | log.step(`Creating branch ${branch}...`); |
| 742 | const branchExists = tryRunArgs(['git', 'rev-parse', '--verify', branch], { cwd: rootDir }) !== null; |
| 743 | |
| 744 | if (branchExists) { |
| 745 | runArgs(['git', 'checkout', branch], { cwd: rootDir }); |
| 746 | runArgs(['git', 'reset', '--hard', baseBranch], { cwd: rootDir }); |
| 747 | } else { |
| 748 | runArgs(['git', 'checkout', '-b', branch], { cwd: rootDir }); |
| 749 | } |
| 750 | |
| 751 | // Run bumpy version |
| 752 | log.step('Running bumpy version...'); |
| 753 | const { versionCommand } = await import('./version.ts'); |
| 754 | await versionCommand(rootDir); |
| 755 | |
| 756 | // Commit and push |
| 757 | runArgs(['git', 'add', '-A'], { cwd: rootDir }); |
| 758 | const status = tryRunArgs(['git', 'status', '--porcelain'], { cwd: rootDir }); |
| 759 | if (!status) { |
| 760 | log.info('No version changes to commit.'); |
| 761 | runArgs(['git', 'checkout', baseBranch], { cwd: rootDir }); |
| 762 | return; |
| 763 | } |
| 764 | |
| 765 | const commitMsg = await resolveCommitMessage(config.versionCommitMessage, plan, rootDir); |
| 766 | runArgs(['git', 'commit', '-F', '-'], { cwd: rootDir, input: commitMsg }); |
| 767 | |
| 768 | pushWithToken(rootDir, branch, config); |
| 769 | |
| 770 | // Create or update PR |
| 771 | const repo = process.env.GITHUB_REPOSITORY; |
| 772 | const noPatWarning = !process.env.BUMPY_GH_TOKEN && !!repo; |
| 773 | |
| 774 | if (existingPr) { |
| 775 | const validPr = validatePrNumber(existingPr); |
| 776 | const prBody = formatVersionPrBody(plan, config.versionPr.preamble, packageDirs, repo, validPr, noPatWarning); |
| 777 | log.step(`Updating existing PR #${validPr}...`); |
| 778 | await withPatToken(() => |
| 779 | runArgsAsync(['gh', 'pr', 'edit', validPr, '--title', config.versionPr.title, '--body-file', '-'], { |
| 780 | cwd: rootDir, |
no test coverage detected
searching dependent graphs…