Skip to content

Permissions

The Permissions class controls the access levels for each GITHUB_TOKEN scope. It can be used at the workflow level or on individual jobs.

Each scope can be set to "read", "write", or "none" using the PermissionLevel enum. Only set the scopes you need; unset scopes are omitted from the output.

from ghagen.models.permissions import Permissions
from ghagen.models.common import PermissionLevel
permissions = Permissions(
contents=PermissionLevel.READ,
pull_requests=PermissionLevel.WRITE,
id_token=PermissionLevel.WRITE,
)
ParameterTypeDefaultDescription
actionsPermissionLevel | Raw[str] | NoneNonePermission for the actions scope.
checksPermissionLevel | Raw[str] | NoneNonePermission for the checks scope.
contentsPermissionLevel | Raw[str] | NoneNonePermission for the contents scope.
deploymentsPermissionLevel | Raw[str] | NoneNonePermission for the deployments scope.
discussionsPermissionLevel | Raw[str] | NoneNonePermission for the discussions scope.
id_tokenPermissionLevel | Raw[str] | NoneNonePermission for the id-token scope. Serialized as id-token.
issuesPermissionLevel | Raw[str] | NoneNonePermission for the issues scope.
packagesPermissionLevel | Raw[str] | NoneNonePermission for the packages scope.
pagesPermissionLevel | Raw[str] | NoneNonePermission for the pages scope.
pull_requestsPermissionLevel | Raw[str] | NoneNonePermission for the pull-requests scope. Serialized as pull-requests.
repository_projectsPermissionLevel | Raw[str] | NoneNonePermission for the repository-projects scope. Serialized as repository-projects.
security_eventsPermissionLevel | Raw[str] | NoneNonePermission for the security-events scope. Serialized as security-events.
statusesPermissionLevel | Raw[str] | NoneNonePermission for the statuses scope.

An enum of valid permission access levels.

from ghagen.models.common import PermissionLevel
ValueString
PermissionLevel.READ"read"
PermissionLevel.WRITE"write"
PermissionLevel.NONE"none"

A type alias used for the Workflow.permissions field, which accepts multiple forms:

PermissionsValue = Permissions | Literal["read-all", "write-all"] | Raw[str] | dict[str, str]

This allows setting permissions as:

  • A Permissions object for fine-grained control
  • "read-all" or "write-all" for blanket permissions
  • A Raw[str] for arbitrary string values
  • A plain dict[str, str] for quick inline definitions

At the workflow level, you can pass a string shorthand instead of a full Permissions object:

from ghagen import Workflow
# Blanket read-only
workflow = Workflow(
name="CI",
permissions="read-all",
# ...
)
# Fine-grained
workflow = Workflow(
name="CI",
permissions=Permissions(contents=PermissionLevel.READ),
# ...
)