Last active
December 14, 2021 09:13
-
-
Save nekoya/21a634619e80f1b3cbd313d25cb171e0 to your computer and use it in GitHub Desktop.
PyGithub cheat sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from github import Github | |
GITHUB_TOKEN = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | |
g = Github(GITHUB_TOKEN) | |
def get_user(): | |
""" | |
Returns: | |
<AuthenticatedUser> | |
""" | |
user = g.get_user() | |
return user | |
def get_organization(organization_name): | |
""" | |
Returns: | |
<Organization> | |
""" | |
organization = g.get_organization(organization_name) | |
return organization | |
def get_repo(owner, repo_name): | |
""" | |
Args: | |
<AuthenticatedUser|Organization> repository owner | |
<string> repository name, not fullname "owner/XXXX" | |
""" | |
repo = owner.get_repo(repo_name) | |
return repo | |
def auto_merge(repo, branch_name): | |
""" | |
Args: | |
<Repository> | |
<string> target branch name | |
""" | |
c = repo.get_commit('HEAD') | |
ref = repo.create_git_ref('refs/heads/auto', c.sha) # create branch | |
repo.merge('auto', branch_name, 'auto merge') | |
# repo.get_git_ref('heads/auto').delete() # without "refs" prefix | |
ref.delete() | |
def show_branches(repo): | |
[print(x.name, x.commit.sha) for x in repo.get_branches()] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment