repo_helper_github

Manage GitHub repositories with repo-helper.

Classes:

GitHubManager(token, target_repo[, …])

Subclass of repo_helper.core.RepoHelper with additional functions to update the repository metadata on GitHub.

IsolatedGitHubManager(token, username, …)

Subclass of GitHubManager which can be used isolated from the repository and its repo_helper.yml config file.

Functions:

compile_required_checks(repo)

Returns an iterator over the names of required checks for the given repository.

echo_rate_limit(github[, verbose])

Contextmanager to echo the GitHub API rate limit before and after making a series of requests.

encrypt_secret(public_key, secret_value)

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: RepoHelper

Subclass of repo_helper.core.RepoHelper with 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 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. Default False.

  • colour (Optional[bool]) – Whether to use coloured output. Default True.

Changed in version 0.3.0: Added the verbose and colour options.

Methods:

assert_matching_usernames(user)

Assert that the username configured in repo_helper.yml matches that of the authenticated user.

assert_org_member(user)

Assert that the organization configured in repo_helper.yml exists, and the authenticated user is a member.

create_labels([org])

Create labels for this repository.

echo_rate_limit()

Contextmanager to echo the GitHub API rate limit before and after making a series of requests.

get_org_or_user([org])

If org is True, returns the Organization object representing the GitHub org that owns the repository.

get_repo_kwargs()

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:

colour

Whether to use coloured output.

github

verbose

Whether to show information on the GitHub API rate limit.

assert_matching_usernames(user)[source]

Assert that the username configured in repo_helper.yml matches that of the authenticated user.

Parameters

user (User)

assert_org_member(user)[source]

Assert that the organization configured in repo_helper.yml exists, and the authenticated user is a member.

Parameters

user (User)

colour

Type:    Optional[bool]

Whether to use coloured output.

create_labels(org=False)[source]

Create labels for this repository.

New in version 0.5.0.

Parameters

org (bool) – Whether the repository should be created for the organization set as username, or for the authenticated user (default). Default False.

Return type

int

echo_rate_limit()[source]

Contextmanager to echo the GitHub API rate limit before and after making a series of requests.

get_org_or_user(org=False)[source]

If org is True, returns the Organization object representing the GitHub org that owns the repository.

If org is False, returns the AuthenticatedUser object representing the GitHub user that owns the repository.

New in version 0.3.0.

Parameters

org (bool) – Default False.

Return type

Union[Organization, User]

get_repo_kwargs()[source]

Returns the keyword arguments used when creating and updating repositories.

Return type

Dict[str, Union[str, bool]]

github

Type:    GitHub

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 as username, or for the authenticated user (default). Default False.

Return type

int

Changed in version 0.3.0:
  • Removed the verbose option. Provide it to the class constructor instead.

  • Added the org argument.

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
  • branch (str) – The branch to update protection for.

  • org (bool) – Whether the repository should be created for the organization set as username, or for the authenticated user (default). Default False.

Return type

int

Raises
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
  • org (bool) – Whether the repository should be created for the organization set as username, or for the authenticated user (default). Default False.

  • overwrite (Optional[bool]) – Overwrite existing values. Default ask first.

PYPI_TOKEN and ANACONDA_TOKEN can either be passed as keyword arguments to this function or provided at the interactive prompt.

Return type

int

Changed in version 0.4.0: Added overwrite, PYPI_TOKEN, ANACONDA_TOKEN options.

update(org=False)[source]

Update the GitHub repository for this project.

Parameters

org (bool) – Whether the repository should be created for the organization set as username, or for the authenticated user (default). Default False.

Return type

int

Changed in version 0.3.0:
  • Removed the verbose option. Provide it to the class constructor instead.

  • Added the org argument.

update_topics(repo)[source]

Update the repository’s topics.

Parameters

repo (Repository)

verbose

Type:    bool

Whether to show information on the GitHub API rate limit.

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: GitHubManager

Subclass of GitHubManager which can be used isolated from the repository and its repo_helper.yml config 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. Default False.

  • colour (Optional[bool]) – Whether to use coloured output. Default True.

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

Iterator[str]

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.Abort if 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.

Return type

Iterator[GitHub]

encrypt_secret(public_key, secret_value)[source]

Encrypt a GitHub Actions secret.

Parameters
  • public_key (str)

  • secret_value (str)

If the key has been obtained with get_secrets() then public_key will 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

str