Skip to content

Instantly share code, notes, and snippets.

Created August 29, 2013 18:40
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
A python script for conveniently reviewing all open changes in a gerrit project
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:
# android_frameworks_base --code-review 1 --verified 1
import sys
import subprocess
import json
# change this to your username on gerrit
USERNAME = 'username'
if len(sys.argv) > 1:
PROJECT_SUFFIX = sys.argv[1]
SITE = ''
LOGIN = '%s@%s' % (USERNAME, SITE)
data = subprocess.check_output(
'status:open', 'project:' + PROJECT,
'--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)):
# now run the command through the picks
for i in range(len(picks)):
review = list(command)
review.append('%d,%d' % picks[i])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment