cli / mcp for bitbucket
1import { createPullRequest } from '@bitbucket-tool/core';
2import { defineCommand, unwrapOrExit } from '../utils/command-builder';
3
4export const registerPrCreateCommand = defineCommand({
5 name: 'pr:create',
6 description: 'Create a pull request',
7 arguments: [
8 { syntax: '<source>', description: 'Source branch name' },
9 { syntax: '<title>', description: 'PR title' },
10 { syntax: '[description]', description: 'PR description' },
11 ],
12 options: [
13 {
14 flag: '-d, --destination <branch>',
15 description: 'Destination branch',
16 default: 'main',
17 },
18 ],
19 action: async ({ workspace, repoSlug, args, options }) => {
20 const [source, title, description] = args;
21
22 const pr = unwrapOrExit(
23 await createPullRequest({
24 workspace,
25 repoSlug,
26 sourceBranch: source,
27 destinationBranch: options.destination,
28 title,
29 description,
30 })
31 );
32
33 console.log(`\nPR created: #${pr.id}`);
34 console.log(`Title: ${pr.title}`);
35 console.log(`Branch: ${pr.source?.branch?.name} → ${pr.destination?.branch?.name}`);
36 console.log(`URL: ${pr.links?.html?.href}\n`);
37 },
38});