github_repo¶
Manage GitHub repositories within an organization or user account: listing and creation as well as, per repository, settings, teams, issues, milestones, pull requests, rulesets, deploy keys, Actions secrets and settings, environments, labels and Pages.
Added in version 1.1.0.
Unlike the legacy functions in the github module,
the functions in this module raise errors (usually subclasses of
CommandExecutionError)
instead of logging them and returning False.
Collections with a unique natural key (repositories, teams, Actions secrets, environments, labels) are returned as mappings keyed by it, id-addressed collections (issues, pull requests, milestones, rulesets, deploy keys, deployment branch policies) as lists.
Note
This module works on repositories of any owner (organization or
user): all functions accept an owner argument that defaults to
the profile’s owner. Teams always belong to the owning
organization, and repository creation (create, the creating branch
of the github_repo.present state) is only supported for
organizations and the authenticated user, a GitHub API limitation.
- depends:
PyGithub python module
Configuration¶
This module reads its configuration from profiles, which are described
in the configuration guide. The
repository-scoped functions operate on the repository named in
repo_name, which is required unless a default is set in the
profile (repo_name).
- saltext.github.modules.github_repo.list_(private=None, owner=None, fields=None, ignore_cache=False, profile='github')[source]¶
List all repositories of an owner the profile token can see, as a mapping of repository name to details.
CLI Example:
salt-call github_repo.list salt-call github_repo.list private=true
- private
Only list private (
true) or public (false) repositories. By default, all repositories are listed.- owner
Owner (organization or user) whose repositories to list. Defaults to the profile’s
owner. Private repositories of users other than the authenticated one are not visible.- fields
Only include these fields in the output. A single field name reduces each entry to the field’s value.
- ignore_cache
Bypass the use of cached repositories.
- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.create(repo_name=None, description=None, homepage=None, private=None, has_issues=None, has_wiki=None, has_downloads=None, auto_init=None, gitignore_template=None, license_template=None, owner=None, profile='github')[source]¶
Create a new repository. Returns information about the created repository.
CLI Example:
salt-call github_repo.create my-repo
- repo_name
Name of the repository to create. Defaults to the profile’s
repo_name.- description
Repository description.
- homepage
URL with more information about the repository, e.g. rendered docs.
- private
Repository visibility.
- has_issues
Enable issues for this repository.
- has_wiki
Enable the wiki for this repository.
- has_downloads
Enable downloads for this repository.
- auto_init
Create an initial commit with an empty README.
- gitignore_template
Desired language or platform for a .gitignore, e.g. “Haskell”.
- license_template
Desired LICENSE template to apply, e.g. “mit” or “mozilla”.
- owner
Owner to create the repository for. Defaults to the profile’s
owner. The GitHub API only supports creating repositories for organizations and the authenticated user.- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.info(repo_name=None, owner=None, ignore_cache=False, profile='github')[source]¶
Return information about a repository.
CLI Example:
salt-call github_repo.info my-repo
- saltext.github.modules.github_repo.get_teams(repo_name=None, owner=None, fields=None, profile='github')[source]¶
Return the teams a repository belongs to, as a mapping of team name to details.
CLI Example:
salt-call github_repo.get_teams my-repo
- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- fields
Only include these fields in the output. A single field name reduces each entry to the field’s value.
- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.update(repo_name=None, owner=None, description=None, homepage=None, private=None, has_issues=None, has_wiki=None, has_downloads=None, default_branch=None, profile='github')[source]¶
Update repository settings. Returns the refreshed repository information.
CLI Example:
salt-call github_repo.update my-repo description='Managed by Salt'
- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- description
Repository description.
- homepage
URL with more information about the repository, e.g. rendered docs.
- private
Repository visibility. Changing this requires
allow_repo_privacy_changesto be enabled in the profile.- has_issues
Enable issues for this repository.
- has_wiki
Enable the wiki for this repository.
- has_downloads
Enable downloads for this repository.
- default_branch
Default branch of the repository. Must already exist: Ignored during repo creation.
- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.delete(repo_name=None, owner=None, profile='github')[source]¶
Delete a repository.
CLI Example:
salt-call github_repo.delete my-repo
- saltext.github.modules.github_repo.list_issues(repo_name=None, owner=None, milestone=None, state='open', assignee=None, creator=None, mentioned=None, labels=None, sort='created', direction='desc', since=None, per_page=None, fields=None, profile='github')[source]¶
Return the issues in the repository, based on the search options. Pull requests are excluded.
CLI Example:
salt-call github_repo.list_issues my-repo
- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- milestone
Number of a GitHub milestone, or a string of either
*ornone.- state
Filter returned issues by their state. Can be either
open,closed, orall. Default isopen.- assignee
Filter returned issues by assigned user handle. Pass
none(as a string) for issues with no assigned user or*for issues assigned to any user.- creator
Filter by the username that created the issue.
- mentioned
Filter issues for a user that’s mentioned in the issue.
- labels
Filter issues by associated labels. String of comma separated label names. For example,
bug,ui,@high.- sort
Field to sort results by. Either
created,updated, orcomments. Default iscreated.- direction
Sort direction. Either
ascordesc. Default isdesc.- since
Only list issues updated at or after this time. This is a timestamp in ISO 8601 format:
YYYY-MM-DDTHH:MM:SSZ.- per_page
Pagination size, maximum 100.
- fields
Only include these fields in the output. A single field name reduces each entry to the field’s value.
- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.get_issue(number, repo_name=None, owner=None, profile='github')[source]¶
Return information about a single issue in the repository.
CLI Example:
salt-call github_repo.get_issue 514
- saltext.github.modules.github_repo.get_issue_comments(number, repo_name=None, owner=None, since=None, profile='github')[source]¶
Return the comments of an issue in the repository.
CLI Example:
salt-call github_repo.get_issue_comments 514
- number
Issue number for which to retrieve comments.
- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- since
Only return comments updated at or after this time. This is a timestamp in ISO 8601 format:
YYYY-MM-DDTHH:MM:SSZ.- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.list_milestones(repo_name=None, owner=None, state='open', sort='due_on', direction='asc', per_page=None, fields=None, profile='github')[source]¶
Return the existing repository milestones.
CLI Example:
salt-call github_repo.list_milestones my-repo
- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- state
Filter milestones by their state. Either
open,closed, orall. Default isopen.- sort
Field to sort results by. Either
due_onorcompleteness. Default isdue_on.- direction
Sort direction. Either
ascordesc. Default isasc.- per_page
Pagination size, maximum 100.
- fields
Only include these fields in the output. A single field name reduces each entry to the field’s value.
- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.get_milestone(number=None, name=None, repo_name=None, owner=None, profile='github')[source]¶
Return information about a single milestone in the repository.
CLI Example:
salt-call github_repo.get_milestone 72 salt-call github_repo.get_milestone name=my_milestone
- saltext.github.modules.github_repo.list_pulls(repo_name=None, owner=None, state='open', head=None, base=None, sort='created', direction='desc', per_page=None, fields=None, profile='github')[source]¶
Return the pull requests in the repository, based on the search options.
CLI Example:
salt-call github_repo.list_pulls my-repo
- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- state
Filter returned pull requests by their state. Can be either
open,closed, orall. Default isopen.- head
Filter pull requests by head user and branch name in the format
user:ref-name.- base
Filter pulls by base branch name, e.g.
gh-pages.- sort
Field to sort results by. Either
created,updated,popularity(comment count), orlong-running(age, filtering by pull requests updated within the last month). Default iscreated.- direction
Sort direction. Either
ascordesc. Default isdesc.- per_page
Pagination size, maximum 100.
- fields
Only include these fields in the output. A single field name reduces each entry to the field’s value.
- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.list_rulesets(repo_name=None, owner=None, per_page=None, fields=None, profile='github')[source]¶
List all rulesets of the repository.
CLI Example:
salt-call github_repo.list_rulesets my-repo
- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- per_page
Pagination size, maximum 100.
- fields
Only include these fields in the output. A single field name reduces each entry to the field’s value.
- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.get_ruleset(ruleset_id, repo_name=None, owner=None, profile='github')[source]¶
Return the data of a single repository ruleset.
CLI Example:
salt-call github_repo.get_ruleset 1234 repo_name=my-repo
- saltext.github.modules.github_repo.add_ruleset(ruleset_params, repo_name=None, owner=None, profile='github')[source]¶
Create a new repository ruleset. Returns the data of the created ruleset.
CLI Example:
salt-call github_repo.add_ruleset '{name: test, enforcement: active}' repo_name=my-repo
- saltext.github.modules.github_repo.update_ruleset(ruleset_id, ruleset_params, repo_name=None, owner=None, profile='github')[source]¶
Update an existing repository ruleset. Returns the data of the updated ruleset.
CLI Example:
salt-call github_repo.update_ruleset 1234 '{enforcement: disabled}' repo_name=my-repo
- saltext.github.modules.github_repo.delete_ruleset(ruleset_id, repo_name=None, owner=None, profile='github')[source]¶
Delete a repository ruleset.
CLI Example:
salt-call github_repo.delete_ruleset 1234 repo_name=my-repo
- saltext.github.modules.github_repo.list_deploy_keys(repo_name=None, owner=None, fields=None, profile='github')[source]¶
List the deploy keys of a repository.
CLI Example:
salt-call github_repo.list_deploy_keys my-repo
- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- fields
Only include these fields in the output. A single field name reduces each entry to the field’s value.
- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.get_deploy_key(key_id, repo_name=None, owner=None, profile='github')[source]¶
Return the data of a single deploy key of a repository.
CLI Example:
salt-call github_repo.get_deploy_key 12345 repo_name=my-repo
- saltext.github.modules.github_repo.add_deploy_key(title, key, read_only=False, repo_name=None, owner=None, profile='github')[source]¶
Add a deploy key to a repository. Returns the data of the created key.
Note
Deploy keys are immutable. To modify one, remove it and add a replacement.
CLI Example:
salt-call github_repo.add_deploy_key autorelease 'ssh-ed25519 AAAA...' read_only=false repo_name=my-repo
- title
Display title of the deploy key.
- key
SSH public key.
- read_only
Deny write access to the repository for this key. Defaults to false.
- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.remove_deploy_key(key_id, repo_name=None, owner=None, profile='github')[source]¶
Remove a deploy key from a repository.
CLI Example:
salt-call github_repo.remove_deploy_key 12345 repo_name=my-repo
- saltext.github.modules.github_repo.list_actions_secrets(repo_name=None, owner=None, fields=None, profile='github')[source]¶
List the Actions secrets of a repository, as a mapping of secret name to metadata. Secret values are write-only, so this only returns metadata (
created_at,updated_at).CLI Example:
salt-call github_repo.list_actions_secrets my-repo
- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- fields
Only include these fields in the output. A single field name reduces each entry to the field’s value.
- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.get_actions_secret(name, repo_name=None, owner=None, profile='github')[source]¶
Return the metadata of a single Actions secret of a repository. The value itself is write-only and cannot be retrieved.
CLI Example:
salt-call github_repo.get_actions_secret MY_SECRET repo_name=my-repo
- saltext.github.modules.github_repo.set_actions_secret(name, value, repo_name=None, owner=None, profile='github')[source]¶
Create or update an Actions secret of a repository. The value is encrypted to the repository public key before leaving the minion.
CLI Example:
salt-call github_repo.set_actions_secret MY_SECRET hunter2 repo_name=my-repo
- saltext.github.modules.github_repo.remove_actions_secret(name, repo_name=None, owner=None, profile='github')[source]¶
Remove an Actions secret from a repository.
CLI Example:
salt-call github_repo.remove_actions_secret MY_SECRET repo_name=my-repo
- saltext.github.modules.github_repo.get_workflow_permissions(repo_name=None, owner=None, profile='github')[source]¶
Return the default workflow permissions granted to the
GITHUB_TOKENin a repository, a mapping withdefault_workflow_permissions(read/write) andcan_approve_pull_request_reviews.CLI Example:
salt-call github_repo.get_workflow_permissions my-repo
- saltext.github.modules.github_repo.set_workflow_permissions(default_workflow_permissions=None, can_approve_pull_request_reviews=None, repo_name=None, owner=None, profile='github')[source]¶
Update the default workflow permissions granted to the
GITHUB_TOKENin a repository.CLI Example:
salt-call github_repo.set_workflow_permissions read can_approve_pull_request_reviews=true repo_name=my-repo
- default_workflow_permissions
Default permissions for the
GITHUB_TOKEN, eitherreadorwrite.- can_approve_pull_request_reviews
Allow GitHub Actions to approve pull requests.
- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.list_environments(repo_name=None, owner=None, fields=None, profile='github')[source]¶
List the environments of a repository, as a mapping of environment name to details.
CLI Example:
salt-call github_repo.list_environments my-repo
- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- fields
Only include these fields in the output. A single field name reduces each entry to the field’s value.
- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.get_environment(name, repo_name=None, owner=None, profile='github')[source]¶
Return the data of a single environment of a repository.
CLI Example:
salt-call github_repo.get_environment release repo_name=my-repo
- saltext.github.modules.github_repo.set_environment(name, wait_timer=None, prevent_self_review=None, reviewers=None, deployment_branch_policy=None, repo_name=None, owner=None, profile='github')[source]¶
Create or update an environment of a repository, replacing its whole configuration. Unspecified settings are reset to their defaults. Returns the data of the environment.
CLI Example:
salt-call github_repo.set_environment release repo_name=my-repo \ deployment_branch_policy='{protected_branches: false, custom_branch_policies: true}'
- name
Name of the environment.
- wait_timer
Amount of time to delay a job after it is initially triggered, in minutes.
- prevent_self_review
Prevent a user who created a job from approving it.
- reviewers
People or teams that may review jobs that reference the environment, as a list of mappings with
type(UserorTeam) andid.- deployment_branch_policy
Type of deployment branch policy for this environment, either
null(default) to allow all branches or a mapping withprotected_branchesandcustom_branch_policiesbooleans. Branch name patterns for custom policies are managed separately, seegithub_repo.add_deployment_branch_policy.- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.remove_environment(name, repo_name=None, owner=None, profile='github')[source]¶
Remove an environment from a repository.
CLI Example:
salt-call github_repo.remove_environment release repo_name=my-repo
- saltext.github.modules.github_repo.list_deployment_branch_policies(environment, repo_name=None, owner=None, fields=None, profile='github')[source]¶
List the deployment branch policies of an environment.
CLI Example:
salt-call github_repo.list_deployment_branch_policies release repo_name=my-repo
- environment
Name of the environment.
- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- fields
Only include these fields in the output. A single field name reduces each entry to the field’s value.
- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.add_deployment_branch_policy(environment, name, typ='branch', repo_name=None, owner=None, profile='github')[source]¶
Add a deployment branch (or tag) policy to an environment. Returns the data of the created policy.
The environment’s
deployment_branch_policymust havecustom_branch_policiesenabled.CLI Example:
salt-call github_repo.add_deployment_branch_policy release main repo_name=my-repo
- environment
Name of the environment.
- name
Name pattern that branches (or tags) must match in order to deploy to the environment.
- typ
Target of this rule, either
branchortag. Defaults tobranch.- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.remove_deployment_branch_policy(environment, policy_id, repo_name=None, owner=None, profile='github')[source]¶
Remove a deployment branch policy from an environment.
CLI Example:
salt-call github_repo.remove_deployment_branch_policy release 12345 repo_name=my-repo
- saltext.github.modules.github_repo.list_labels(repo_name=None, owner=None, fields=None, profile='github')[source]¶
List the labels of a repository, as a mapping of label name to details.
CLI Example:
salt-call github_repo.list_labels my-repo
- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- fields
Only include these fields in the output. A single field name reduces each entry to the field’s value.
- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.get_label(name, repo_name=None, owner=None, profile='github')[source]¶
Return the data of a single label of a repository.
CLI Example:
salt-call github_repo.get_label bug repo_name=my-repo
- saltext.github.modules.github_repo.add_label(name, color=None, description=None, repo_name=None, owner=None, profile='github')[source]¶
Create a label in a repository. Returns the data of the created label.
CLI Example:
salt-call github_repo.add_label release color=00ff00 repo_name=my-repo
- name
Name of the label.
- color
Hexadecimal color code for the label, without the leading
#. If unset, GitHub assigns a random one.- description
Short description of the label.
- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.edit_label(name, new_name=None, color=None, description=None, repo_name=None, owner=None, profile='github')[source]¶
Update an existing label of a repository. Returns the data of the updated label.
CLI Example:
salt-call github_repo.edit_label release color=00ff00 repo_name=my-repo
- name
Current name of the label.
- new_name
New name for the label.
- color
Hexadecimal color code for the label, without the leading
#.- description
Short description of the label.
- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.remove_label(name, repo_name=None, owner=None, profile='github')[source]¶
Delete a label from a repository.
CLI Example:
salt-call github_repo.remove_label release repo_name=my-repo
- saltext.github.modules.github_repo.get_pages(repo_name=None, owner=None, profile='github')[source]¶
Return information about the GitHub Pages site of a repository.
CLI Example:
salt-call github_repo.get_pages my-repo
- saltext.github.modules.github_repo.setup_pages(build_type=None, source_branch=None, source_path=None, repo_name=None, owner=None, profile='github')[source]¶
Configure a GitHub Pages site for a repository. Returns the data of the created site.
CLI Example:
salt-call github_repo.setup_pages build_type=workflow repo_name=my-repo
- build_type
Process by which the site is built, either
legacy(deploy from a branch) orworkflow(GitHub Actions).- source_branch
For
legacybuilds, the repository branch to publish from.- source_path
For
legacybuilds, the repository directory to publish from, either/or/docs.- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- profile
Profile configuration name to use. Defaults to
github.
- saltext.github.modules.github_repo.update_pages(build_type=None, source_branch=None, source_path=None, cname=Ellipsis, https_enforced=None, repo_name=None, owner=None, profile='github')[source]¶
Update the GitHub Pages site configuration of a repository.
CLI Example:
salt-call github_repo.update_pages build_type=workflow repo_name=my-repo
- build_type
Process by which the site is built, either
legacy(deploy from a branch) orworkflow(GitHub Actions).- source_branch
For
legacybuilds, the repository branch to publish from.- source_path
For
legacybuilds, the repository directory to publish from, either/or/docs.- cname
Custom domain for the site. Pass
nullexplicitly to remove it, omit to leave it unchanged.- https_enforced
Enforce HTTPS for the site.
- repo_name
Name of the repository. Defaults to the profile’s
repo_name.- owner
Owner of the repository. Defaults to the profile’s
owner.- profile
Profile configuration name to use. Defaults to
github.