forked from CyanogenMod/hudson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepopick.py
67 lines (56 loc) · 1.83 KB
/
repopick.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import json
import os
import subprocess
import re
try:
# For python3
import urllib.request
except ImportError:
# For python2
import imp
import urllib2
urllib = imp.new_module('urllib')
urllib.request = urllib2
for change in sys.argv[1:]:
print(change)
f = urllib.request.urlopen('http://review.cyanogenmod.org/query?q=change:%s' % change)
d = f.read()
# gerrit doesnt actually return json. returns two json blobs, separate lines. bizarre.
print(d)
d = d.split('\n')[0]
data = json.loads(d)
project = data['project']
plist = subprocess.Popen([os.environ['HOME']+"/bin/repo","list"], stdout=subprocess.PIPE)
while(True):
retcode = plist.poll()
pline = plist.stdout.readline().rstrip()
ppaths = re.split('\s*:\s*', pline.decode())
if ppaths[1] == project:
project = ppaths[0]
break
if(retcode is not None):
break
print(project)
number = data['number']
f = urllib.request.urlopen("http://review.cyanogenmod.org/changes/%s/revisions/current/review" % number)
d = f.read()
d = '\n'.join(d.split('\n')[1:])
data = json.loads(d)
current_revision = data['current_revision']
patchset = 0
ref = ""
for i in data['revisions']:
if i == current_revision:
ref = data['revisions'][i]['fetch']['anonymous http']['ref']
patchset = data['revisions'][i]['_number']
break
print("Patch set: %i" % patchset)
print("Ref: %s" % ref)
if not os.path.isdir(project):
sys.stderr.write('no project directory: %s' % project)
sys.exit(1)
os.system('cd %s ; git fetch http://review.cyanogenmod.org/%s %s' % (project, data['project'], ref))
os.system('cd %s ; git merge FETCH_HEAD' % project)