GithubUtils (autotransform.util.github)
Github related utilities.
- class autotransform.util.github.Gist(api: GhApi, gist_id: str)
Bases:
object
A wrapper around GhApi gist response for simplified access to gist info.
- id
The id of the gist.
- Type:
str
- _api
The API object used to access Github’s API.
- Type:
GhApi
- get_description() str
Gets the description of the gist.
- Returns:
The description of the gist.
- Return type:
str
- get_file_content(file_name: str) str | None
Gets the content of the requested file within the gist.
- Parameters:
file_name (str) – The name of the file to get the content for.
- Returns:
- The contents of the file. None if the gist does not have a file with
the supplied name.
- Return type:
Optional[str]
- gist_id: str
- 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
- _fully_qualified_repo
The fully qualified name of the Github repo.
- Type:
str
- _pulls
A mapping from pull number to PullRequest.
- Type:
Dict[int, PullRequest]
- BEGIN_BATCH: str = '<<<<BEGIN BATCH>>>>'
- BEGIN_SCHEMA: str = '<<<<BEGIN SCHEMA>>>>'
- END_BATCH: str = '<<<<END BATCH>>>>'
- END_SCHEMA: str = '<<<<END SCHEMA>>>>'
- create_gist(files: Dict[str, Dict[str, str]], description: str, public: bool = True) Gist
Creates a Gist containing the supplied information
- Parameters:
files (Dict[str, Dict[str, str]]) – The files to include in the gist.
description (str) – A simple description of the gist.
public (bool, optional) – Whether the gist should be public. Defaults to True.
- Returns:
The created gist.
- Return type:
- 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:
- create_workflow_dispatch(workflow: str | int, ref: str, inputs: Dict[str, Any]) str | None
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:
- get_gist(gist_id: str) Gist
Gets a wrapper around the requested gist.
- Parameters:
gist_id (str) – The id of the gist.
- Returns:
The requested gist.
- Return type:
- get_open_pull_requests(base: str | None = 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.
- Parameters:
pull_number (int) – The number of the pull request.
- Returns:
The pull request.
- Return type:
- 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_number: int)
Bases:
object
A wrapper around GhApi pull request response for simplified access to pull request info.
- number
The number of the pull request.
- Type:
int
- _api
The API object used to access Github’s API.
- Type:
GhApi
- 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.
- property body: str
Gets the body of the pull request.
- Returns:
The body of the pull request.
- Return type:
str
- property branch: str
Gets the name of the head branch for the pull request.
- Returns:
The name of the head branch.
- Return type:
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
- get_labels() List[str]
Gets the labels for a Pull Request.
- Returns:
The labels for a Pull Request.
- Return type:
List[str]
- get_mergeable_state() str
Gets the mergeable state of the PR.
- Returns:
The mergeable state.
- Return type:
str
- get_review_state() str | None
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_test_state() str | None
Gets the state of tests on the PR using the checks API.
- Returns:
The combined state of test runs.
- Return type:
Optional[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
- property merged: bool
Whether the pull request has been merged.
- Returns:
Whether the pull request was merged.
- Return type:
bool
- number: int
- property owner_id: int
The ID of the user that created the pull request.
- Returns:
The ID of the owner of the pull request.
- Return type:
int
- remove_label(label: str) None
Removes a label from the pull request.
- Parameters:
label (str) – The label to remove from the pull request.