Created
July 6, 2016 15:10
-
-
Save invisiblek/284fe138752fb12488110a4da07a78d0 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 | |
# | |
# shipit.py | |
# v1.2 | |
# | |
# Written by Dan Pasanen, 2016 | |
# WTFPL | |
# | |
# CHANGES | |
# v1.0 - initial release | |
# v1.1 - add support for a range of changes to ship | |
# v1.2 - add support for shipping a topic | |
# | |
# IMPORTANT: | |
# Must have a ~/.gerritrc with your gerrit info, pipe-separated | |
# Example: | |
# review.cyanogenmod.org|invisiblek|your_http_password_here | |
# (get http password from your settings in gerrit's web interface) | |
# | |
# USAGE: | |
# Any usage method can be used in conjunction with any other simply by | |
# separating them by spaces. Order doesn't matter. | |
# | |
# shipit.py 123456 (ship a single commit) | |
# shipit.py 123456 123457 (ship multiple commits) | |
# shipit.py 123456-123460 (ship a range of commits) | |
# shipit.py -t m7-audio-hal (ships a topic) | |
# shipit.py fake 1234 (fake ships, for testing) | |
# | |
import json | |
import os | |
import requests | |
import sys | |
from requests.auth import HTTPDigestAuth | |
u = "" | |
p = "" | |
fake = False | |
# This could be changed or parameterized | |
review = "review.cyanogenmod.org" | |
url = "http://" + review + "/a/changes/" | |
f = open(os.getenv("HOME") + "/.gerritrc", "r") | |
for line in f: | |
parts = line.rstrip().split("|") | |
if parts[0] == review: | |
u = parts[1] | |
p = parts[2] | |
if u == "" or p == "": | |
print "Couldn't find a valid config for " + review + " in " + os.getenv("HOME") + "/.gerritrc" | |
sys.exit(0) | |
auth = HTTPDigestAuth(username=u, password=p) | |
params = sys.argv | |
params.pop(0) | |
wasTopic = False | |
changes = [] | |
for i, p in enumerate(params): | |
if wasTopic: | |
wasTopic = False | |
elif p == "fake": | |
fake = True | |
elif p == "-t": | |
wasTopic = True | |
topic = params[i + 1] | |
response = requests.get(url + "?q=topic:" + topic, auth=auth) | |
j = json.loads(response.text[5:]) | |
for k in j: | |
changes.append(str(k['_number'])) | |
elif '-' in p: | |
templist = p.split('-') | |
for i in range(int(templist[0]), int(templist[1]) + 1): | |
changes.append(str(i)) | |
else: | |
changes.append(p) | |
for c in changes: | |
if fake == False: | |
try: | |
# Rebase it | |
response = requests.post(url + c + "/rebase", auth=auth) | |
except Exception: | |
print "Already at top of HEAD" | |
pass | |
j = {} | |
j['labels'] = {} | |
j['labels']['Code-Review'] = "+2" | |
j['labels']['Verified'] = "+1" | |
# +2 it | |
response = requests.post(url + c + "/revisions/current/review", auth=auth, json=j) | |
# SHIPIT!!! | |
response = requests.post(url + c + "/revisions/current/submit", auth=auth) | |
print "Shipped: " + c + "!" | |
else: | |
print "Fake shipped: " + c + "!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment