In [6]:
import subprocess
import re
import github3
def generate_pr_summary(directory, commit_range, owner, repository, bullet_char, password):
gitlog = subprocess.Popen(['git', 'log', '--pretty="%s"', '--merges', '--first-parent', commit_range],
stdout=subprocess.PIPE, cwd=directory)
grep = subprocess.Popen(('grep', 'pull'), stdin=gitlog.stdout, stdout=subprocess.PIPE)
gitlog.stdout.close()
data = grep.stdout.read()
grep.stdout.close()
s = str(data)
p = re.compile('.*?#([0-9]+)')
p2 = re.compile('[^0-9 ].*')
pull_numbers = p2.sub('', p.sub('\\1 ', s))
pr_list = pull_numbers.rstrip().split(' ')
username = "lindsayad"
gh = github3.login(username=username,password=password)
remote_repo = gh.repository(owner, repository)
with open(directory + '/pr_summary.txt', 'w') as f:
for pr in pr_list:
f.write(' ' + bullet_char + ' ' + remote_repo.pull_request(pr).title + '\n')
In [8]:
generate_pr_summary('/Users/lindad/projects/moose/libmesh/contrib/metaphysicl',
'c77e500..80d609',
'roystgnr',
'metaphysicl',
'*',
'')