GitHubClient
NOTE: GitHub extensive document on how to generation tokens here.
Once generated, you may base64 encode it however you wish. However, it should be noted that such tokens need to be treated with the upmost secrecy. If you are using this library via GitHub Actions it is thus recommended instead to:
- Auto-generate a limited access token as per the docs
- Use JWT to generate a limited access token
- Fine-grain your organisational access to a secret access token
Bases: IClient
This is our primary interface for interacting with the GitHub RESTAPI.
It requires a bearer token for authentication, base64 encoded
as user:token
. This may either:
- Be exported to the
GITHUB_TOKEN
environment variable - Passed explicitly to the constructor
Attributes:
Name | Type | Description |
---|---|---|
client |
Session
|
object created by |
Example
With an explicit token provided:
from sudoblark_python_core import GitHubClient
client = GitHubClient("<TOKEN>")
When GITHUB_TOKEN
is a known environment variable:
from sudoblark_python_core import GitHubClient
client = GitHubClient()
__post__init__()
Overwritten IClient method to execute at the end of IClient init, mutates headers etc to be those recommended for GitHub.
get_organisation(name)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the organisation |
required |
Examples:
get_organisation("Sudoblark")
Returns:
Type | Description |
---|---|
Union[None, Organisation]
|
|
get_organisations()
Examples:
get_organisations()
Returns:
Type | Description |
---|---|
List[Organisation]
|
All Organisations within GitHub the instance may access, empty if none found |
List[Organisation]
|
or instance otherwise doesn't have access or fails to query the RESTAPI. |
get_repository(owner, name)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the repository we are querying for |
required |
owner
|
str
|
The owner of the repository we are querying for |
required |
Examples:
get_repository("othneildrew", "Best-README-Template")
Returns:
Type | Description |
---|---|
Union[Repository, None]
|
Repository instance if found, else None |