Created
November 19, 2013 17:18
-
-
Save zenoalbisser/7548935 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
#!/usr/bin/env python | |
import sys | |
import subprocess | |
import json | |
open_changes = [] | |
class GerritChange: | |
def __init__(self, json_data): | |
self.data = json_data | |
def isUnreviewed(self): | |
if 'approvals' in self.data['currentPatchSet'].keys(): | |
for approval in self.data['currentPatchSet']['approvals']: | |
if approval['type'] == 'CRVW': | |
return False | |
return True | |
def printShortForm(self): | |
owner = '{:<20}'.format(self.data['owner']['name']) | |
subject = '{:<80}'.format(self.data['subject']) | |
gerrit_url = self.data['url'] | |
if sys.stdout.isatty(): | |
blue = '\033[94m' | |
green = '\033[92m' | |
yellow = '\033[93m' | |
red = '\033[91m' | |
end = '\033[0m' | |
gerrit_url = green + gerrit_url + end | |
owner = red + owner + end | |
print gerrit_url + ' ' + owner + ' ' + subject | |
def parse_gerrit_results(gerrit_query): | |
changes = [] | |
gerrit_result = subprocess.check_output(gerrit_query); | |
lines = gerrit_result.splitlines(); | |
for line in lines: | |
json_data = json.loads(line) | |
if 'owner' in json_data.keys(): | |
changes.append(GerritChange(json_data)) | |
return changes | |
def show_open(): | |
print '------------ status: open -------------' | |
for change in open_changes: | |
change.printShortForm(); | |
def show_unreviewed(): | |
print '------------ unreviewed -------------' | |
found_one = False | |
for change in open_changes: | |
if change.isUnreviewed(): | |
found_one = True | |
change.printShortForm(); | |
if not found_one: | |
print 'NONE.' | |
def query(): | |
global open_changes | |
open_changes = parse_gerrit_results(['ssh', 'codereview.qt-project.org', 'gerrit', 'query', 'status:open', 'project:qt-labs/qtwebengine', '--current-patch-set', '--format json']); | |
query(); | |
show_open(); | |
show_unreviewed(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment