Merge "implement gerrit pagination in simplequery"

This commit is contained in:
Jenkins 2014-11-26 16:31:58 +00:00 committed by Gerrit Code Review
commit 186a1d5261
2 changed files with 28 additions and 16 deletions

View File

@ -145,21 +145,33 @@ class Gerrit(object):
return data
def simpleQuery(self, query):
args = '--current-patch-set'
cmd = 'gerrit query --format json %s %s' % (
args, query)
out, err = self._ssh(cmd)
if not out:
return False
lines = out.split('\n')
if not lines:
return False
data = [json.loads(line) for line in lines[:-1]]
if not data:
return False
self.log.debug("Received data from Gerrit query: \n%s" %
(pprint.pformat(data)))
return data
def _query_chunk(query):
args = '--current-patch-set'
cmd = 'gerrit query --format json %s %s' % (
args, query)
out, err = self._ssh(cmd)
if not out:
return False
lines = out.split('\n')
if not lines:
return False
data = [json.loads(line) for line in lines[:-1]]
if not data:
return False
self.log.debug("Received data from Gerrit query: \n%s" %
(pprint.pformat(data)))
return data
# gerrit returns 500 results by default, so implement paging
# for large projects like nova
alldata = []
chunk = _query_chunk(query)
while(chunk):
alldata.extend(chunk)
sortkey = "resume_sortkey:'%s'" % chunk[-1]["sortKey"]
chunk = _query_chunk("%s %s" % (query, sortkey))
return alldata
def _open(self):
client = paramiko.SSHClient()

View File

@ -331,7 +331,7 @@ class Gerrit(object):
self.log.debug("Running query %s to get project open changes" % (query,))
data = self.gerrit.simpleQuery(query)
changes = []
for record in data[:-1]:
for record in data:
try:
changes.append(self._getChange(record['number'],
record['currentPatchSet']['number']))