Help us understand the problem. What is going on with this article?

Fetch PR from Github filtered by labels using PyGithub

More than 3 years have passed since last update.

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした