Skip to content

Instantly share code, notes, and snippets.

@ShinJJang
Last active July 9, 2020 09:14
Show Gist options
  • Save ShinJJang/97d10bcc81b25fd5c53d17ba580f50c4 to your computer and use it in GitHub Desktop.
Save ShinJJang/97d10bcc81b25fd5c53d17ba580f50c4 to your computer and use it in GitHub Desktop.
Get pull requests with PyGithub, python3 📒
#!/usr/bin/env python3
from github import Github
token = 'YOUR TOKEN' # https://github.com/settings/tokens
username = 'YOUR USERNAME'
organization = 'YOUR TEAM'
gh = Github(token) # or Github(username, password)
query = 'org:{} is:merged'.format(organization) # https://help.github.com/en/articles/searching-issues-and-pull-requests
issues = list(gh.search_issues(query, author=username, type='pr'))
for issue in issues:
print(issue.number, issue.state, issue.title, issue.html_url)
print('Count : {}'.format(len(issues)))
@ShinJJang
Copy link
Author

ShinJJang commented Aug 19, 2019

Prerequisites 📦

$ pip3 install PyGithub

Execute ⚡

$ ./get_pr_list.py
# OR
$ python3 get_pr_list.py

# Result Example
48 closed Expand method with iteration count, as mentioned in #18. https://github.com/scottyab/secure-preferences/pull/48
271 closed Update typo in doc "af_paket" => "af_packet" https://github.com/elastic/beats/pull/271
240 closed Update missing comment word "out" in /etc/packetbeat.yml https://github.com/elastic/beats/pull/240

@ShinJJang
Copy link
Author

Github enterprise version

  • In specific repo,
  • Created than ~
  • Merged than ~
#!/usr/bin/env python3

from github import Github

token = 'YOUR TOKEN'  # https://github.com/settings/tokens
organization = 'YOUR TEAM'
repo = 'YOUR REPO'

gh = Github(token, base_url='[YOUR Github Domain]/api/v3') # or Github(username, password)

count = 0 
print('-------merged------')
query = 'repo:{}/{} is:merged merged:>=2020-06-17'.format(organization, repo) # https://help.github.com/en/articles/searching-issues-and-pull-requests
issues = list(gh.search_issues(query, type='pr'))
for issue in issues:
    print(issue.number, issue.state, issue.user.name, issue.created_at.date(), issue.title)

count += len(issues)

print('------opend-------')
query = 'repo:{}/{} is:unmerged created:>=2020-06-17'.format(organization, repo) # https://help.github.com/en/articles/searching-issues-and-pull-requests
issues = list(gh.search_issues(query, type='pr'))
for issue in issues:
    print(issue.number, issue.state, issue.user.name, issue.created_at.date(), issue.title)

count += len(issues)

print('Count : {}'.format(count))

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