2.8 KiB
GitHub Integration Tool
The GitHub Integration Tool provides a simple interface to interact with the GitHub repository for the Cyclop project. This tool allows reading files, creating branches, committing changes, and creating pull requests.
Functions
The tool provides the following functions:
read_file: Read a file from the repositorycreate_branch: Create a new branch in the repositorycommit_file: Commit a file to a branch (not main)create_pull_request: Create a pull request
Usage
To use this tool, you need to have the GITHUB_TOKEN environment variable set with your GitHub personal access token.
Read File
Reads the content of a file from the repository.
Parameters:
path: The path to the file in the repository
Example:
`python result = github_tool.execute("read_file", path="README.md") print(result) # Prints the content of README.md `
Create Branch
Creates a new branch in the repository.
Parameters:
branch_name: Name of the new branchbase_branch(optional): Name of the base branch (default is "main")
Example:
`python result = github_tool.execute("create_branch", branch_name="feature-branch") print(result) # Prints a success message if the branch was created `
Commit File
Commits a file to a specified branch (not main).
Parameters:
branch_name: Name of the branch to commit tofile_path: Path to the file in the repositorycontent: Content of the filecommit_message: Commit message
Example:
`python result = github_tool.execute( "commit_file", branch_name="feature-branch", file_path="docs/NEW_FEATURE.md", content="# New Feature\n\nThis document describes the new feature.", commit_message="Add documentation for new feature" ) print(result) # Prints a success message if the file was committed `
Create Pull Request
Creates a pull request from one branch to another.
Parameters:
title: Title of the pull requestbody: Body of the pull requesthead: The name of the branch where your changes are implementedbase(optional): The name of the branch you want the changes pulled into (default is "main")
Example:
`python result = github_tool.execute( "create_pull_request", title="Add new feature documentation", body="This PR adds documentation for the new feature.", head="feature-branch" ) print(result) # Prints the URL of the created pull request `
Error Handling
If an error occurs during the execution of any function, an error message will be returned instead of the expected result. Always check the returned value to ensure the operation was successful.
Notes
- This tool uses the GitHub API v3.
- Make sure your GitHub token has the necessary permissions to perform these operations.
- Committing directly to the main branch is not allowed for safety reasons.