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