Created
May 19, 2017 14:47
-
-
Save HalCanary/34676318075e81c7aca849021aa4570d to your computer and use it in GitHub Desktop.
This file contains 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 | |
# Copyright 2017 Google Inc. | |
# Use of this source code is governed by a BSD-style license that can be | |
# found in the LICENSE file. | |
import httplib, json, re, subprocess, sys | |
def retrieve_changeid(commit_or_branch): | |
b = subprocess.check_output(['git', 'log', '-1', '--format=%B', commit_or_branch]) | |
r = re.compile(r'^Change-Id: (.*)$') | |
for l in b.split('\n'): | |
m = r.match(l) | |
if m: | |
return m.group(1) | |
exit(2) | |
def gerrit_change_id_to_number(cid): | |
try: | |
conn = httplib.HTTPSConnection('skia-review.googlesource.com') | |
conn.request('GET', '/changes/?q=change:%s' % cid) | |
r = conn.getresponse() | |
assert(r.status == 200) | |
x = r.read() | |
i = 0 | |
while i < len(x) and x[i] != '[': | |
i += 1 | |
print json.loads(x[i:])[0]['_number'] | |
except: | |
exit(1) | |
if __name__ == '__main__': | |
if len(sys.argv) == 2 and len(sys.argv[1]) == 41 and sys.argv[1][0] == 'I': | |
gerrit_change_id_to_number(sys.argv[1]) | |
else: | |
gerrit_change_id_to_number(retrieve_changeid( | |
sys.argv[1] if len(sys.argv) == 2 else 'HEAD')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment