repomatic.github.event module

Read the event that started a GitHub Actions workflow run.

The runner writes the event payload to the file GITHUB_EVENT_PATH names. The readers here take the defaults a command needs from it: the issue or pull request a run is about, its author and number, and the repository’s default branch.

class repomatic.github.event.WorkflowEvent(*values)[source]

Bases: StrEnum

Workflow events that cause a workflow to run.

List of events.

branch_protection_rule = 'branch_protection_rule'
check_run = 'check_run'
check_suite = 'check_suite'
create = 'create'
delete = 'delete'
deployment = 'deployment'
deployment_status = 'deployment_status'
discussion = 'discussion'
discussion_comment = 'discussion_comment'
fork = 'fork'
gollum = 'gollum'
issue_comment = 'issue_comment'
issues = 'issues'
label = 'label'
merge_group = 'merge_group'
milestone = 'milestone'
page_build = 'page_build'
project = 'project'
project_card = 'project_card'
project_column = 'project_column'
public = 'public'
pull_request = 'pull_request'
pull_request_comment = 'pull_request_comment'
pull_request_review = 'pull_request_review'
pull_request_review_comment = 'pull_request_review_comment'
pull_request_target = 'pull_request_target'
push = 'push'
registry_package = 'registry_package'
release = 'release'
repository_dispatch = 'repository_dispatch'
schedule = 'schedule'
status = 'status'
watch = 'watch'
workflow_call = 'workflow_call'
workflow_dispatch = 'workflow_dispatch'
workflow_run = 'workflow_run'
repomatic.github.event.extract_workflow_filename(workflow_ref)[source]

Extract the workflow filename from GITHUB_WORKFLOW_REF.

Parameters:

workflow_ref (str | None) – The full workflow reference, like owner/repo/.github/workflows/name.yaml@refs/heads/branch.

Return type:

str

Returns:

The workflow filename (like name.yaml), or an empty string if the reference is empty or malformed.

repomatic.github.event.get_github_event() → dict[str, Any][source]

Load the GitHub event payload from GITHUB_EVENT_PATH.

Every reader here takes a default from the payload, so a payload that cannot be read degrades to no defaults instead of failing the command.

Return type:

dict[str, Any]

Returns:

The parsed event payload, or an empty dict when the variable is unset, or the file is missing, unreadable, or holds no JSON object.

repomatic.github.event.get_event_pull_request()[source]

Return the event payload’s pull_request node, empty when absent.

Truthiness, not key presence, is the test every reader below shares. A payload carrying pull_request as an empty object has no PR to act on, and it has to read that way to is_pull_request() as well as to the default lookups, or the two would disagree on which node they read.

Return type:

dict[str, Any]

repomatic.github.event.get_event_subject()[source]

Return the issue or pull request the current event is about.

Pull requests win: the two nodes are mutually exclusive on the events these readers handle, and preferring the PR keeps the lookups reading the same node is_pull_request() reports on.

Return type:

dict[str, Any]

Returns:

The subject node, or an empty dict when the event carries neither.

repomatic.github.event.get_default_author()[source]

Get the issue/PR author from the GitHub event payload.

Return type:

str | None

repomatic.github.event.get_default_number()[source]

Get the issue/PR number from the GitHub event payload.

Return type:

int | None

repomatic.github.event.get_default_branch()[source]

Get the repository’s default branch from the GitHub event payload.

Every event that names a repository carries its default_branch, so a checkout detached at a raw SHA can still name the branch to open a pull request against.

Return type:

str | None

repomatic.github.event.is_pull_request()[source]

Check if the current event is a pull request.

Return type:

bool