summaryrefslogtreecommitdiff
path: root/tools/zuul_enqueue.py
blob: 0073257656d1231dee086b72a57813552f57752a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/python
# This tool is useful to query gerrit for negative or missing votes left by
# a user. It may require tweaking for different failure messages etc.

import json
import requests
import traceback

# Set the user to watch
user = 'turbo-hipster'
author_name = 'DB Datasets CI'

# Grab a list of missing or negative reviews for a user:
url = ("https://review.openstack.org/changes/?q=status:open "
       "project:openstack/nova NOT label:Verified>=0,%s "
       "branch:master&o=CURRENT_REVISION&o=MESSAGES" % user)

print "Grabbing reviews from %s" % url
r = requests.get(url)

no_votes = []
negative_votes = []
merge_failures = []
unknown = []

for change in json.loads(r.text[5:]):
    try:
        patchset = change['revisions'][change['current_revision']]['_number']
        change_id = str(change['_number']) + ',' + str(patchset)
        last_message = None
        for message in sorted(change['messages'],
                              key=lambda k: (k['_revision_number'],
                                             k['date']), reverse=True):
            if message['_revision_number'] < patchset:
                # Finished looking at all the messages on this patchset
                break
            if message['author']['name'] == author_name:
                last_message = message['message']
                break

        if not last_message:
            # turbo-hister hasn't commented on this patchset
            no_votes.append({
                'change_id': change_id,
                'updated': change['updated'],
                'change': change
            })
        elif ('This change was unable to be automatically merged with the '
              'current state of the repository.' in last_message):
            merge_failures.append({
                'change_id': change_id,
                'updated': change['updated'],
                'change': change
            })
        elif 'Database migration testing failed' in last_message:
            negative_votes.append({
                'change_id': change_id,
                'updated': change['updated'],
                'change': change
            })
        else:
            unknown.append({
                'change_id': change_id,
                'updated': change['updated'],
                'change': change
            })

    except Exception:
        print "Something failed.. Here is the change..."
        print change
        traceback.print_exc()


def print_enqueues(changes):
    for change in sorted(changes, key=lambda k: k['updated'], reverse=True):
        print ("zuul enqueue --trigger gerrit --pipeline check "
               "--project openstack/nova --change %s" % (change['change_id']))

print "=" * 20 + (" Changes with no votes (%d) " % len(no_votes)) + "=" * 20
print_enqueues(no_votes)
print ("=" * 20 + (" Changes with negative votes (%d) " % len(negative_votes))
       + "=" * 20)
print_enqueues(negative_votes)
print ("=" * 20 + (" Changes with merge failure (%d) " % len(merge_failures)) +
       "=" * 20)
print_enqueues(merge_failures)
print "=" * 20 + (" Others in this query (%d) " % len(unknown)) + "=" * 20
print_enqueues(unknown)