Skip to content

Instantly share code, notes, and snippets.

@ansiwen
Last active Dec 15, 2016
Embed
What would you like to do?
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),
)
@mwhahaha

This comment has been minimized.

Copy link

@mwhahaha mwhahaha commented Dec 15, 2016

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.

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