gitapi#

showyourwork.gitapi.clear_cache(name, org=None)#

Clear the Actions cache for a repository.

Parameters
  • name (str) – The name of the repository (without the user).

  • org (str, optional) – Name of the organization (if applicable). Default is None.

showyourwork.gitapi.create_repo(name, description=None, private=False, org=None)#

Create a new repository on GitHub if it does not already exist.

Parameters
  • name (str) – The name of the repository (without the user).

  • private (bool, optional) – Set to True for private repos. Default False.

  • org (str, optional) – Name of the organization (if applicable). Default is None.

showyourwork.gitapi.delete_repo(name, org=None, quiet=False)#

Delete a repository on GitHub.

Parameters
  • name (str) – The name of the repository (without the user).

  • org (str, optional) – Name of the organization (if applicable). Default is None.

  • quiet (bool, optional) – Default False.

showyourwork.gitapi.flatten_dict(d, parent_key='', sep='__')#

Flatten a nested dictionary.

Adapted from https://stackoverflow.com/a/6027615.

showyourwork.gitapi.get_access_token(token_name='GH_API_KEY', error_if_missing=False)#

Return the access token stored in the environment variable token_name.

Parameters
  • token_name (str, optional) – Name of the environment variable containing the GitHub API token. Default is GH_API_KEY.

  • error_if_missing (bool, optional) – Raise an error if the environment variable is not defined or empty? Default False.

showyourwork.gitapi.get_authenticated_user()#

Return the name of the current authenticated GitHub user.

showyourwork.gitapi.get_workflow_run_status(name, org=None, q={})#

Checks the status of the latest GH Actions workflow run for a repository, optionally matching certain search criteria.

Parameters
  • name (str) – The name of the repository (without the user).

  • org (str, optional) – The name of the organization (if applicable). Default is None.

  • q (dict, optional) – Search query, a dictionary containing all the key-value pairs to be matched in the JSON response of the workflow search. Nested dictionaries are allowed.

Returns

A tuple containing (status, conclusion, url).

Return type

tuple

The status is one of

  • queued

  • in_progress

  • completed

The conclusion is one of

  • action_required

  • cancelled

  • failure

  • neutral

  • success

  • skipped

  • stale

  • timed_out

If the workflow is not found, both are set to unknown.

The url is that of the workflow on GitHub actions.