Last active
December 15, 2016 21:55
-
-
Save ansiwen/e139cbf25bc243d30629e0157fc753ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import re | |
import requests | |
projects = [ | |
'tripleo-heat-templates', | |
'tripleo-common', | |
'tripleo-puppet-elements', | |
'puppet-tripleo', | |
] | |
fmt = '{:>6} {:>8} {:>9} {:>10}' | |
recheck_re = re.compile('^ *recheck', flags=re.MULTILINE) | |
build_re = re.compile('^Build ', flags=re.MULTILINE) | |
for project in projects: | |
print "\nProject: {}\n".format(project) | |
print fmt.format( | |
'month', | |
'patches', | |
'rechecks', | |
'CI-factor', | |
) | |
tot_patches = 0 | |
tot_rechecks = 0 | |
for month in range(1, 13): | |
url = ('https://review.openstack.org/changes/' | |
'?q=project:openstack/{}' | |
'+status:merged+since:2016-{}-01+before:2016-{}-01' | |
'&o=MESSAGES').format(project, month, month+1) | |
response = requests.get(url) | |
if (response.ok): | |
changes = json.loads(response.text[5:]) | |
month_rechecks = 0 | |
month_patches = 0 | |
for change in changes: | |
rechecks = 0 | |
patches = {} | |
for message in change['messages']: | |
if recheck_re.search(message['message']): | |
rechecks += 1 | |
elif build_re.search(message['message']): | |
patches[message['_revision_number']] = True | |
month_rechecks += rechecks | |
month_patches += len(patches) | |
print fmt.format( | |
month, | |
month_patches, | |
month_rechecks, | |
round(float(month_rechecks)/month_patches+1, 2), | |
) | |
tot_patches += month_patches | |
tot_rechecks += month_rechecks | |
print fmt.format( | |
'total', | |
tot_patches, | |
tot_rechecks, | |
round(float(tot_rechecks)/tot_patches+1, 2), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On line 52, you can use round(float(month_rechecks)/max(month_patches,1)+1, 2) if you want to prevent division by 0 for smaller repos which may not have patches for a given month.