blob: ad9e653ba1226fd99803906e38d8cb052688f37a [file] [log] [blame]
Joshua Heskethda8ac652014-07-09 20:13:46 +10001#!/usr/bin/python
2# This tool is useful to query gerrit for negative or missing votes left by
3# a user. It may require tweaking for different failure messages etc.
4
5import json
6import requests
7import traceback
8
9# Set the user to watch
10user = 'turbo-hipster'
Joshua Hesketh0d2c8b82014-08-14 12:51:46 +100011author_name = 'DB Datasets CI'
Joshua Hesketh6730ed42015-06-12 21:33:57 +100012upstream_user = 'jenkins'
13upstream_author_name = "Jenkins"
Joshua Heskethda8ac652014-07-09 20:13:46 +100014
15# Grab a list of missing or negative reviews for a user:
16url = ("https://review.openstack.org/changes/?q=status:open "
17 "project:openstack/nova NOT label:Verified>=0,%s "
18 "branch:master&o=CURRENT_REVISION&o=MESSAGES" % user)
19
20print "Grabbing reviews from %s" % url
21r = requests.get(url)
22
23no_votes = []
24negative_votes = []
25merge_failures = []
Joshua Hesketh6730ed42015-06-12 21:33:57 +100026upstream_merge_failures = []
Joshua Heskethda8ac652014-07-09 20:13:46 +100027unknown = []
28
29for change in json.loads(r.text[5:]):
30 try:
31 patchset = change['revisions'][change['current_revision']]['_number']
32 change_id = str(change['_number']) + ',' + str(patchset)
33 last_message = None
Joshua Hesketh6730ed42015-06-12 21:33:57 +100034 last_upstream_message = None
Joshua Heskethda8ac652014-07-09 20:13:46 +100035 for message in sorted(change['messages'],
36 key=lambda k: (k['_revision_number'],
37 k['date']), reverse=True):
38 if message['_revision_number'] < patchset:
39 # Finished looking at all the messages on this patchset
40 break
Joshua Hesketh6730ed42015-06-12 21:33:57 +100041 if not last_message and message['author']['name'] == author_name:
Joshua Heskethda8ac652014-07-09 20:13:46 +100042 last_message = message['message']
Joshua Hesketh6730ed42015-06-12 21:33:57 +100043 if (not last_upstream_message and
44 message['author']['name'] == upstream_author_name):
45 last_upstream_message = message['message']
Joshua Heskethda8ac652014-07-09 20:13:46 +100046
Joshua Hesketh6730ed42015-06-12 21:33:57 +100047 if (last_upstream_message and
48 'Merge Failed.' in last_upstream_message.split('\n')[2]):
49 upstream_merge_failures.append({
50 'change_id': change_id,
51 'updated': change['updated'],
52 'change': change,
53 'last_upstream_message': last_upstream_message,
54 })
55 elif not last_message:
Joshua Heskethda8ac652014-07-09 20:13:46 +100056 # turbo-hister hasn't commented on this patchset
57 no_votes.append({
58 'change_id': change_id,
59 'updated': change['updated'],
Joshua Hesketh6730ed42015-06-12 21:33:57 +100060 'change': change,
61 'last_upstream_message': last_upstream_message,
Joshua Heskethda8ac652014-07-09 20:13:46 +100062 })
63 elif ('This change was unable to be automatically merged with the '
64 'current state of the repository.' in last_message):
65 merge_failures.append({
66 'change_id': change_id,
67 'updated': change['updated'],
Joshua Hesketh6730ed42015-06-12 21:33:57 +100068 'change': change,
69 'last_upstream_message': last_upstream_message,
Joshua Heskethda8ac652014-07-09 20:13:46 +100070 })
71 elif 'Database migration testing failed' in last_message:
72 negative_votes.append({
73 'change_id': change_id,
74 'updated': change['updated'],
Joshua Hesketh6730ed42015-06-12 21:33:57 +100075 'change': change,
76 'last_upstream_message': last_upstream_message,
Joshua Heskethda8ac652014-07-09 20:13:46 +100077 })
78 else:
79 unknown.append({
80 'change_id': change_id,
81 'updated': change['updated'],
Joshua Hesketh6730ed42015-06-12 21:33:57 +100082 'change': change,
83 'last_upstream_message': last_upstream_message,
Joshua Heskethda8ac652014-07-09 20:13:46 +100084 })
85
86 except Exception:
87 print "Something failed.. Here is the change..."
88 print change
89 traceback.print_exc()
90
91
92def print_enqueues(changes):
93 for change in sorted(changes, key=lambda k: k['updated'], reverse=True):
94 print ("zuul enqueue --trigger gerrit --pipeline check "
95 "--project openstack/nova --change %s" % (change['change_id']))
96
97print "=" * 20 + (" Changes with no votes (%d) " % len(no_votes)) + "=" * 20
98print_enqueues(no_votes)
99print ("=" * 20 + (" Changes with negative votes (%d) " % len(negative_votes))
100 + "=" * 20)
101print_enqueues(negative_votes)
102print ("=" * 20 + (" Changes with merge failure (%d) " % len(merge_failures)) +
103 "=" * 20)
104print_enqueues(merge_failures)
105print "=" * 20 + (" Others in this query (%d) " % len(unknown)) + "=" * 20
106print_enqueues(unknown)
Joshua Hesketh6730ed42015-06-12 21:33:57 +1000107print "=" * 20 + (" Changes with merge failures upstream (%d) "
108 % len(upstream_merge_failures)) + "=" * 20
109print_enqueues(upstream_merge_failures)