forked from otroan/gerrit-review
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_changes.py
executable file
·46 lines (36 loc) · 1.36 KB
/
get_changes.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
#!/usr/bin/env python3
import sys
import json
import argparse
import requests
def getjson(url, request):
"""Given a URL return the received JSON"""
r = requests.get(url + request)
if r.status_code != 200:
raise IOError("Downloading from Gerrit failed")
return json.loads(r.text[5:])
def get_changes_from_gerrit(branch):
URL = "https://gerrit.fd.io/r"
request = f"/changes/?q=project:vpp+status:open+branch:{branch}+-is:wip&o=LABELS&o=CURRENT_REVISION&o=CURRENT_FILES&o=DETAILED_ACCOUNTS&o=CHECK&o=SUBMITTABLE"
changes = getjson(URL, request)
last = changes[-1]
batch_count = 500 # gerrit returns at most 500 entries at a time
try:
while last["_more_changes"] == True:
remaining = getjson(URL, f"{request}&S={batch_count}")
changes += remaining
last = remaining[-1]
batch_count += 500 # gerrit returns at most 500 entries at a time
except:
pass
return changes
def main():
parser = argparse.ArgumentParser(description="VPP Gerrit changes download")
parser.add_argument("outfile", type=argparse.FileType("w"))
parser.add_argument("-branch", default="master")
args = parser.parse_args()
changes = get_changes_from_gerrit(args.branch)
json.dump(changes, args.outfile)
args.outfile.close()
if __name__ == "__main__":
sys.exit(main())