Skip to main content

GitHubFileEditor

Edit files in GitHub repositories.

Basic Information

  • Type: haystack_integrations.components.connectors.github.file_editor.GitHubFileEditor
  • Components it can connect with:
    • Input: Receives command and payload as input.
    • GitHubRepoViewer: Works alongside to view files before editing.
    • GitHubPRCreator: Works alongside to create PRs after editing files.

Inputs

ParameterTypeDefaultDescription
commandUnion[Command, str]Operation to perform: "edit", "undo", "create", or "delete".
payloadDict[str, Any]Dictionary containing command-specific parameters.
repoOptional[str]NoneRepository in owner/repo format (overrides default if provided).
branchOptional[str]NoneBranch to perform operations on (overrides default if provided).

Outputs

ParameterTypeDefaultDescription
resultstrOperation result message.

Overview

GitHubFileEditor can edit files in GitHub repositories. It supports the following operations:

  • edit: Modify an existing file's content.
  • create: Create a file in the repository.
  • delete: Delete an existing file.
  • undo: Revert changes to a file.

This component is useful for building automated pipelines that make code changes, such as bug fix bots or documentation updaters.

Authorization

To use this component, you must create a secret with your GitHub personal access token with write access to the repository you want to edit. Type GITHUB_TOKEN as the secret key.

For detailed instructions on creating secrets, see Create Secrets.

Usage Example

This pipeline uses GitHubFileEditor to edit files in a repository:

components:
GitHubRepoViewer:
type: haystack_integrations.components.connectors.github.repo_viewer.GitHubRepoViewer
init_parameters:
github_token:
type: env_var
env_vars:
- GITHUB_TOKEN
strict: false
raise_on_failure: true
max_file_size: 1000000
repo:
branch: main

ChatPromptBuilder:
type: haystack.components.builders.chat_prompt_builder.ChatPromptBuilder
init_parameters:
template:
- role: system
content: "You are a code editor assistant. Based on the file content and the user's request, generate the updated file content."
- role: user
content: "Current file content:\n{% for doc in documents %}\n{{ doc.content }}\n{% endfor %}\n\nEdit request: {{ query }}"

OpenAIChatGenerator:
type: haystack.components.generators.chat.openai.OpenAIChatGenerator
init_parameters:
api_key:
type: env_var
env_vars:
- OPENAI_API_KEY
strict: false
model: gpt-4o

GitHubFileEditor:
type: haystack_integrations.components.connectors.github.file_editor.GitHubFileEditor
init_parameters:
github_token:
type: env_var
env_vars:
- GITHUB_TOKEN
strict: true
repo:
branch: main
raise_on_failure: true

connections:
- sender: GitHubRepoViewer.documents
receiver: ChatPromptBuilder.documents
- sender: ChatPromptBuilder.prompt
receiver: OpenAIChatGenerator.messages

inputs:
query:
- ChatPromptBuilder.query
repo:
- GitHubRepoViewer.repo
- GitHubFileEditor.repo
path:
- GitHubRepoViewer.path
branch:
- GitHubRepoViewer.branch
- GitHubFileEditor.branch
command:
- GitHubFileEditor.command
payload:
- GitHubFileEditor.payload

outputs:
result: GitHubFileEditor.result

max_runs_per_component: 100

metadata: {}

Parameters

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
github_tokenSecretSecret.from_env_var('GITHUB_TOKEN')GitHub personal access token for API authentication.
repoOptional[str]NoneDefault repository in owner/repo format.
branchstrmainDefault branch to work with.
raise_on_failureboolTrueIf True, raises exceptions on API errors.

Run Method Parameters

These are the parameters you can configure for the run() method. You can pass these parameters at query time through the API, in Playground, or when running a job.

ParameterTypeDefaultDescription
commandUnion[Command, str]Operation to perform: "edit", "undo", "create", or "delete".
payloadDict[str, Any]Dictionary containing command-specific parameters.
repoOptional[str]NoneRepository in owner/repo format (overrides default if provided).
branchOptional[str]NoneBranch to perform operations on (overrides default if provided).