review.bot.gh_interface#

Contains functions to interface with GitHub.

Module Contents#

Functions#

get_changed_files_and_contents(owner, repo, pull_number)

Retrieve the filenames, status, and contents of files changed in a GitHub PR.

Attributes#

LOG

review.bot.gh_interface.LOG#
review.bot.gh_interface.get_changed_files_and_contents(owner, repo, pull_number, gh_access_token=None)#

Retrieve the filenames, status, and contents of files changed in a GitHub PR.

Parameters:
ownerstr

The owner of the repository where the pull request was made.

repostr

The name of the repository where the pull request was made.

pull_numberint

The number of the pull request to retrieve the changed files for.

gh_access_tokenstr, optional

GitHub token needed to communicate with the repository. By default, None, which means it will try to read an existing env variable named GITHUB_TOKEN.

Returns:
list[dict]

A list of dictionaries, where each dictionary represents a file that was changed in the pull request. The dictionary contains the following keys:

  • filename: str, the name of the file

  • status: str, the status of the file change (‘added’, ‘modified’, or ‘removed’)

  • file_text: str, the contents of the file as a string

Raises:
RuntimeError

If an error occurs while fetching the file content.

Notes

This function uses the GitHub API to retrieve the list of changed files in a pull request, along with the contents of each changed file. It requires a GitHub access token with appropriate permissions to access the repository.