GitHubAPIWrapper#

class langchain_community.utilities.github.GitHubAPIWrapper[source]#

Bases: BaseModel

Wrapper for GitHub API.

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

param active_branch: str | None = None#
param github_app_id: str | None = None#
param github_app_private_key: str | None = None#
param github_base_branch: str | None = None#
param github_repository: str | None = None#
comment_on_issue(comment_query: str) str[source]#

Adds a comment to a github issue Parameters:

comment_query(str): a string which contains the issue number, two newlines, and the comment. for example: “1

Working on it now”

adds the comment “working on it now” to issue 1

Returns:

str: A success or failure message

Parameters:

comment_query (str) –

Return type:

str

create_branch(proposed_branch_name: str) str[source]#

Create a new branch, and set it as the active bot branch. Equivalent to git switch -c proposed_branch_name If the proposed branch already exists, we append _v1 then _v2… until a unique name is found.

Returns:

A plaintext success message.

Return type:

str

Parameters:

proposed_branch_name (str) –

create_file(file_query: str) str[source]#

Creates a new file on the Github repo Parameters:

file_query(str): a string which contains the file path and the file contents. The file path is the first line in the string, and the contents are the rest of the string. For example, “hello_world.md

# Hello World!”
Returns:

str: A success or failure message

Parameters:

file_query (str) –

Return type:

str

create_pull_request(pr_query: str) str[source]#

Makes a pull request from the bot’s branch to the base branch Parameters:

pr_query(str): a string which contains the PR title and the PR body. The title is the first line in the string, and the body are the rest of the string. For example, “Updated README

made changes to add info”
Returns:

str: A success or failure message

Parameters:

pr_query (str) –

Return type:

str

create_review_request(reviewer_username: str) str[source]#

Creates a review request on THE open pull request that matches the current active_branch.

Parameters:

reviewer_username (str) – The username of the person who is being requested

Returns:

A message confirming the creation of the review request

Return type:

str

delete_file(file_path: str) str[source]#

Deletes a file from the repo :param file_path: Where the file is :type file_path: str

Returns:

Success or failure message

Return type:

str

Parameters:

file_path (str) –

get_files_from_directory(directory_path: str) str[source]#

Recursively fetches files from a directory in the repo.

Parameters:

directory_path (str) – Path to the directory

Returns:

List of file paths, or an error message.

Return type:

str

get_issue(issue_number: int) Dict[str, Any][source]#

Fetches a specific issue and its first 10 comments :param issue_number: The number for the github issue :type issue_number: int

Returns:

A dictionary containing the issue’s title, body, comments as a string, and the username of the user who opened the issue

Return type:

dict

Parameters:

issue_number (int) –

get_issues() str[source]#

Fetches all open issues from the repo excluding pull requests

Returns:

A plaintext report containing the number of issues and each issue’s title and number.

Return type:

str

get_pull_request(pr_number: int) Dict[str, Any][source]#

Fetches a specific pull request and its first 10 comments, limited by max_tokens.

Parameters:
  • pr_number (int) – The number for the Github pull

  • max_tokens (int) – The maximum number of tokens in the response

Returns:

A dictionary containing the pull’s title, body, and comments as a string

Return type:

dict

list_branches_in_repo() str[source]#

Fetches a list of all branches in the repository.

Returns:

A plaintext report containing the names of the branches.

Return type:

str

list_files_in_bot_branch() str[source]#

Fetches all files in the active branch of the repo, the branch the bot uses to make changes.

Returns:

A plaintext list containing the filepaths in the branch.

Return type:

str

list_files_in_main_branch() str[source]#

Fetches all files in the main branch of the repo.

Returns:

A plaintext report containing the paths and names of the files.

Return type:

str

list_open_pull_requests() str[source]#

Fetches all open PRs from the repo

Returns:

A plaintext report containing the number of PRs and each PR’s title and number.

Return type:

str

list_pull_request_files(pr_number: int) List[Dict[str, Any]][source]#

Fetches the full text of all files in a PR. Truncates after first 3k tokens. # TODO: Enhancement to summarize files with ctags if they’re getting long.

Parameters:

pr_number (int) – The number of the pull request on Github

Returns:

A dictionary containing the issue’s title, body, and comments as a string

Return type:

dict

parse_issues(issues: List[Issue]) List[dict][source]#

Extracts title and number from each Issue and puts them in a dictionary :param issues: A list of Github Issue objects :type issues: List[Issue]

Returns:

A dictionary of issue titles and numbers

Return type:

List[dict]

Parameters:

issues (List[Issue]) –

parse_pull_requests(pull_requests: List[PullRequest]) List[dict][source]#

Extracts title and number from each Issue and puts them in a dictionary :param issues: A list of Github Issue objects :type issues: List[Issue]

Returns:

A dictionary of issue titles and numbers

Return type:

List[dict]

Parameters:

pull_requests (List[PullRequest]) –

read_file(file_path: str) str[source]#

Read a file from this agent’s branch, defined by self.active_branch, which supports PR branches. :param file_path: the file path :type file_path: str

Returns:

The file decoded as a string, or an error message if not found

Return type:

str

Parameters:

file_path (str) –

run(mode: str, query: str) str[source]#
Parameters:
  • mode (str) –

  • query (str) –

Return type:

str

search_code(query: str) str[source]#

Searches code in the repository. # Todo: limit total tokens returned…

Parameters:

query (str) – The search query

Returns:

A string containing, at most, the top 5 search results

Return type:

str

search_issues_and_prs(query: str) str[source]#

Searches issues and pull requests in the repository.

Parameters:

query (str) – The search query

Returns:

A string containing the first 5 issues and pull requests

Return type:

str

set_active_branch(branch_name: str) str[source]#

Equivalent to git checkout branch_name for this Agent. Clones formatting from Github.

Returns an Error (as a string) if branch doesn’t exist.

Parameters:

branch_name (str) –

Return type:

str

update_file(file_query: str) str[source]#

Updates a file with new content. :param file_query: Contains the file path and the file contents.

The old file contents is wrapped in OLD <<<< and >>>> OLD The new file contents is wrapped in NEW <<<< and >>>> NEW For example: /test/hello.txt OLD <<<< Hello Earth! >>>> OLD NEW <<<< Hello Mars! >>>> NEW

Returns:

A success or failure message

Parameters:

file_query (str) –

Return type:

str

Examples using GitHubAPIWrapper