PullRequestHandler

class baldrick.github.github_api.PullRequestHandler(repo, number, installation=None)

Bases: baldrick.github.github_api.IssueHandler

Attributes Summary

base_branch
base_sha
head_branch
head_repo_name
head_sha
json
last_commit_date
milestone
user

Methods Summary

get_file_contents(path_to_file[, branch]) Get the contents of a file.
get_modified_files() Get all the filenames of the files modified by this PR.
get_repo_config([branch, path_to_file, …]) Load user configuration for bot.
has_modified(filelist) Check if PR has modified any of the given list of filename(s).
list_statuses([commit_hash]) List status messages on a commit on GitHub.
set_status(state, description, context[, …]) Set status message on a commit on GitHub.
submit_review(decision, body) Submit a review comment to the pull request

Attributes Documentation

base_branch
base_sha
head_branch
head_repo_name
head_sha
json
last_commit_date
milestone
user

Methods Documentation

get_file_contents(path_to_file, branch=None)

Get the contents of a file.

This will get the file from the head branch of the PR by default.

get_modified_files()

Get all the filenames of the files modified by this PR.

get_repo_config(branch=None, path_to_file='pyproject.toml', warn_on_failure=True)

Load user configuration for bot.

Parameters:
  • branch (str) – The branch to read the config file from. (Will default to the base branch of the PR i.e. the one the PR is opened against.)
  • path_to_file (str) – Path to the pyproject.toml file in the repository. Will default to the root of the repository.
  • warn_on_failure (bool) – Emit warning on failure to load the pyproject file.
Returns:

cfg – Configuration parameters.

Return type:

dict

has_modified(filelist)

Check if PR has modified any of the given list of filename(s).

list_statuses(commit_hash='head')

List status messages on a commit on GitHub.

Parameters:commit_hash (str, optional) – The commit hash to set the status on. Defaults to “head” can also be “base”.
set_status(state, description, context, commit_hash='head', target_url=None)

Set status message on a commit on GitHub.

Parameters:
  • state ({ 'pending' | 'success' | 'error' | 'failure' }) – The state to set for the pull request.
  • description (str) – The message that appears in the status line.
  • context (str) – A string used to identify the status line.
  • commit_hash (str) – The commit hash to set the status on. Defaults to “head” can also be “base”.
  • target_url (str or None) – Link to bot comment that is relevant to this status, if given.
submit_review(decision, body)

Submit a review comment to the pull request

Parameters:
  • decision ({ 'approve' | 'request_changes' | 'comment' }) – The decision as to whether to aprove or reject the changes so far.
  • body (str) – The body of the review comment