Created
January 14, 2014 15:30
-
-
Save zenoalbisser/8420129 to your computer and use it in GitHub Desktop.
This file contains hidden or 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_qtwebengine = [] | |
open_changes_qwebchannel = [] | |
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': | |
if approval['value'] == '2' or approval['value'] == '-2' or approval['value'] == '-1': | |
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(changes): | |
print '------------ status: open -------------' | |
for change in changes: | |
change.printShortForm(); | |
def show_unreviewed(changes): | |
print '------------ unreviewed -------------' | |
found_one = False | |
for change in changes: | |
if change.isUnreviewed(): | |
found_one = True | |
change.printShortForm(); | |
if not found_one: | |
print 'NONE.' | |
def query(): | |
global open_changes_qtwebengine | |
global open_changes_qwebchannel | |
open_changes_qtwebengine = parse_gerrit_results(['ssh', 'codereview.qt-project.org', 'gerrit', 'query', 'status:open', 'project:qt-labs/qtwebengine', '--current-patch-set', '--format json']); | |
open_changes_qwebchannel = parse_gerrit_results(['ssh', 'codereview.qt-project.org', 'gerrit', 'query', 'status:open', 'project:qt-labs/qwebchannel', '--current-patch-set', '--format json']); | |
query(); | |
print '########################################### QWebChannel ###########################################' | |
show_open(open_changes_qwebchannel); | |
show_unreviewed(open_changes_qwebchannel); | |
print '########################################### QtWebEngine ###########################################' | |
show_open(open_changes_qtwebengine); | |
show_unreviewed(open_changes_qtwebengine); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment