Method signature

async createPullRequest(
  labelOptions?: LabelOptions,
  branchPrefix?: string
): Promise<PullRequestResponse>

Description

The createPullRequest method allows you to create a GitHub pull request after code changes have been generated using any supported agent (Codex, Claude, OpenCode, or Gemini). This method streamlines the process of submitting code changes for review by automatically creating a pull request with the generated modifications.

Parameters

ParameterTypeRequiredDescription
labelOptionsLabelOptionsNoOptional label configuration for the pull request
branchPrefixstringNoOptional prefix for the branch name that will be created

LabelOptions Interface

PropertyTypeRequiredDescription
namestringYesThe name of the label to create/apply to the pull request
colorstringYesThe color of the label in hex format (without #). Examples: “0e8a16” (green), “d73a49” (red), “0366d6” (blue)
descriptionstringYesA description of what this label represents

Return type

TypeDescription
Promise<PullRequestResponse>Promise that resolves to a pull request response object

PullRequestResponse Interface

PropertyTypeRequiredDescription
idnumberYesThe unique identifier of the pull request
numbernumberYesThe pull request number
statestringYesThe state of the pull request (e.g., “open”, “closed”)
titlestringYesThe title of the pull request
bodystringYesThe body/description of the pull request
html_urlstringYesThe URL to view the pull request on GitHub
headobjectYesInformation about the head branch of the PR
baseobjectYesInformation about the base branch of the PR
userobjectYesInformation about the user who created the PR
created_atstringYesISO timestamp when the PR was created
updated_atstringYesISO timestamp when the PR was last updated
mergedbooleanYesWhether the pull request has been merged
mergeableboolean | nullYesWhether the pull request can be merged
merge_commit_shastring | nullYesThe SHA of the merge commit if merged
branchNamestringYesThe name of the branch created for the PR
commitShastringNoThe SHA of the commit

Requirements

  • Agent Type: This method is available for all supported agents (Codex, Claude, OpenCode, and Gemini)
  • Initialization: The VibeKit instance must be properly initialized with valid agent configuration
  • Code Generation: Code changes should be generated before creating a pull request
  • GitHub Integration: A valid GitHub token and repository URL must be configured

Error handling

The method throws errors in the following scenarios:

Initialization Error

throw new Error("Agent not initialized")
  • When: The agent is not properly initialized
  • Resolution: Verify your VibeKit configuration includes valid agent settings and GitHub configuration

Usage examples

Basic Usage

import { VibeKit } from 'vibekit';

const vibekit = new VibeKit(config);

// Generate code first
await vibekit.generateCode({
  prompt: "Add a new user registration feature",
  mode: "code"
});

// Create pull request with default settings
try {
  const prResponse = await vibekit.createPullRequest();
  
  console.log(`Pull request created: ${prResponse.html_url}`);
  console.log(`PR ID: ${prResponse.id}`);
  console.log(`PR Number: ${prResponse.number}`);
  console.log(`Title: ${prResponse.title}`);
  console.log(`State: ${prResponse.state}`);
  console.log(`Branch: ${prResponse.branchName}`);
  console.log(`Commit SHA: ${prResponse.commitSha}`);
  console.log(`Created at: ${prResponse.created_at}`);
  console.log(`Mergeable: ${prResponse.mergeable}`);
} catch (error) {
  console.error("Failed to create pull request:", error.message);
}

Advanced Usage with Parameters

import { VibeKit, LabelOptions } from 'vibekit';

const vibekit = new VibeKit(config);

// Generate code first
await vibekit.generateCode({
  prompt: "Add authentication middleware",
  mode: "code"
});

// Create pull request with custom parameters
const labelOptions: LabelOptions = {
  name: "ai-generated",
  color: "0e8a16",
  description: "Code generated by AI agent"
};

try {
  const prResponse = await vibekit.createPullRequest(
    labelOptions,               // Custom label options
    "feature"                   // Branch prefix (will create feature/xyz branch)
  );
  
  console.log(`Pull request created: ${prResponse.html_url}`);
  console.log(`PR Number: ${prResponse.number}`);
  console.log(`Branch: ${prResponse.branchName}`);
  
  // Access additional GitHub API data
  console.log(`PR Title: ${prResponse.title}`);
  console.log(`PR Body: ${prResponse.body}`);
  console.log(`Author: ${prResponse.user.login}`);
  console.log(`Head branch: ${prResponse.head.ref}`);
  console.log(`Base branch: ${prResponse.base.ref}`);
} catch (error) {
  console.error("Failed to create pull request:", error.message);
}

Additional Label Examples

// Different label configurations
const bugfixLabel: LabelOptions = {
  name: "bug-fix",
  color: "d73a49",
  description: "Fixes a bug in the codebase"
};

const featureLabel: LabelOptions = {
  name: "new-feature",
  color: "0366d6", 
  description: "Adds new functionality"
};

const refactorLabel: LabelOptions = {
  name: "refactor",
  color: "f9d71c",
  description: "Code refactoring without functional changes"
};

Using with Different Agents

// Works with any agent type
const vibekitClaude = new VibeKit({
  agent: { type: "claude", model: { ... } },
  github: { token: "...", repository: "..." },
  // ... other config
});

const vibekitCodex = new VibeKit({
  agent: { type: "codex", model: { ... } },
  github: { token: "...", repository: "..." },
  // ... other config
});

// Both agents support createPullRequest
await vibekitClaude.createPullRequest();
await vibekitCodex.createPullRequest();

Notes

  • The pull request is automatically labeled with the agent type (‘codex’, ‘claude’, ‘opencode’, or ‘gemini’) to indicate which agent created it
  • Ensure your GitHub token has the necessary permissions to create pull requests in the target repository
  • The method creates a new branch for the pull request automatically
  • Code changes must be generated before calling this method
  • When using branchPrefix, the final branch name will be in the format {branchPrefix}/{generated-suffix}
  • The labelOptions parameter creates a new label if it doesn’t exist in the repository and applies it to the pull request
  • The response includes the complete GitHub API pull request data, allowing access to detailed information like user details, branch information, timestamps, and merge status