PullRequestHandler

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

Bases: IssueHandler

Attributes Summary

base_branch

base_sha

draft

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_checks([commit_hash, only_ours])

List checks on a commit on GitHub.

list_statuses([commit_hash])

List status messages on a commit on GitHub.

set_check(external_id, title[, name, ...])

Set check status.

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
draft
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')

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.

Returns:

cfg – Configuration parameters.

Return type:

dict

has_modified(filelist)

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

list_checks(commit_hash='head', only_ours=True)

List checks on a commit on GitHub.

Parameters:
  • commit_hash (str, optional) – The commit hash to set the check on. Defaults to “head” can also be “base”.

  • only_ours (bool, optional) – Only return checks which were posted by this GitHub app.

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_check(external_id, title, name=None, summary=None, text=None, commit_hash='head', details_url=None, status=None, conclusion='neutral', check_id=None, completed_at=None)

Set check status.

Note

This method does not provide API access to full check run capability (e.g., annotation and image). Add them as needed.

Parameters:
  • external_id (str) – The internal reference for this check, used to reference the check later, to update it.

  • title (str) – The short description of the check to be put in the status line of the PR.

  • name (str, optional) – Name of the check, defaults to {bot_username}:{external_id} if not specified, is displayed first in the status line.

  • summary (str) – Summary of the check run, displays at the top of the checks page.

  • text (str, optional) – The full body of the check, displayed on the checks page.

  • commit_hash ({ 'head' | 'base' }, optional) – The SHA of the commit.

  • details_url (str or None, optional) – The URL of the integrator’s site that has the full details of the check.

  • status ({ 'queued' | 'in_progress' | 'completed' }) – The current status.

  • conclusion ({ 'success' | 'failure' | 'neutral' | 'cancelled' | 'timed_out' | 'action_required' }) – The final conclusion of the check. Required if you provide a status of 'completed'. When the conclusion is 'action_required', additional details should be provided on the site specified by 'details_url'. Note: Providing conclusion will automatically set the status parameter to 'completed'.

  • check_id (str, optional) – If specified this check will be updated rather than a new check being made.

  • completed_at (bool or datetime.datetime) – The time the check completed. If None this will not be set, if True it will be set to the time this method is called, otherwise it should be a datetime.datetime.

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 ({ 'head' | 'base' }) – 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