Module to interface with GitHub API
classGitHubRequests()Parent class to execute GitHub API requests
def__init__(token: str, endpoint: str, debug: bool=False)Contructor
Arguments:
token: GitHub token (gotten from the user Settings page)endpoint: Resource endpointdebug: Debug mode
defdownload(url: str, output_file: str)Download object from GitHub
Arguments:
url: URLoutput_file: local file name
defadd_variable(name: str, value: str)Add variable
Arguments:
name: variable name to addvalue: variable value
defdelete_variable(name: str)Delete variable
Arguments:
name: variable to delete
deflist_variables() ->dictList variables
Returns:
variable dict
deflist_secrets() ->dictList secrets
Returns:
secret dict
defdelete_runner(runner_id: int)Delete runner
Arguments:
runner_id: runner to delete
deflist_runners() ->dictList runners
Returns:
runner dict
defget_issues() ->dictList issues
Returns:
issues dict
classGitHubOrganization(GitHubRequests)Class to manage Organizations via GitHub API
def__init__(token: str, organization: str, debug: bool=False)Contructor
Arguments:
token: GitHub token (needs the admin:org rights)organization: Organization namedebug: Debug mode
deflist_repositories() ->dictList organization repositories (generator to handle pagination)
Returns:
repository infos
defget_pull_requests(state: str, author: str=None) ->dictGet pull requests at organization level
Arguments:
state: Status (open, closed)author: Author (GitHub login)
Returns:
GitHub API JSON Response
deffind(pattern: str, path: str=None) ->dictGet pull requests at organization level
Arguments:
state: Status (open, closed)author: Author (GitHub login)
Returns:
GitHub API JSON Response
classGitHubRepository(GitHubRequests)Class to manage Repositories via GitHub API
def__init__(token: str, repository: str, debug: bool=False)Contructor
Arguments:
token: GitHub token (needs the repo rights)repository: repository namedebug: Debug mode
defclone(destination: str=None, ref: str=None)Clone a remote repository locally
Arguments:
destination: local destination directoryref: remote branch or tag to clone
deflist_runs(**kwargs) ->dictList repository action runs (generator to handle pagination)
Returns:
run infos
defget_run(run_id: int) ->dictGet a specific repository action run
Arguments:
run_id: Run ID
Returns:
run info (JSON format)
defcancel_run(run_id: int)Cancel a specific run
Arguments:
run_id: ID of the run to cancel
deflist_commits() ->dictList repository commits (generator to handle pagination)
Returns:
commit infos
defget_deploy_keys() ->dictGet the deploy keys in a repository
Returns:
Keys (JSON format)
defadd_deploy_key(title: str,
content: str,
write_access: bool=False) ->dictAdd a new deploy key in a repository
Arguments:
title: Titlecontent: Key contentwrite_access: Allow write access
Returns:
Response (JSON format)
defadd_secret(name: str, value: str) ->dictAdd Secret
Arguments:
name: variable name to addvalue: secret value
Returns:
Secret in JSON format
defget_commit(branch: str) ->dictGet the latest commit of a specific branch
Arguments:
branch: branch name
Returns:
commit info (JSON format)
defget_pull_request(number: int) ->dictGet a specific pull request info
Arguments:
branch: pull request number
Returns:
pull request info (JSON format)
defpull_request_approved(number: int) ->boolGet a list of pull requests reviewers
Arguments:
branch: pull request number
Returns:
pull request reviewers (JSON format)
defbrowse(path: str) ->dictBrowse the repository file structure on the default branch
Arguments:
path: Path to browse
Returns:
JSON file structure
deflist_artifacts(run_id: int) ->strList of the artifacts generated by a specific run
Arguments:
run_id: Run ID
Returns:
JSON artifact details
defexecute_workflow(workflow: str,
payload: dict,
head_sha: str=None) ->intExecute a workflow dispatch run and return the run ID
Arguments:
workflow: Remote workflow file namepayload: Parameters to send to the workflowhead_sha: current HEAD SHA of the branch where the workflow is executed
Returns:
Run ID
defexport_variables(url: str, workflow: str, output: str, prefix: str=None)Extract variables from artifacts and fill a file with the variables
Arguments:
url: Remote artifact URLworkflow: variable name workflowoutput: Local file name where the variables are exportedprefix: exported variable prefix
defcreate_pull_request(branch: str,
commit_message: str,
files: dict,
target_branch: str=None) ->strCreate a pull request
Arguments:
branch: Source branchcommit_message: Commit messagefiles: Dict of {path: content}target_branch: Destination branch (default: default branch)
Returns:
Pull Request URL