Skip to content

Instantly share code, notes, and snippets.

@0xD34D
Created August 29, 2013 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 0xD34D/6381835 to your computer and use it in GitHub Desktop.
Save 0xD34D/6381835 to your computer and use it in GitHub Desktop.
A python script for conveniently reviewing all open changes in a gerrit project
#!/bin/sh
""":"
exec python $0 ${1+"$@"}
"""
# mass review all open commits for a project.
# you will need to specify extra arguments like --code-review, --verified, --submit
#
# The following example will +1 and verify all commits for android_frameworks_base:
# mass_review.py android_frameworks_base --code-review 1 --verified 1
import sys
import subprocess
import json
# change this to your username on gerrit
USERNAME = 'username'
PROJECT_PREFIX = 'ChameleonOS/'
PROJECT_SUFFIX = ''
if len(sys.argv) > 1:
PROJECT_SUFFIX = sys.argv[1]
PROJECT = PROJECT_PREFIX + PROJECT_SUFFIX
SITE = 'review.chameleonos.org'
LOGIN = '%s@%s' % (USERNAME, SITE)
data = subprocess.check_output(
[
'ssh',
'-p',
'29418',
LOGIN,
'gerrit',
'query',
'status:open', 'project:' + PROJECT,
'limit:1000',
'--current-patch-set',
'--format', 'JSON'
])
# there is a \n at the very end so omit that from the list
listdata = data.split('\n')[:-1]
picks = []
for i in range(len(listdata) - 1):
jsondata = json.loads(listdata[i])
commitId = int(jsondata['number'])
patchset = int(jsondata['currentPatchSet']['number'])
picks.append((commitId, patchset))
# pre-sort the list based on commit id
picks = sorted(picks, key=lambda x: x[0])
# now go through and pick these bad boys
# template requires a tuple of (SITE, PROJECT, commitId % 100, commitId, patchset)
command = ['ssh', '-p', '29418', LOGIN, 'gerrit', 'review']
extra_args = sys.argv[2:]
for i in range(len(extra_args)):
command.append(extra_args[i])
# now run the command through the picks
for i in range(len(picks)):
review = list(command)
review.append('%d,%d' % picks[i])
subprocess.check_output(review)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment