Skip to content

Instantly share code, notes, and snippets.

@bilderbuchi
Last active October 24, 2017 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bilderbuchi/f2c83cd9fe91a33a9832e0cf76aa9c95 to your computer and use it in GitHub Desktop.
Save bilderbuchi/f2c83cd9fe91a33a9832e0cf76aa9c95 to your computer and use it in GitHub Desktop.
Detect pytest PRs whose related issues have not been closed
from github import Github # uses https://github.com/PyGithub/PyGithub
mytoken = '' # insert your GH API token here
g = Github(login_or_token=mytoken)
repo = g.get_repo('pytest-dev/pytest')
candidates = {}
for m in (pr for pr in repo.get_pulls(state='closed') if pr.merged==True):
pr_number = m.number
print('Checking PR {}'.format(pr_number))
issuenr = None
files = m.get_files()
for fname in (f.filename for f in files):
# detect filename pattern like 'changelog/1505.doc'
if fname.startswith('changelog'):
entry = fname.split('/')[1]
issuenr = entry.split('.')[0]
try:
issuenr = int(issuenr)
except ValueError as e:
print('Encountered invalid issue number: {}'.format(issuenr))
issuenr = 0
print('Related issue: {}'.format(issuenr))
break # for speed, assume there's only one changelog entry
if issuenr:
issue_state = repo.get_issue(int(issuenr)).state
if issue_state == 'open':
print('PR {}: Issue {} not closed!'.format(pr_number, issuenr))
candidates[pr_number] = issuenr
print(candidates)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment