summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-11-26 16:31:58 +0000
committerGerrit Code Review <review@openstack.org>2014-11-26 16:31:58 +0000
commit186a1d5261a61d16df2210bbfb29a999f3369cf8 (patch)
tree202d244ad90bcb33d4d6bbf92f5a494b3940b47c
parent3075b680d58441688c737694becdfbcf38390e46 (diff)
parenteae3f421becfccd94e4b3db5469faae6cead704a (diff)
downloadzuul-186a1d5261a61d16df2210bbfb29a999f3369cf8.tar.gz
Merge "implement gerrit pagination in simplequery"
-rw-r--r--zuul/lib/gerrit.py42
-rw-r--r--zuul/trigger/gerrit.py2
2 files changed, 28 insertions, 16 deletions
diff --git a/zuul/lib/gerrit.py b/zuul/lib/gerrit.py
index 52e60578a..799459d47 100644
--- a/zuul/lib/gerrit.py
+++ b/zuul/lib/gerrit.py
@@ -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()
diff --git a/zuul/trigger/gerrit.py b/zuul/trigger/gerrit.py
index 368e37d38..0c0a37654 100644
--- a/zuul/trigger/gerrit.py
+++ b/zuul/trigger/gerrit.py
@@ -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']))