repo_helper_github¶
Manage GitHub repositories with repo-helper.
Classes:
|
Subclass of |
|
Subclass of |
Functions:
|
Returns an iterator over the names of required checks for the given repository. |
|
Contextmanager to echo the GitHub API rate limit before and after making a series of requests. |
|
Encrypt a GitHub Actions secret. |
-
class
GitHubManager(token, target_repo, managed_message="This file is managed by 'repo_helper'. Don't edit it directly.", *, verbose=False, colour=True)[source]¶ Bases:
RepoHelperSubclass of
repo_helper.core.RepoHelperwith additional functions to update the repository metadata on GitHub.- Parameters
token (
str) – The token to authenticate with the GitHub API.target_repo (
Union[str,Path,PathLike]) – The path to the root of the repository to manage files for.managed_message (
str) – Message placed at the top of files to indicate that they are managed byrepo_helper. Default"This file is managed by 'repo_helper'. Don't edit it directly.".verbose (
bool) – Whether to show information on the GitHub API rate limit. DefaultFalse.colour (
Optional[bool]) – Whether to use coloured output. DefaultTrue.
Changed in version 0.3.0: Added the
verboseandcolouroptions.Methods:
Assert that the username configured in
repo_helper.ymlmatches that of the authenticated user.assert_org_member(user)Assert that the organization configured in
repo_helper.ymlexists, and the authenticated user is a member.create_labels([org])Create labels for this repository.
Contextmanager to echo the GitHub API rate limit before and after making a series of requests.
get_org_or_user([org])If
orgisTrue, returns theOrganizationobject representing the GitHub org that owns the repository.Returns the keyword arguments used when creating and updating repositories.
new([org])Create a new GitHub repository for this project.
protect_branch(branch[, org])Update branch protection for the given branch.
secrets([org, overwrite, PYPI_TOKEN, …])Set or update the secrets of the GitHub repository for this project.
update([org])Update the GitHub repository for this project.
update_topics(repo)Update the repository’s topics.
Attributes:
Whether to use coloured output.
Whether to show information on the GitHub API rate limit.
-
assert_matching_usernames(user)[source]¶ Assert that the username configured in
repo_helper.ymlmatches that of the authenticated user.- Parameters
user (
User)
-
assert_org_member(user)[source]¶ Assert that the organization configured in
repo_helper.ymlexists, and the authenticated user is a member.- Parameters
user (
User)
-
echo_rate_limit()[source]¶ Contextmanager to echo the GitHub API rate limit before and after making a series of requests.
- Return type
-
get_org_or_user(org=False)[source]¶ If
orgisTrue, returns theOrganizationobject representing the GitHub org that owns the repository.If
orgisFalse, returns theAuthenticatedUserobject representing the GitHub user that owns the repository.New in version 0.3.0.
- Parameters
- Return type
-
get_repo_kwargs()[source]¶ Returns the keyword arguments used when creating and updating repositories.
-
new(org=False)[source]¶ Create a new GitHub repository for this project.
- Parameters
org (
bool) – Whether the repository should be created for the organization set asusername, or for the authenticated user (default). DefaultFalse.- Return type
Changed in version 0.3.0:Removed the
verboseoption. Provide it to the class constructor instead.Added the
orgargument.
-
protect_branch(branch, org=False)[source]¶ Update branch protection for the given branch.
This requires that the Linux and Windows tests pass, together with the mypy check.
New in version 0.4.0.
- Parameters
- Return type
- Raises
NoSuchBranchif the branch is not found.NoSuchRepositoryif the repository is not found.
-
secrets(org=False, overwrite=None, PYPI_TOKEN=None, ANACONDA_TOKEN=None)[source]¶ Set or update the secrets of the GitHub repository for this project.
New in version 0.3.0.
- Parameters
PYPI_TOKENandANACONDA_TOKENcan either be passed as keyword arguments to this function or provided at the interactive prompt.- Return type
Changed in version 0.4.0: Added
overwrite,PYPI_TOKEN,ANACONDA_TOKENoptions.
-
update(org=False)[source]¶ Update the GitHub repository for this project.
- Parameters
org (
bool) – Whether the repository should be created for the organization set asusername, or for the authenticated user (default). DefaultFalse.- Return type
Changed in version 0.3.0:Removed the
verboseoption. Provide it to the class constructor instead.Added the
orgargument.
-
update_topics(repo)[source]¶ Update the repository’s topics.
- Parameters
repo (
Repository)
-
class
IsolatedGitHubManager(token, username, repo_name, *, managed_message="This file is managed by 'repo_helper'. Don't edit it directly.", verbose=False, colour=True)[source]¶ Bases:
GitHubManagerSubclass of
GitHubManagerwhich can be used isolated from the repository and itsrepo_helper.ymlconfig file.New in version 0.4.0.
- Parameters
token (
str) – The token to authenticate with the GitHub API.username (
str) – The username of the GitHub account hosting the repository.repo_name (
str) – The name of GitHub repository.managed_message – Message placed at the top of files to indicate that they are managed by
repo_helper. Default"This file is managed by 'repo_helper'. Don't edit it directly.".verbose (
bool) – Whether to show information on the GitHub API rate limit. DefaultFalse.colour (
Optional[bool]) – Whether to use coloured output. DefaultTrue.
-
compile_required_checks(repo)[source]¶ Returns an iterator over the names of required checks for the given repository.
New in version 0.4.0.
- Parameters
repo (
RepoHelper)- Return type
-
echo_rate_limit(github, verbose=True)[source]¶ Contextmanager to echo the GitHub API rate limit before and after making a series of requests.
- Parameters
- Raises
click.Abortif the rate limit has been exceeded.
Deprecated since version 0.5.0: This will be removed in 1.0.0. Use the new ‘github3-utils’ package instead.
-
encrypt_secret(public_key, secret_value)[source]¶ Encrypt a GitHub Actions secret.
If the key has been obtained with
get_secrets()thenpublic_keywill be:get_secrets(repo)['key']
Deprecated since version 0.5.0: This will be removed in 1.0.0. Use the new ‘github3-utils’ package instead.
- Return type