Skip to content

Instantly share code, notes, and snippets.

@giwa
Last active April 26, 2016 21:08
Show Gist options
  • Save giwa/8d9af1a037de7440499a4eeba655cf49 to your computer and use it in GitHub Desktop.
Save giwa/8d9af1a037de7440499a4eeba655cf49 to your computer and use it in GitHub Desktop.
Fetch PR from Github filtered by labels using PyGithub ref: http://qiita.com/giwa/items/50167309774927a5a203
from github import Github
token = 'YOUR_TOKEN'
g = Github(token)
repos = ['YOUR_REPO', 'YOUR_REPO']
# You can change get_organization to get_user()
org = g.get_organization('YOUR_ORG')
git_repos ={repo: org.get_repo(repo) for repo in repos}
# Issue is a equivalent to pr
# Issue API should be called first to fetch tags
def get_pr_from_issues(issues):
for issue in issues:
if issue.pull_request is not None:
pr_id = int(issue.pull_request.html_url.split("/")[-1])
yield issue.repository.get_pull(pr_id), issue.labels
repo_prs = {}
for repo_name, repo in git_repos.items():
repo_prs[repo_name] = get_pr_from_issues(repo.get_issues(state='open'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment