GitHubPRCreator
Create a pull request from a forked repository back to the original repository—designed for AI agents that write code fixes and submit them for review.
Key Features
- Creates cross-repository pull requests from a fork to the upstream repository.
- Parses the target repository and issue number from a GitHub issue URL, automatically linking the PR to the issue.
- Verifies that the fork exists under the authenticated user's account before submitting.
- Supports draft pull requests via the
draftparameter. - Allows maintainers to modify the PR by setting
maintainer_can_modifytotrueautomatically. - Also available as
GitHubPRCreatorToolfor use with Haystack agents.
Configuration
- Store your GitHub personal access token as a secret named
GITHUB_TOKEN. For instructions, see Create Secrets. - Drag the
GitHubPRCreatorcomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- The token is read automatically from the
GITHUB_TOKENenvironment variable.
Connections
GitHubPRCreator receives an issue_url, a title, a branch (branch in your fork containing the changes), a base (target branch in the upstream repo), and an optional body and draft flag. It outputs a result string with the PR number or an error message. Connect it at the end of an agent pipeline after GitHubFileEditor and GitHubRepoForker have prepared the fork and branch.
Source Code
To check this component's source code, open pr_creator.py in the Haystack Core Integrations repository.
Usage Examples
Basic Configuration
GitHubPRCreator:
type: haystack_integrations.components.connectors.github.pr_creator.GitHubPRCreator
init_parameters:
github_token:
type: env_var
env_vars:
- GITHUB_TOKEN
strict: true
raise_on_failure: true
Using the Component in a Pipeline
This example shows the final step of a code-fix agent pipeline that forks a repo, makes a change, and opens a pull request.
# haystack-pipeline
components:
repo_forker:
type: haystack_integrations.components.connectors.github.repo_forker.GitHubRepoForker
init_parameters:
github_token:
type: env_var
env_vars:
- GITHUB_TOKEN
strict: true
auto_sync: true
create_branch: true
file_editor:
type: haystack_integrations.components.connectors.github.file_editor.GitHubFileEditor
init_parameters:
github_token:
type: env_var
env_vars:
- GITHUB_TOKEN
strict: true
branch: main
pr_creator:
type: haystack_integrations.components.connectors.github.pr_creator.GitHubPRCreator
init_parameters:
github_token:
type: env_var
env_vars:
- GITHUB_TOKEN
strict: true
raise_on_failure: true
connections:
- sender: repo_forker.repo
receiver: file_editor.repo
- sender: repo_forker.issue_branch
receiver: file_editor.branch
inputs:
query:
- repo_forker.url
- pr_creator.issue_url
outputs:
result: pr_creator.result
max_runs_per_component: 100
metadata: {}
Parameters
Inputs
| Parameter | Type | Default | Description |
|---|---|---|---|
issue_url | str | Full GitHub issue URL (for example, https://github.com/owner/repo/issues/123). Used to identify the target repository and to link the PR. | |
title | str | Title of the pull request. | |
branch | str | Branch in your fork that contains the changes. | |
base | str | Branch in the original repository to merge into (for example, main). | |
body | str | "" | Additional description for the pull request. |
draft | bool | False | If True, creates a draft pull request. |
Outputs
| Parameter | Type | Description |
|---|---|---|
result | str | Confirmation message with the PR number (for example, Pull request #42 created successfully and linked to issue #123) or an error message. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
github_token | Secret | Secret.from_env_var("GITHUB_TOKEN") | GitHub personal access token used for API authentication. Must belong to the fork owner. |
raise_on_failure | bool | True | If True, raises an exception on API errors. If False, returns an error string in result. |
Related Information
Was this page helpful?