Skip to content

Instantly share code, notes, and snippets.

@mogproject
Last active May 16, 2022 18:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mogproject/fbf714db9a7ed1ac40e5b092e961899c to your computer and use it in GitHub Desktop.
Save mogproject/fbf714db9a7ed1ac40e5b092e961899c to your computer and use it in GitHub Desktop.
Accessing Issues on GitHub Enterprise using PyGitHub

How to Access Issues on GitHub Enterprise

Setup

1. Install PyGitHub

pip install PyGitHub

You may want to use pip3 instead of pip.

2. Get personal access token

  • Log into GitHub Enterprise on your browser
  • Open Settings -> Developer settings -> Personal access tokens
  • Create a new access token
    • Grant repo scope
    • Treat your access token as your password.

Examples

1. Access your repository

from github import Github
g = Github(base_url="https://{YOUR_HOSTNAME}/api/v3", login_or_token=YOUR_ACCESS_TOKEN)
repo = g.get_repo("{YOUR_ORGANIZATION}/{YOUR_REPO}")

2. Get issues

  • Open issues repo.get_issues()
  • All issues repo.get_issues(state='all')
  • Specific issue repo.get_issue(number=ISSUE_NUMBER)

Print some issue information.

issue = repo.get_issue(number=123)
print(f"{issue.number}, {issue.state}, {issue.title}, {issue.assignee}, {issue.milestone}")

3. Update issue description

issue = repo.get_issue(number=123)
issue.edit(body=NEW_DESCRIPTION)

Reference:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment