github_create_pr
Create a pull request on GitHub with title, body, base, and head branches. Optionally specify the repository path.
Instructions
Create a pull request on GitHub
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | Pull request title | |
| body | Yes | Pull request body | |
| base | Yes | Base branch | |
| head | Yes | Head branch | |
| path | No | Repository path (optional, defaults to current directory) |
Implementation Reference
- Main handler for github_create_pr tool. Calls gitService.createPullRequest with title, body, base, head args and returns JSON result.
protected async executeCommand(context: CommandContext): Promise<CommandResult> { try { const gitService = context.container.getService<GitService>('gitService'); const pr = await gitService.createPullRequest({ title: context.args.title as string, body: context.args.body as string, base: context.args.base as string, head: context.args.head as string, ...context.args }); return { content: [{ type: 'text', text: JSON.stringify({ message: 'Pull request created successfully', result: pr }, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: `Failed to create pull request: ${error instanceof Error ? error.message : String(error)}` }] }; } } - Alternative legacy handler for github_create_pr tool. Uses GitIntegration directly via gh CLI to create a pull request.
export class GitHubCreatePRCommand extends Command { readonly name = 'github_create_pr'; readonly description = 'Create a pull request'; readonly inputSchema: Tool['inputSchema'] = { type: 'object', properties: { title: { type: 'string', description: 'PR title' }, body: { type: 'string', description: 'PR description' }, base: { type: 'string', description: 'Base branch (optional)' }, path: { type: 'string', description: 'Repository path (optional, defaults to current directory)' } }, required: ['title'] }; protected validateArgs(args: Record<string, any>): void { this.assertString(args.title, 'title'); if (args.body !== undefined) { this.assertString(args.body, 'body'); } if (args.base !== undefined) { this.assertString(args.base, 'base'); } if (args.path !== undefined) { this.assertString(args.path, 'path'); } } protected async executeCommand(context: CommandContext): Promise<CommandResult> { const { title, body, base, path } = context.args; const git = new GitIntegration(path); if (!await git.hasGitHubCLI()) { throw new Error('GitHub CLI (gh) is not installed. Please install it first: https://cli.github.com'); } const prUrl = await git.createPullRequest(title, body, base); return { content: [{ type: 'text', text: `Pull request created: ${prUrl}` }] }; } } - PullRequest interface definition and GitHubIntegration.createPullRequest method that builds and executes gh pr create command.
export interface PullRequest { title: string; body?: string; base?: string; head?: string; } export class GitHubIntegration { private async executeCommand(command: string): Promise<string> { try { const { stdout } = await execAsync(command); return stdout.trim(); } catch (error: any) { throw new Error(`GitHub CLI command failed: ${error.message}`); } } async createPullRequest(options: PullRequest): Promise<string> { let command = `gh pr create --title "${options.title}"`; if (options.body) { command += ` --body "${options.body}"`; } if (options.base) { command += ` --base ${options.base}`; } if (options.head) { command += ` --head ${options.head}`; } return this.executeCommand(command); - GitService.createPullRequest delegates to GitHubIntegration.createPullRequest, the service-layer implementation.
async createPullRequest(options: PullRequest): Promise<string> { if (!this.github) { throw new Error('GitHub integration not available'); } return this.github.createPullRequest(options); - src/core/commands/index.ts:182-183 (registration)Registration of GitHubCreatePRCommand in the core command registry via registerMany.
new GitHubCreatePRCommand(), new GitCloneCommand()