Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
Comments¶
There seem to be issues with the library. It is suggested that you call GitHub REST APIs directly, which is very straightforwad. For more discussions on GitHub APIs, please refer to GitHub API .
In [1]:
!pip3 install ghapi
Defaulting to user installation because normal site-packages is not writeable Collecting ghapi Downloading ghapi-0.1.20-py3-none-any.whl (53 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 54.0/54.0 KB 1.2 MB/s eta 0:00:00a 0:00:01 Collecting fastcore Downloading fastcore-1.4.2-py3-none-any.whl (60 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 60.1/60.1 KB 1.7 MB/s eta 0:00:00 Requirement already satisfied: pip in /usr/local/lib/python3.8/dist-packages (from ghapi) (22.0.4) Requirement already satisfied: packaging in /usr/local/lib/python3.8/dist-packages (from ghapi) (21.3) Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /usr/local/lib/python3.8/dist-packages (from packaging->ghapi) (3.0.8) Installing collected packages: fastcore, ghapi Successfully installed fastcore-1.4.2 ghapi-0.1.20
In [47]:
from ghapi.all import GhApi
api = GhApi(owner="dclong", token="ghp_xxxxxxxxxxxxxxxxxxxxxxxxx")
Methods of GhApi¶
In [4]:
[m for m in dir(api) if not m.startswith("_")]
Out[4]:
['actions', 'activity', 'apps', 'billing', 'checks', 'code_scanning', 'codes_of_conduct', 'codespaces', 'create_branch_empty', 'create_gist', 'create_release', 'debug', 'delete_branch', 'delete_release', 'delete_tag', 'dependabot', 'dependency_graph', 'emojis', 'enable_pages', 'enterprise_admin', 'fetch_events', 'full_docs', 'func_dict', 'get_branch', 'get_content', 'gh_host', 'gists', 'git', 'gitignore', 'groups', 'headers', 'interactions', 'issues', 'last_page', 'licenses', 'limit_cb', 'limit_rem', 'list_branches', 'list_events', 'list_events_parallel', 'list_files', 'list_tags', 'markdown', 'meta', 'migrations', 'oauth_authorizations', 'orgs', 'packages', 'projects', 'pulls', 'rate_limit', 'reactions', 'repos', 'scim', 'search', 'secret_scanning', 'teams', 'update_contents', 'upload_file', 'users']
GhApi.repos¶
In [13]:
api.repos
Out[13]:
- repos.list_for_org(org, type, sort, direction, per_page, page): List organization repositories
- repos.create_in_org(org, name, description, homepage, private, visibility, has_issues, has_projects, has_wiki, is_template, team_id, auto_init, gitignore_template, license_template, allow_squash_merge, allow_merge_commit, allow_rebase_merge, allow_auto_merge, delete_branch_on_merge): Create an organization repository
- repos.get(owner, repo): Get a repository
- repos.update(owner, repo, name, description, homepage, private, visibility, security_and_analysis, has_issues, has_projects, has_wiki, is_template, default_branch, allow_squash_merge, allow_merge_commit, allow_rebase_merge, allow_auto_merge, delete_branch_on_merge, archived, allow_forking): Update a repository
- repos.delete(owner, repo): Delete a repository
- repos.list_autolinks(owner, repo, page): List all autolinks of a repository
- repos.create_autolink(owner, repo, key_prefix, url_template): Create an autolink reference for a repository
- repos.get_autolink(owner, repo, autolink_id): Get an autolink reference of a repository
- repos.delete_autolink(owner, repo, autolink_id): Delete an autolink reference from a repository
- repos.enable_automated_security_fixes(owner, repo): Enable automated security fixes
- repos.disable_automated_security_fixes(owner, repo): Disable automated security fixes
- repos.list_branches(owner, repo, protected, per_page, page): List branches
- repos.get_branch(owner, repo, branch): Get a branch
- repos.get_branch_protection(owner, repo, branch): Get branch protection
- repos.update_branch_protection(owner, repo, branch, required_status_checks, enforce_admins, required_pull_request_reviews, restrictions, required_linear_history, allow_force_pushes, allow_deletions, block_creations, required_conversation_resolution): Update branch protection
- repos.delete_branch_protection(owner, repo, branch): Delete branch protection
- repos.get_admin_branch_protection(owner, repo, branch): Get admin branch protection
- repos.set_admin_branch_protection(owner, repo, branch): Set admin branch protection
- repos.delete_admin_branch_protection(owner, repo, branch): Delete admin branch protection
- repos.get_pull_request_review_protection(owner, repo, branch): Get pull request review protection
- repos.update_pull_request_review_protection(owner, repo, branch, dismissal_restrictions, dismiss_stale_reviews, require_code_owner_reviews, required_approving_review_count, bypass_pull_request_allowances): Update pull request review protection
- repos.delete_pull_request_review_protection(owner, repo, branch): Delete pull request review protection
- repos.get_commit_signature_protection(owner, repo, branch): Get commit signature protection
- repos.create_commit_signature_protection(owner, repo, branch): Create commit signature protection
- repos.delete_commit_signature_protection(owner, repo, branch): Delete commit signature protection
- repos.get_status_checks_protection(owner, repo, branch): Get status checks protection
- repos.update_status_check_protection(owner, repo, branch, strict, contexts, checks): Update status check protection
- repos.remove_status_check_protection(owner, repo, branch): Remove status check protection
- repos.get_all_status_check_contexts(owner, repo, branch): Get all status check contexts
- repos.add_status_check_contexts(owner, repo, branch, contexts): Add status check contexts
- repos.set_status_check_contexts(owner, repo, branch, contexts): Set status check contexts
- repos.remove_status_check_contexts(owner, repo, branch, contexts): Remove status check contexts
- repos.get_access_restrictions(owner, repo, branch): Get access restrictions
- repos.delete_access_restrictions(owner, repo, branch): Delete access restrictions
- repos.get_apps_with_access_to_protected_branch(owner, repo, branch): Get apps with access to the protected branch
- repos.add_app_access_restrictions(owner, repo, branch, apps): Add app access restrictions
- repos.set_app_access_restrictions(owner, repo, branch, apps): Set app access restrictions
- repos.remove_app_access_restrictions(owner, repo, branch, apps): Remove app access restrictions
- repos.get_teams_with_access_to_protected_branch(owner, repo, branch): Get teams with access to the protected branch
- repos.add_team_access_restrictions(owner, repo, branch, teams): Add team access restrictions
- repos.set_team_access_restrictions(owner, repo, branch, teams): Set team access restrictions
- repos.remove_team_access_restrictions(owner, repo, branch, teams): Remove team access restrictions
- repos.get_users_with_access_to_protected_branch(owner, repo, branch): Get users with access to the protected branch
- repos.add_user_access_restrictions(owner, repo, branch, users): Add user access restrictions
- repos.set_user_access_restrictions(owner, repo, branch, users): Set user access restrictions
- repos.remove_user_access_restrictions(owner, repo, branch, users): Remove user access restrictions
- repos.rename_branch(owner, repo, branch, new_name): Rename a branch
- repos.codeowners_errors(owner, repo, ref): List CODEOWNERS errors
- repos.list_collaborators(owner, repo, affiliation, per_page, page): List repository collaborators
- repos.check_collaborator(owner, repo, username): Check if a user is a repository collaborator
- repos.add_collaborator(owner, repo, username, permission, permissions): Add a repository collaborator
- repos.remove_collaborator(owner, repo, username): Remove a repository collaborator
- repos.get_collaborator_permission_level(owner, repo, username): Get repository permissions for a user
- repos.list_commit_comments_for_repo(owner, repo, per_page, page): List commit comments for a repository
- repos.get_commit_comment(owner, repo, comment_id): Get a commit comment
- repos.update_commit_comment(owner, repo, comment_id, body): Update a commit comment
- repos.delete_commit_comment(owner, repo, comment_id): Delete a commit comment
- repos.list_commits(owner, repo, sha, path, author, since, until, per_page, page): List commits
- repos.list_branches_for_head_commit(owner, repo, commit_sha): List branches for HEAD commit
- repos.list_comments_for_commit(owner, repo, commit_sha, per_page, page): List commit comments
- repos.create_commit_comment(owner, repo, commit_sha, body, path, position, line): Create a commit comment
- repos.list_pull_requests_associated_with_commit(owner, repo, commit_sha, per_page, page): List pull requests associated with a commit
- repos.get_commit(owner, repo, ref, page, per_page): Get a commit
- repos.get_combined_status_for_ref(owner, repo, ref, per_page, page): Get the combined status for a specific reference
- repos.list_commit_statuses_for_ref(owner, repo, ref, per_page, page): List commit statuses for a reference
- repos.get_community_profile_metrics(owner, repo): Get community profile metrics
- repos.compare_commits(owner, repo, basehead, page, per_page): Compare two commits
- repos.get_content(owner, repo, path, ref): Get repository content
- repos.create_or_update_file_contents(owner, repo, path, message, content, sha, branch, committer, author): Create or update file contents
- repos.delete_file(owner, repo, path, message, sha, branch, committer, author): Delete a file
- repos.list_contributors(owner, repo, anon, per_page, page): List repository contributors
- repos.list_deployments(owner, repo, sha, ref, task, environment, per_page, page): List deployments
- repos.create_deployment(owner, repo, ref, task, auto_merge, required_contexts, payload, environment, description, transient_environment, production_environment): Create a deployment
- repos.get_deployment(owner, repo, deployment_id): Get a deployment
- repos.delete_deployment(owner, repo, deployment_id): Delete a deployment
- repos.list_deployment_statuses(owner, repo, deployment_id, per_page, page): List deployment statuses
- repos.create_deployment_status(owner, repo, deployment_id, state, target_url, log_url, description, environment, environment_url, auto_inactive): Create a deployment status
- repos.get_deployment_status(owner, repo, deployment_id, status_id): Get a deployment status
- repos.create_dispatch_event(owner, repo, event_type, client_payload): Create a repository dispatch event
- repos.get_all_environments(owner, repo, per_page, page): Get all environments
- repos.get_environment(owner, repo, environment_name): Get an environment
- repos.create_or_update_environment(owner, repo, environment_name, wait_timer, reviewers, deployment_branch_policy): Create or update an environment
- repos.delete_an_environment(owner, repo, environment_name): Delete an environment
- repos.list_forks(owner, repo, sort, per_page, page): List forks
- repos.create_fork(owner, repo, organization): Create a fork
- repos.list_webhooks(owner, repo, per_page, page): List repository webhooks
- repos.create_webhook(owner, repo, name, config, events, active): Create a repository webhook
- repos.get_webhook(owner, repo, hook_id): Get a repository webhook
- repos.update_webhook(owner, repo, hook_id, config, events, add_events, remove_events, active): Update a repository webhook
- repos.delete_webhook(owner, repo, hook_id): Delete a repository webhook
- repos.get_webhook_config_for_repo(owner, repo, hook_id): Get a webhook configuration for a repository
- repos.update_webhook_config_for_repo(owner, repo, hook_id, url, content_type, secret, insecure_ssl): Update a webhook configuration for a repository
- repos.list_webhook_deliveries(owner, repo, hook_id, per_page, cursor): List deliveries for a repository webhook
- repos.get_webhook_delivery(owner, repo, hook_id, delivery_id): Get a delivery for a repository webhook
- repos.redeliver_webhook_delivery(owner, repo, hook_id, delivery_id): Redeliver a delivery for a repository webhook
- repos.ping_webhook(owner, repo, hook_id): Ping a repository webhook
- repos.test_push_webhook(owner, repo, hook_id): Test the push repository webhook
- repos.list_invitations(owner, repo, per_page, page): List repository invitations
- repos.update_invitation(owner, repo, invitation_id, permissions): Update a repository invitation
- repos.delete_invitation(owner, repo, invitation_id): Delete a repository invitation
- repos.list_deploy_keys(owner, repo, per_page, page): List deploy keys
- repos.create_deploy_key(owner, repo, title, key, read_only): Create a deploy key
- repos.get_deploy_key(owner, repo, key_id): Get a deploy key
- repos.delete_deploy_key(owner, repo, key_id): Delete a deploy key
- repos.list_languages(owner, repo): List repository languages
- repos.enable_lfs_for_repo(owner, repo): Enable Git LFS for a repository
- repos.disable_lfs_for_repo(owner, repo): Disable Git LFS for a repository
- repos.merge_upstream(owner, repo, branch): Sync a fork branch with the upstream repository
- repos.merge(owner, repo, base, head, commit_message): Merge a branch
- repos.get_pages(owner, repo): Get a GitHub Pages site
- repos.create_pages_site(owner, repo, source): Create a GitHub Pages site
- repos.update_information_about_pages_site(owner, repo, cname, https_enforced, public, source): Update information about a GitHub Pages site
- repos.delete_pages_site(owner, repo): Delete a GitHub Pages site
- repos.list_pages_builds(owner, repo, per_page, page): List GitHub Pages builds
- repos.request_pages_build(owner, repo): Request a GitHub Pages build
- repos.get_latest_pages_build(owner, repo): Get latest Pages build
- repos.get_pages_build(owner, repo, build_id): Get GitHub Pages build
- repos.get_pages_health_check(owner, repo): Get a DNS health check for GitHub Pages
- repos.get_readme(owner, repo, ref): Get a repository README
- repos.get_readme_in_directory(owner, repo, dir, ref): Get a repository README for a directory
- repos.list_releases(owner, repo, per_page, page): List releases
- repos.create_release(owner, repo, tag_name, target_commitish, name, body, draft, prerelease, discussion_category_name, generate_release_notes): Create a release
- repos.get_release_asset(owner, repo, asset_id): Get a release asset
- repos.update_release_asset(owner, repo, asset_id, name, label, state): Update a release asset
- repos.delete_release_asset(owner, repo, asset_id): Delete a release asset
- repos.generate_release_notes(owner, repo, tag_name, target_commitish, previous_tag_name, configuration_file_path): Generate release notes content for a release
- repos.get_latest_release(owner, repo): Get the latest release
- repos.get_release_by_tag(owner, repo, tag): Get a release by tag name
- repos.get_release(owner, repo, release_id): Get a release
- repos.update_release(owner, repo, release_id, tag_name, target_commitish, name, body, draft, prerelease, discussion_category_name): Update a release
- repos.delete_release(owner, repo, release_id): Delete a release
- repos.list_release_assets(owner, repo, release_id, per_page, page): List release assets
- repos.upload_release_asset(owner, repo, release_id, name, label): Upload a release asset
- repos.get_code_frequency_stats(owner, repo): Get the weekly commit activity
- repos.get_commit_activity_stats(owner, repo): Get the last year of commit activity
- repos.get_contributors_stats(owner, repo): Get all contributor commit activity
- repos.get_participation_stats(owner, repo): Get the weekly commit count
- repos.get_punch_card_stats(owner, repo): Get the hourly commit count for each day
- repos.create_commit_status(owner, repo, sha, state, target_url, description, context): Create a commit status
- repos.list_tags(owner, repo, per_page, page): List repository tags
- repos.download_tarball_archive(owner, repo, ref): Download a repository archive (tar)
- repos.list_teams(owner, repo, per_page, page): List repository teams
- repos.get_all_topics(owner, repo, page, per_page): Get all repository topics
- repos.replace_all_topics(owner, repo, names): Replace all repository topics
- repos.get_clones(owner, repo, per): Get repository clones
- repos.get_top_paths(owner, repo): Get top referral paths
- repos.get_top_referrers(owner, repo): Get top referral sources
- repos.get_views(owner, repo, per): Get page views
- repos.transfer(owner, repo, new_owner, team_ids): Transfer a repository
- repos.check_vulnerability_alerts(owner, repo): Check if vulnerability alerts are enabled for a repository
- repos.enable_vulnerability_alerts(owner, repo): Enable vulnerability alerts
- repos.disable_vulnerability_alerts(owner, repo): Disable vulnerability alerts
- repos.download_zipball_archive(owner, repo, ref): Download a repository archive (zip)
- repos.create_using_template(template_owner, template_repo, owner, name, description, include_all_branches, private): Create a repository using a template
- repos.list_public(since): List public repositories
- repos.list_for_authenticated_user(visibility, affiliation, type, sort, direction, per_page, page, since, before): List repositories for the authenticated user
- repos.create_for_authenticated_user(name, description, homepage, private, has_issues, has_projects, has_wiki, team_id, auto_init, gitignore_template, license_template, allow_squash_merge, allow_merge_commit, allow_rebase_merge, allow_auto_merge, delete_branch_on_merge, has_downloads, is_template): Create a repository for the authenticated user
- repos.list_invitations_for_authenticated_user(per_page, page): List repository invitations for the authenticated user
- repos.accept_invitation_for_authenticated_user(invitation_id): Accept a repository invitation
- repos.decline_invitation_for_authenticated_user(invitation_id): Decline a repository invitation
- repos.list_for_user(username, type, sort, direction, per_page, page): List repositories for a user
In [138]:
repos = api.repos.list_for_org("legendu-net", per_page=100)
In [139]:
len(repos)
Out[139]:
61
Get all Docker related repositories in the org legendu-net.
In [140]:
repos_docker = [repo.name for repo in repos.items if repo.name.startswith("docker-")]
repos_docker
Out[140]:
['docker-rstudio', 'docker-ubuntu_cn', 'docker-jupyterlab', 'docker-jupyterhub-rb', 'docker-r-base', 'docker-r-pop', 'docker-jupyterhub-rp', 'docker-jupyterhub-toree', 'docker-python', 'docker-jdk', 'docker-dryscrape', 'docker-nodejs', 'docker-typescript', 'docker-jupyterhub-ts', 'docker-jupyterhub-ds', 'docker-base', 'docker-xubuntu-py', 'docker-samba', 'docker-conda', 'docker-conda-yarn', 'docker-jupyter', 'docker-jupyterhub', 'docker-jupyterhub-jdk', 'docker-jupyterhub-antlr4', 'docker-python-jdk', 'docker-nfs', 'docker-conda-build', 'docker-mlflow', 'docker-python-nodejs', 'docker-jupyterhub-sagemath', 'docker-lubuntu', 'docker-lubuntu-jdk', 'docker-jupyterhub-julia', 'docker-jupyterhub-almond', 'docker-jupyterlab-quickopen', 'docker-deepin', 'docker-deepin_b', 'docker-deepin_cn', 'docker-ldeepin', 'docker-lubuntu-pyside2', 'docker-jupyterhub-selenium-firefox', 'docker-jupyterhub-selenium-chrome', 'docker-vscode-server', 'docker-gitpod', 'docker-jupyterhub-cuda', 'docker-jupyterhub-cuda-dev', 'docker-jupyterhub-pytorch', 'docker-jupyterhub-more', 'docker-rustpython', 'docker-rust', 'docker-python-portable', 'docker-pypy', 'docker-rust-utils', 'docker-tensorboard', 'docker-evcxr_jupyter', 'docker-jupyterhub-golang', 'docker-jupyterhub-kotlin']
GhApi.Actions¶
In [38]:
api.actions
Out[38]:
- actions.get_actions_cache_usage_for_enterprise(enterprise): Get GitHub Actions cache usage for an enterprise
- actions.get_actions_cache_usage_for_org(org): Get GitHub Actions cache usage for an organization
- actions.get_actions_cache_usage_by_repo_for_org(org, per_page, page): List repositories with GitHub Actions cache usage for an organization
- actions.get_github_actions_permissions_organization(org): Get GitHub Actions permissions for an organization
- actions.set_github_actions_permissions_organization(org, enabled_repositories, allowed_actions): Set GitHub Actions permissions for an organization
- actions.list_selected_repositories_enabled_github_actions_organization(org, per_page, page): List selected repositories enabled for GitHub Actions in an organization
- actions.set_selected_repositories_enabled_github_actions_organization(org, selected_repository_ids): Set selected repositories enabled for GitHub Actions in an organization
- actions.enable_selected_repository_github_actions_organization(org, repository_id): Enable a selected repository for GitHub Actions in an organization
- actions.disable_selected_repository_github_actions_organization(org, repository_id): Disable a selected repository for GitHub Actions in an organization
- actions.get_allowed_actions_organization(org): Get allowed actions and reusable workflows for an organization
- actions.set_allowed_actions_organization(org, github_owned_allowed, verified_allowed, patterns_allowed): Set allowed actions and reusable workflows for an organization
- actions.get_github_actions_default_workflow_permissions_organization(org): Get default workflow permissions
- actions.set_github_actions_default_workflow_permissions_organization(org, default_workflow_permissions, can_approve_pull_request_reviews): Set default workflow permissions
- actions.list_self_hosted_runner_groups_for_org(org, per_page, page): List self-hosted runner groups for an organization
- actions.create_self_hosted_runner_group_for_org(org, name, visibility, selected_repository_ids, runners, allows_public_repositories, restricted_to_workflows, selected_workflows): Create a self-hosted runner group for an organization
- actions.get_self_hosted_runner_group_for_org(org, runner_group_id): Get a self-hosted runner group for an organization
- actions.update_self_hosted_runner_group_for_org(org, runner_group_id, name, visibility, allows_public_repositories, restricted_to_workflows, selected_workflows): Update a self-hosted runner group for an organization
- actions.delete_self_hosted_runner_group_from_org(org, runner_group_id): Delete a self-hosted runner group from an organization
- actions.list_repo_access_to_self_hosted_runner_group_in_org(org, runner_group_id, page, per_page): List repository access to a self-hosted runner group in an organization
- actions.set_repo_access_to_self_hosted_runner_group_in_org(org, runner_group_id, selected_repository_ids): Set repository access for a self-hosted runner group in an organization
- actions.add_repo_access_to_self_hosted_runner_group_in_org(org, runner_group_id, repository_id): Add repository access to a self-hosted runner group in an organization
- actions.remove_repo_access_to_self_hosted_runner_group_in_org(org, runner_group_id, repository_id): Remove repository access to a self-hosted runner group in an organization
- actions.list_self_hosted_runners_in_group_for_org(org, runner_group_id, per_page, page): List self-hosted runners in a group for an organization
- actions.set_self_hosted_runners_in_group_for_org(org, runner_group_id, runners): Set self-hosted runners in a group for an organization
- actions.add_self_hosted_runner_to_group_for_org(org, runner_group_id, runner_id): Add a self-hosted runner to a group for an organization
- actions.remove_self_hosted_runner_from_group_for_org(org, runner_group_id, runner_id): Remove a self-hosted runner from a group for an organization
- actions.list_self_hosted_runners_for_org(org, per_page, page): List self-hosted runners for an organization
- actions.list_runner_applications_for_org(org): List runner applications for an organization
- actions.create_registration_token_for_org(org): Create a registration token for an organization
- actions.create_remove_token_for_org(org): Create a remove token for an organization
- actions.get_self_hosted_runner_for_org(org, runner_id): Get a self-hosted runner for an organization
- actions.delete_self_hosted_runner_from_org(org, runner_id): Delete a self-hosted runner from an organization
- actions.list_labels_for_self_hosted_runner_for_org(org, runner_id): List labels for a self-hosted runner for an organization
- actions.add_custom_labels_to_self_hosted_runner_for_org(org, runner_id, labels): Add custom labels to a self-hosted runner for an organization
- actions.set_custom_labels_for_self_hosted_runner_for_org(org, runner_id, labels): Set custom labels for a self-hosted runner for an organization
- actions.remove_all_custom_labels_from_self_hosted_runner_for_org(org, runner_id): Remove all custom labels from a self-hosted runner for an organization
- actions.remove_custom_label_from_self_hosted_runner_for_org(org, runner_id, name): Remove a custom label from a self-hosted runner for an organization
- actions.list_org_secrets(org, per_page, page): List organization secrets
- actions.get_org_public_key(org): Get an organization public key
- actions.get_org_secret(org, secret_name): Get an organization secret
- actions.create_or_update_org_secret(org, secret_name, encrypted_value, key_id, visibility, selected_repository_ids): Create or update an organization secret
- actions.delete_org_secret(org, secret_name): Delete an organization secret
- actions.list_selected_repos_for_org_secret(org, secret_name, page, per_page): List selected repositories for an organization secret
- actions.set_selected_repos_for_org_secret(org, secret_name, selected_repository_ids): Set selected repositories for an organization secret
- actions.add_selected_repo_to_org_secret(org, secret_name, repository_id): Add selected repository to an organization secret
- actions.remove_selected_repo_from_org_secret(org, secret_name, repository_id): Remove selected repository from an organization secret
- actions.list_artifacts_for_repo(owner, repo, per_page, page): List artifacts for a repository
- actions.get_artifact(owner, repo, artifact_id): Get an artifact
- actions.delete_artifact(owner, repo, artifact_id): Delete an artifact
- actions.download_artifact(owner, repo, artifact_id, archive_format): Download an artifact
- actions.get_actions_cache_usage(owner, repo): Get GitHub Actions cache usage for a repository
- actions.get_job_for_workflow_run(owner, repo, job_id): Get a job for a workflow run
- actions.download_job_logs_for_workflow_run(owner, repo, job_id): Download job logs for a workflow run
- actions.re_run_job_for_workflow_run(owner, repo, job_id): Re-run a job from a workflow run
- actions.get_github_actions_permissions_repository(owner, repo): Get GitHub Actions permissions for a repository
- actions.set_github_actions_permissions_repository(owner, repo, enabled, allowed_actions): Set GitHub Actions permissions for a repository
- actions.get_workflow_access_to_repository(owner, repo): Get the level of access for workflows outside of the repository
- actions.set_workflow_access_to_repository(owner, repo, access_level): Set the level of access for workflows outside of the repository
- actions.get_allowed_actions_repository(owner, repo): Get allowed actions and reusable workflows for a repository
- actions.set_allowed_actions_repository(owner, repo, github_owned_allowed, verified_allowed, patterns_allowed): Set allowed actions and reusable workflows for a repository
- actions.list_self_hosted_runners_for_repo(owner, repo, per_page, page): List self-hosted runners for a repository
- actions.list_runner_applications_for_repo(owner, repo): List runner applications for a repository
- actions.create_registration_token_for_repo(owner, repo): Create a registration token for a repository
- actions.create_remove_token_for_repo(owner, repo): Create a remove token for a repository
- actions.get_self_hosted_runner_for_repo(owner, repo, runner_id): Get a self-hosted runner for a repository
- actions.delete_self_hosted_runner_from_repo(owner, repo, runner_id): Delete a self-hosted runner from a repository
- actions.list_labels_for_self_hosted_runner_for_repo(owner, repo, runner_id): List labels for a self-hosted runner for a repository
- actions.add_custom_labels_to_self_hosted_runner_for_repo(owner, repo, runner_id, labels): Add custom labels to a self-hosted runner for a repository
- actions.set_custom_labels_for_self_hosted_runner_for_repo(owner, repo, runner_id, labels): Set custom labels for a self-hosted runner for a repository
- actions.remove_all_custom_labels_from_self_hosted_runner_for_repo(owner, repo, runner_id): Remove all custom labels from a self-hosted runner for a repository
- actions.remove_custom_label_from_self_hosted_runner_for_repo(owner, repo, runner_id, name): Remove a custom label from a self-hosted runner for a repository
- actions.list_workflow_runs_for_repo(owner, repo, actor, branch, event, status, per_page, page, created, exclude_pull_requests, check_suite_id): List workflow runs for a repository
- actions.get_workflow_run(owner, repo, run_id, exclude_pull_requests): Get a workflow run
- actions.delete_workflow_run(owner, repo, run_id): Delete a workflow run
- actions.get_reviews_for_run(owner, repo, run_id): Get the review history for a workflow run
- actions.approve_workflow_run(owner, repo, run_id): Approve a workflow run for a fork pull request
- actions.list_workflow_run_artifacts(owner, repo, run_id, per_page, page): List workflow run artifacts
- actions.get_workflow_run_attempt(owner, repo, run_id, attempt_number, exclude_pull_requests): Get a workflow run attempt
- actions.list_jobs_for_workflow_run_attempt(owner, repo, run_id, attempt_number, per_page, page): List jobs for a workflow run attempt
- actions.download_workflow_run_attempt_logs(owner, repo, run_id, attempt_number): Download workflow run attempt logs
- actions.cancel_workflow_run(owner, repo, run_id): Cancel a workflow run
- actions.list_jobs_for_workflow_run(owner, repo, run_id, filter, per_page, page): List jobs for a workflow run
- actions.download_workflow_run_logs(owner, repo, run_id): Download workflow run logs
- actions.delete_workflow_run_logs(owner, repo, run_id): Delete workflow run logs
- actions.get_pending_deployments_for_run(owner, repo, run_id): Get pending deployments for a workflow run
- actions.review_pending_deployments_for_run(owner, repo, run_id, environment_ids, state, comment): Review pending deployments for a workflow run
- actions.re_run_workflow(owner, repo, run_id): Re-run a workflow
- actions.re_run_workflow_failed_jobs(owner, repo, run_id): Re-run failed jobs from a workflow run
- actions.get_workflow_run_usage(owner, repo, run_id): Get workflow run usage
- actions.list_repo_secrets(owner, repo, per_page, page): List repository secrets
- actions.get_repo_public_key(owner, repo): Get a repository public key
- actions.get_repo_secret(owner, repo, secret_name): Get a repository secret
- actions.create_or_update_repo_secret(owner, repo, secret_name, encrypted_value, key_id): Create or update a repository secret
- actions.delete_repo_secret(owner, repo, secret_name): Delete a repository secret
- actions.list_repo_workflows(owner, repo, per_page, page): List repository workflows
- actions.get_workflow(owner, repo, workflow_id): Get a workflow
- actions.disable_workflow(owner, repo, workflow_id): Disable a workflow
- actions.create_workflow_dispatch(owner, repo, workflow_id, ref, inputs): Create a workflow dispatch event
- actions.enable_workflow(owner, repo, workflow_id): Enable a workflow
- actions.list_workflow_runs(owner, repo, workflow_id, actor, branch, event, status, per_page, page, created, exclude_pull_requests, check_suite_id): List workflow runs
- actions.get_workflow_usage(owner, repo, workflow_id): Get workflow usage
- actions.list_environment_secrets(repository_id, environment_name, per_page, page): List environment secrets
- actions.get_environment_public_key(repository_id, environment_name): Get an environment public key
- actions.get_environment_secret(repository_id, environment_name, secret_name): Get an environment secret
- actions.create_or_update_environment_secret(repository_id, environment_name, secret_name, encrypted_value, key_id): Create or update an environment secret
- actions.delete_environment_secret(repository_id, environment_name, secret_name): Delete an environment secret
In [77]:
[m for m in dir(api.actions) if "secret" in m]
Out[77]:
['add_selected_repo_to_org_secret', 'create_or_update_environment_secret', 'create_or_update_org_secret', 'create_or_update_repo_secret', 'delete_environment_secret', 'delete_org_secret', 'delete_repo_secret', 'get_environment_secret', 'get_org_secret', 'get_repo_secret', 'list_environment_secrets', 'list_org_secrets', 'list_repo_secrets', 'list_selected_repos_for_org_secret', 'remove_selected_repo_from_org_secret', 'set_selected_repos_for_org_secret']
List secrets in the repository dclong/blog.
In [48]:
api.actions.list_repo_secrets(owner="dclong", repo="blog")
Out[48]:
{'secrets': [], 'total_count': 0}
In [71]:
api.actions.list_repo_secrets(owner="legendu-net", repo="xinstall")
Out[71]:
{ 'secrets': [{'name': 'PYPI_XINSTALL', 'created_at': '2022-04-29T19:39:43Z', 'updated_at': '2022-04-29T19:39:43Z'}],
'total_count': 1}
In [68]:
api.actions.get_repo_secret("xinstall", "PYPI_XINSTALL")
Out[68]:
{ 'created_at': '2022-04-29T19:39:43Z',
'name': 'PYPI_XINSTALL',
'updated_at': '2022-04-29T19:39:43Z'}
In [72]:
api.actions.get_repo_secret("docker_image_builder", "DOCKERHUB_USERNAME")
Out[72]:
{ 'created_at': '2020-11-14T05:26:26Z',
'name': 'DOCKERHUB_USERNAME',
'updated_at': '2020-11-14T05:26:26Z'}
In [71]:
api.actions.list_repo_secrets(owner="legendu-net", repo="xinstall")
Out[71]:
{ 'secrets': [{'name': 'PYPI_XINSTALL', 'created_at': '2022-04-29T19:39:43Z', 'updated_at': '2022-04-29T19:39:43Z'}],
'total_count': 1}
In [82]:
api.actions.list_repo_secrets(owner="legendu-net", repo="docker-jupyterhub-cuda")
Out[82]:
{ 'secrets': [{'name': 'GITHUBACTIONS', 'created_at': '2021-11-28T21:46:41Z', 'updated_at': '2021-11-28T21:46:41Z'}],
'total_count': 1}
List secrets in the repository legendu-net/xinstall.
In [142]:
?api.actions.delete_repo_secret
Signature: api.actions.delete_repo_secret(repo, secret_name) Type: _GhVerb String form: actions.delete_repo_secret(repo, secret_name) https://docs.github.com/rest/reference/actions#delete-a-repository-secret File: ~/.local/lib/python3.8/site-packages/ghapi/core.py Docstring: Delete a repository secret
In [150]:
api.actions.delete_repo_secret(
owner="legendu-net", repo="docker-jupyterhub-cuda", secret_name="GITHUBACTIONS"
)
--------------------------------------------------------------------------- HTTPError Traceback (most recent call last) Input In [150], in <cell line: 1>() ----> 1 api.actions.delete_repo_secret(owner="legendu-net", repo="docker-jupyterhub-cuda", secret_name="GITHUBACTIONS") File ~/.local/lib/python3.8/site-packages/ghapi/core.py:63, in _GhVerb.__call__(self, headers, *args, **kwargs) 60 kwargs = {k:v for k,v in kwargs.items() if v is not None} 61 route_p,query_p,data_p = [{p:kwargs[p] for p in o if p in kwargs} 62 for o in (self.route_ps,self.params,d)] ---> 63 return self.client(self.path, self.verb, headers=headers, route=route_p, query=query_p, data=data_p) File ~/.local/lib/python3.8/site-packages/ghapi/core.py:112, in GhApi.__call__(self, path, verb, headers, route, query, data) 110 if route: 111 for k,v in route.items(): route[k] = quote(str(route[k])) --> 112 res,self.recv_hdrs = urlsend(path, verb, headers=headers or None, debug=self.debug, return_headers=True, 113 route=route or None, query=query or None, data=data or None) 114 if 'X-RateLimit-Remaining' in self.recv_hdrs: 115 newlim = self.recv_hdrs['X-RateLimit-Remaining'] File ~/.local/lib/python3.8/site-packages/fastcore/net.py:212, in urlsend(url, verb, headers, route, query, data, json_data, return_json, return_headers, debug) 209 if route and route.get('archive_format', None): 210 return urlread(req, decode=False, return_json=False, return_headers=return_headers) --> 212 return urlread(req, return_json=return_json, return_headers=return_headers) File ~/.local/lib/python3.8/site-packages/fastcore/net.py:111, in urlread(url, data, headers, decode, return_json, return_headers, timeout, **kwargs) 109 "Retrieve `url`, using `data` dict or `kwargs` to `POST` if present" 110 try: --> 111 with urlopen(url, data=data, headers=headers, timeout=timeout, **kwargs) as u: res,hdrs = u.read(),u.headers 112 except HTTPError as e: 113 if 400 <= e.code < 500: raise ExceptionsHTTP[e.code](e.url, e.hdrs, e.fp) from None File ~/.local/lib/python3.8/site-packages/fastcore/net.py:105, in urlopen(url, data, headers, timeout, **kwargs) 103 if not isinstance(data, (str,bytes)): data = urlencode(data) 104 if not isinstance(data, bytes): data = data.encode('ascii') --> 105 return _opener.open(urlwrap(url, data=data, headers=headers), timeout=timeout) File /usr/lib/python3.8/urllib/request.py:531, in OpenerDirector.open(self, fullurl, data, timeout) 529 for processor in self.process_response.get(protocol, []): 530 meth = getattr(processor, meth_name) --> 531 response = meth(req, response) 533 return response File /usr/lib/python3.8/urllib/request.py:640, in HTTPErrorProcessor.http_response(self, request, response) 637 # According to RFC 2616, "2xx" code indicates that the client's 638 # request was successfully received, understood, and accepted. 639 if not (200 <= code < 300): --> 640 response = self.parent.error( 641 'http', request, response, code, msg, hdrs) 643 return response File /usr/lib/python3.8/urllib/request.py:563, in OpenerDirector.error(self, proto, *args) 561 http_err = 0 562 args = (dict, proto, meth_name) + args --> 563 result = self._call_chain(*args) 564 if result: 565 return result File /usr/lib/python3.8/urllib/request.py:502, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args) 500 for handler in handlers: 501 func = getattr(handler, meth_name) --> 502 result = func(*args) 503 if result is not None: 504 return result File /usr/lib/python3.8/urllib/request.py:734, in HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers) 729 newurl = urljoin(req.full_url, newurl) 731 # XXX Probably want to forget about the state of the current 732 # request, although that might interact poorly with other 733 # handlers that also use handler-specific request attributes --> 734 new = self.redirect_request(req, fp, code, msg, headers, newurl) 735 if new is None: 736 return File /usr/lib/python3.8/urllib/request.py:672, in HTTPRedirectHandler.redirect_request(self, req, fp, code, msg, headers, newurl) 669 m = req.get_method() 670 if (not (code in (301, 302, 303, 307) and m in ("GET", "HEAD") 671 or code in (301, 302, 303) and m == "POST")): --> 672 raise HTTPError(req.full_url, code, msg, headers, fp) 674 # Strictly (according to RFC 2616), 301 or 302 in response to 675 # a POST MUST NOT cause a redirection without confirmation 676 # from the user (of urllib.request, in this case). In practice, (...) 681 # redundant with the more complete encoding done in http_error_302(), 682 # but it is kept for compatibility with other callers. 683 newurl = newurl.replace(' ', '%20') HTTPError: HTTP Error 307: Temporary Redirect
GhApi.issues¶
In [9]:
api.issues.list()
Unexpected exception formatting exception. Falling back to standard exception
Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 3397, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "/tmp/ipykernel_3545/1632110837.py", line 1, in <cell line: 1> api.issues.list() File "/home/dclong/.local/lib/python3.8/site-packages/ghapi/core.py", line 63, in __call__ return self.client(self.path, self.verb, headers=headers, route=route_p, query=query_p, data=data_p) File "/home/dclong/.local/lib/python3.8/site-packages/ghapi/core.py", line 112, in __call__ res,self.recv_hdrs = urlsend(path, verb, headers=headers or None, debug=self.debug, return_headers=True, File "/home/dclong/.local/lib/python3.8/site-packages/fastcore/net.py", line 212, in urlsend return urlread(req, return_json=return_json, return_headers=return_headers) File "/home/dclong/.local/lib/python3.8/site-packages/fastcore/net.py", line 113, in urlread if 400 <= e.code < 500: raise ExceptionsHTTP[e.code](e.url, e.hdrs, e.fp) from None fastcore.basics.HTTP404NotFoundError: HTTP Error 404: Not Found During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/IPython/core/interactiveshell.py", line 1989, in showtraceback if hasattr(value, "_render_traceback_"): File "/usr/lib/python3.8/tempfile.py", line 606, in __getattr__ file = self.__dict__['file'] KeyError: 'file'
In [7]:
api.issues
Out[7]:
- issues.list(filter, state, labels, sort, direction, since, collab, orgs, owned, pulls, per_page, page): List issues assigned to the authenticated user
- issues.list_for_org(org, filter, state, labels, sort, direction, since, per_page, page): List organization issues assigned to the authenticated user
- issues.list_assignees(owner, repo, per_page, page): List assignees
- issues.check_user_can_be_assigned(owner, repo, assignee): Check if a user can be assigned
- issues.list_for_repo(owner, repo, milestone, state, assignee, creator, mentioned, labels, sort, direction, since, per_page, page): List repository issues
- issues.create(owner, repo, title, body, assignee, milestone, labels, assignees): Create an issue
- issues.list_comments_for_repo(owner, repo, sort, direction, since, per_page, page): List issue comments for a repository
- issues.get_comment(owner, repo, comment_id): Get an issue comment
- issues.update_comment(owner, repo, comment_id, body): Update an issue comment
- issues.delete_comment(owner, repo, comment_id): Delete an issue comment
- issues.list_events_for_repo(owner, repo, per_page, page): List issue events for a repository
- issues.get_event(owner, repo, event_id): Get an issue event
- issues.get(owner, repo, issue_number): Get an issue
- issues.update(owner, repo, issue_number, title, body, assignee, state, milestone, labels, assignees): Update an issue
- issues.add_assignees(owner, repo, issue_number, assignees): Add assignees to an issue
- issues.remove_assignees(owner, repo, issue_number, assignees): Remove assignees from an issue
- issues.list_comments(owner, repo, issue_number, since, per_page, page): List issue comments
- issues.create_comment(owner, repo, issue_number, body): Create an issue comment
- issues.list_events(owner, repo, issue_number, per_page, page): List issue events
- issues.list_labels_on_issue(owner, repo, issue_number, per_page, page): List labels for an issue
- issues.add_labels(owner, repo, issue_number, labels): Add labels to an issue
- issues.set_labels(owner, repo, issue_number, labels): Set labels for an issue
- issues.remove_all_labels(owner, repo, issue_number): Remove all labels from an issue
- issues.remove_label(owner, repo, issue_number, name): Remove a label from an issue
- issues.lock(owner, repo, issue_number, lock_reason): Lock an issue
- issues.unlock(owner, repo, issue_number): Unlock an issue
- issues.list_events_for_timeline(owner, repo, issue_number, per_page, page): List timeline events for an issue
- issues.list_labels_for_repo(owner, repo, per_page, page): List labels for a repository
- issues.create_label(owner, repo, name, color, description): Create a label
- issues.get_label(owner, repo, name): Get a label
- issues.update_label(owner, repo, name, new_name, color, description): Update a label
- issues.delete_label(owner, repo, name): Delete a label
- issues.list_milestones(owner, repo, state, sort, direction, per_page, page): List milestones
- issues.create_milestone(owner, repo, title, state, description, due_on): Create a milestone
- issues.get_milestone(owner, repo, milestone_number): Get a milestone
- issues.update_milestone(owner, repo, milestone_number, title, state, description, due_on): Update a milestone
- issues.delete_milestone(owner, repo, milestone_number): Delete a milestone
- issues.list_labels_for_milestone(owner, repo, milestone_number, per_page, page): List labels for issues in a milestone
- issues.list_for_authenticated_user(filter, state, labels, sort, direction, since, per_page, page): List user account issues assigned to the authenticated user
In [11]:
api.oauth_authorizations
Out[11]:
- oauth-authorizations.list_grants(per_page, page, client_id): List your grants
- oauth-authorizations.get_grant(grant_id): Get a single grant
- oauth-authorizations.delete_grant(grant_id): Delete a grant
- oauth-authorizations.list_authorizations(per_page, page, client_id): List your authorizations
- oauth-authorizations.create_authorization(scopes, note, note_url, client_id, client_secret, fingerprint): Create a new authorization
- oauth-authorizations.get_or_create_authorization_for_app(client_id, client_secret, scopes, note, note_url, fingerprint): Get-or-create an authorization for a specific app
- oauth-authorizations.get_or_create_authorization_for_app_and_fingerprint(client_id, fingerprint, client_secret, scopes, note, note_url): Get-or-create an authorization for a specific app and fingerprint
- oauth-authorizations.get_authorization(authorization_id): Get a single authorization
- oauth-authorizations.update_authorization(authorization_id, scopes, add_scopes, remove_scopes, note, note_url, fingerprint): Update an existing authorization
- oauth-authorizations.delete_authorization(authorization_id): Delete an authorization
In [20]:
api.secret_scanning
Out[20]:
- secret-scanning.list_alerts_for_enterprise(enterprise, state, secret_type, resolution, per_page, before, after): List secret scanning alerts for an enterprise
- secret-scanning.list_alerts_for_org(org, state, secret_type, resolution, page, per_page): List secret scanning alerts for an organization
- secret-scanning.list_alerts_for_repo(owner, repo, state, secret_type, resolution, page, per_page): List secret scanning alerts for a repository
- secret-scanning.get_alert(owner, repo, alert_number): Get a secret scanning alert
- secret-scanning.update_alert(owner, repo, alert_number, state, resolution): Update a secret scanning alert
- secret-scanning.list_locations_for_alert(owner, repo, alert_number, page, per_page): List locations for a secret scanning alert
In [ ]: