Skip to content

Instantly share code, notes, and snippets.

@fakechris
Created June 4, 2013 06:17
Show Gist options
  • Save fakechris/5703940 to your computer and use it in GitHub Desktop.
Save fakechris/5703940 to your computer and use it in GitHub Desktop.
import simplejson
import subprocess
USERNAME='user'
PROJECT='prj'
HOST='192.168.0.1'
ls_cmd = "ssh -p 29418 %s@%s gerrit query limit:1000 --current-patch-set --format=json status:open project:%s" % (USERNAME, HOST, PROJECT)
submit_cmd = "ssh -p 29418 %s@%s gerrit review --code-review 2 --abandon %s"
def submit(cmd):
print "submmitting ", cmd
proc = subprocess.Popen(cmd.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = proc.communicate()
proc = subprocess.Popen(ls_cmd.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = proc.communicate()
retcode = proc.returncode
for result in reversed(out.split("\n")):
try:
jsonr = simplejson.loads(result)
changeid = jsonr['currentPatchSet']['revision']
full_submit_cmd = submit_cmd % (USERNAME, HOST, changeid)
submit(full_submit_cmd)
except:
print "Decode failed", result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment