github3_utils.apps

Functions and classes for GitHub apps.

Classes:

ContextSwitcher(client, private_key_pem, app_id)

Class to aid switching contexts between the app itself and its installations.

Functions:

iter_installed_repos(*[, context_switcher, …])

Returns an iterator over all repositories the app is installed for.

make_footer_links(owner, name[, event_date, …])

Create markdown footer links for a GitHub app.

class ContextSwitcher(client, private_key_pem, app_id)[source]

Bases: object

Class to aid switching contexts between the app itself and its installations.

Parameters
  • client (GitHub)

  • private_key_pem (bytes) – The bytes of the private key for this GitHub App.

  • app_id (int) – The integer identifier for this GitHub App.

Attributes:

app_id

The integer identifier for this GitHub App.

client

private_key_pem

The bytes of the private key for this GitHub App.

Methods:

login_as_app()

Login as the GitHub app.

login_as_org_installation(organization)

Login as an organization installation of a GitHub app, and return its installation ID.

login_as_repo_installation(owner, repository)

Login as a repository installation of a GitHub app, and return its installation ID.

login_as_user_installation(username)

Login as a user installation of a GitHub app, and return its installation ID.

app_id

Type:    int

The integer identifier for this GitHub App.

client

Type:    GitHub

login_as_app()[source]

Login as the GitHub app.

login_as_org_installation(organization)[source]

Login as an organization installation of a GitHub app, and return its installation ID.

New in version 0.5.0.

Parameters

organization (str)

Return type

int

login_as_repo_installation(owner, repository)[source]

Login as a repository installation of a GitHub app, and return its installation ID.

Parameters
  • owner (str)

  • repository (str)

Return type

int

login_as_user_installation(username)[source]

Login as a user installation of a GitHub app, and return its installation ID.

Parameters

username (str)

Return type

int

private_key_pem

Type:    bytes

The bytes of the private key for this GitHub App.

iter_installed_repos(*, context_switcher=None, client=None, private_key_pem=None, app_id=None)[source]

Returns an iterator over all repositories the app is installed for.

Parameters

Either context_switcher or all of client, private_key_pem and app_id must be provided.

Return type

Iterator[Dict]

Create markdown footer links for a GitHub app.

Parameters
  • owner (str) – The owner of the repository.

  • name (str) – The name of the repository.

  • event_date (Optional[date]) – The date on which the footer is being created. Determines the emoji shown. Default None.

  • type (Literal['marketplace', 'app']) – Whether the footer is for a GitHub app or an item in the marketplace. Default 'marketplace'.

  • docs_url (Optional[str]) – The URL of the app’s documentation. If None no link will be shown. Default None.

New in version 0.3.0.

Return type

str