GithubUtils (autotransform.util.github)

Github related utilities.

class autotransform.util.github.GithubUtils(fully_qualified_repo: str)

Bases: object

A class for utilities used to interact with Github. Stores instances of objects to prevent excessive API usage.

__instances

A mapping of repo names to Util objects.

Type

Dict[str, GithubUtils]

_api

The API object used to handle requests to Github.

Type

GhApi

BEGIN_BATCH: str = '<<<<BEGIN BATCH>>>>'
BEGIN_SCHEMA: str = '<<<<BEGIN SCHEMA>>>>'
END_BATCH: str = '<<<<END BATCH>>>>'
END_SCHEMA: str = '<<<<END SCHEMA>>>>'
create_pull_request(title: str, body: str, base: str, head: str) PullRequest

Create a pull request with the given information.

Parameters
  • title (str) – The title of the pull request.

  • body (str) – The body of the pull request.

  • base (str) – The base branch the pull request is against.

  • head (str) – The head to apply to the base branch.

Returns

The created pull request.

Return type

PullRequest

create_workflow_dispatch(workflow: str | int, ref: str, inputs: Dict[str, Any]) Optional[str]

Creates a workflow dispatch event and runs it.

Parameters
  • workflow (str | int) – The ID or filename of the workflow to run.

  • ref (str) – The ref to run the workflow on.

  • inputs (Dict[str, Any]) – Any inputs the workflow needs.

Returns

The best guess URL of the workflow run. None if failed.

Return type

Optional[str]

static get(fully_qualified_repo: str) GithubUtils

Gets an instance of the GithubUtils for a specific repo which is stored in a cache.

Parameters

fully_qualified_repo (str) – The fully qualified name of the repo, uses the format {owner}/{repo}.

Returns

A util class with a cached API object for requests.

Return type

GithubUtils

get_open_pull_requests(base: Optional[str] = None) List[PullRequest]

Gets all outstanding pull requests from the repo.

Parameters

base (Optional[str], optional) – The base branch to fetch pull requests against. Defaults to None.

Returns

The list of all requests outstanding for the repo.

Return type

List[PullRequest]

get_pull_request(pull_number: int) PullRequest

Gets a pull request from the Github API.

Parameters

pull_number (int) – The number of the pull request.

Returns

The pull request.

Return type

PullRequest

get_user_id() int

Gets the user ID of the authenticated user.

Returns

The user ID of the authenticated user.

Return type

int

class autotransform.util.github.PullRequest(api: GhApi, pull: AttrDict)

Bases: object

A wrapper around GhApi pull request response for simplified access to pull request info.

body

The body of the pull request.

Type

str

branch

The branch of the pull request.

Type

str

merged

Whether the pull request has been merged.

Type

bool

number

The number of the pull request.

Type

int

_api

The API object used to access Github’s API.

Type

GhApi

_state

The state of the pull request.

Type

str

add_labels(labels: List[str]) None

Adds a list of labels to the pull request.

Parameters

labels (List[str]) – The labels to add to the pull request.

add_reviewers(reviewers: List[str], team_reviewers: List[str]) None

Adds a list of labels to the pull request.

Parameters
  • reviewers (List[str]) – The reviewers to request for the pull request.

  • team_reviewers (List[str]) – The team reviewers to request for the pull request.

body: str
branch: str
close() bool

Closes the pull request.

Returns

Whether the update happened successfully.

Return type

bool

create_comment(body: str) None

Adds a comment to the pull request.

Parameters

body (str) – The body of the comment.

delete_branch() bool

Deletes the branch associated with the pull request.

Returns

Whether the deletion was successful.

Return type

bool

get_created_at() int

Gets the created at timestamp.

Returns

The timestamp for when the pull request was created.

Return type

int

static get_from_number(api: GhApi, pull_number: int) PullRequest

Gets a pull request with the given number.

Parameters
  • api (GhApi) – The API object used to access Github’s API.

  • pull_number (int) – The number of the pull request.

Returns

The pull request associated with the number.

Return type

PullRequest

get_labels() List[str]

Gets the labels for a Pull Request.

Returns

The labels for a Pull Request.

Return type

List[str]

get_review_state() Optional[str]

The state of the most recent review, only checking reviews that are “APPROVED” or “CHANGES_REQUESTED”. If there are no approving or change_requested reviews, returns None.

Returns

The state of the review.

Return type

Optional[str]

get_reviewers() List[str]

Gets the requested reviewers for a Pull Request.

Returns

The requested reviewers for a Pull Request.

Return type

List[str]

get_team_reviewers() List[str]

Gets the requested team reviewers for a Pull Request.

Returns

The requested team reviewers for a Pull Request.

Return type

List[str]

get_updated_at() int

Gets the updated at timestamp.

Returns

The timestamp for when the pull request was updated.

Return type

int

is_closed() bool

A simple check if the pull request is closed.

Returns

Whether the pull request is closed.

Return type

bool

is_open() bool

A simple check if the pull request is open.

Returns

Whether the pull request is open.

Return type

bool

merge() bool

Merges the pull request.

Returns

Whether the pull request was successfully merged.

Return type

bool

merged: bool
number: int
owner_id: int
remove_label(label: str) None

Removes a label from the pull request.

Parameters

label (str) – The label to remove from the pull request.