Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

GitHubPRCheckout

Fetch a GitHub pull request's diff and the repository's review guidelines so an LLM or agent can review the change. Use it at the start of a code review pipeline.

Key Features​

  • Takes a repository in owner/repo format and a pull request number.
  • Returns the pull request diff as text, with the new-file line number on every line, along with the SHA of the pull request's head commit.
  • Checks out the head commit into a directory in the working directory, so an agent can read the code around the change with other tools.
  • Returns the repository's guideline files, such as AGENTS.md, from the base branch before the diff.
  • Can return the diff of specific changed files only, for example files that were left out of an earlier call.
  • Needs git 2.31 or later, which is installed on the platform.
  • Also available as GitHubPRCheckoutTool for use with Haystack agents.

Configuration​

  1. Store a GitHub personal access token as a secret named GITHUB_TOKEN. The token must have access to the repository you want to review. For instructions, see Create Secrets.
  2. Add the GitHubPRCheckout component to your pipeline and make sure its github_token init parameter reads the GITHUB_TOKEN secret.

If the component fails to fetch a pull request, check that the token has access to the repository and that repo and pull_number are correct.

Connections​

GitHubPRCheckout receives a repo (in owner/repo format) and a pull_number. It can also receive a list of files to limit the diff. It outputs text with the diff and head_sha with the SHA of the head commit. Connect text to a prompt builder or an LLM that reviews the change. When you use it with an agent, use GitHubPRCheckoutTool instead so the agent can call it on its own.

Source Code​

To check this component's source code, open the github integration in the Haystack Core Integrations repository.

Usage Examples​

Basic Configuration​

GitHubPRCheckout:
type: haystack_integrations.components.connectors.github.pr_checkout.GitHubPRCheckout
init_parameters:
github_token:
type: env_var
env_vars:
- GITHUB_TOKEN
strict: false

Using the Component in a Pipeline​

This example shows a pipeline that fetches a pull request and asks an LLM to review it.

# haystack-pipeline

components:
pr_checkout:
type: haystack_integrations.components.connectors.github.pr_checkout.GitHubPRCheckout
init_parameters:
github_token:
type: env_var
env_vars:
- GITHUB_TOKEN
strict: false

prompt_builder:
type: haystack.components.builders.chat_prompt_builder.ChatPromptBuilder
init_parameters:
template:
- role: user
content: "Review the following pull request and point out bugs and risky changes:\n\n{{ text }}"
required_variables:
- text

llm:
type: haystack.components.generators.chat.openai.OpenAIChatGenerator
init_parameters:
model: gpt-5.4-mini

connections:
- sender: pr_checkout.text
receiver: prompt_builder.text
- sender: prompt_builder.prompt
receiver: llm.messages

inputs:
query:
- pr_checkout.repo
- pr_checkout.pull_number

outputs:
replies: llm.replies

max_runs_per_component: 100

metadata: {}

Parameters​

Inputs​

ParameterTypeDefaultDescription
repostrThe repository in owner/repo format.
pull_numberintThe pull request number.
filesOptional[List[str]]NonePaths of changed files to show the diff of, such as files left out of an earlier call. If set, the guidelines are not returned and excluded_files does not apply.

Outputs​

ParameterTypeDescription
textstrThe pull request diff and, unless you set the files input, the repository's guideline files.
head_shastrThe SHA of the pull request's head commit.

Init Parameters​

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
github_tokenSecretSecret.from_env_var("GITHUB_TOKEN")GitHub token for the API and for fetching the code. Without a token, only public repositories can be read. Loaded when the component warms up.
checkout_dirstrrepoDirectory, relative to the working directory, that the head commit is checked out into. An earlier checkout by this component is reused for the same commit and replaced for another one. Any other non-empty directory is left untouched, and the checkout fails.
guideline_filesOptional[List[str]]NoneFiles read from the root of the base branch and returned before the diff. Defaults to AGENTS.md, CLAUDE.md, and CONTRIBUTING.md.
excluded_filesOptional[List[str]]Nonefnmatch patterns of changed files whose diff is left out, such as lockfiles. Defaults to common lockfiles and minified files.
max_diff_charsint100000Maximum number of characters of diff to return. Files past the limit are listed by name.
raise_on_failureboolTrueIf True, errors from the GitHub API raise. If False, the error message is returned as the text output.