LoginSignup
2
1

More than 5 years have passed since last update.

Fetch PR from Github filtered by labels using PyGithub

Last updated at Posted at 2016-04-26

Label cannot fetch from Github PR API. Therefere, Issue API should be used. Current implementation, I filter pr in local. It is better to filter Github API lebel. There is API for filtering issue by label. I will update this post.

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'))

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1