move gerrit querying loop somewhere more reusable
Change-Id: Ib41e49fe1e94af56d2a3fef892b55c4526e4f31d Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
parent
d41c659628
commit
4e08bbc1d5
@ -94,6 +94,14 @@ class Review:
|
||||
self._id = id
|
||||
self._data = data
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def raw_change(self):
|
||||
return self._data
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return GERRIT_API_URL + self._id + '/'
|
||||
@ -262,3 +270,36 @@ class ReviewFactory:
|
||||
response = Review(review_id, data)
|
||||
cache_review(review_id, data, self._cache)
|
||||
return response
|
||||
|
||||
def query(self, query_string):
|
||||
"Generator for changes matching the query criteria."
|
||||
batch_size = 200
|
||||
offset = 0
|
||||
while True:
|
||||
changes = query_gerrit(
|
||||
'changes/',
|
||||
params={
|
||||
'n': str(batch_size),
|
||||
'start': offset,
|
||||
'q': query_string,
|
||||
'o': QUERY_OPTIONS,
|
||||
},
|
||||
)
|
||||
LOG.debug('%d changes', len(changes))
|
||||
|
||||
for change in changes:
|
||||
review = Review(
|
||||
change['_number'],
|
||||
change,
|
||||
)
|
||||
cache_review(
|
||||
review.id,
|
||||
review.raw_change,
|
||||
self._cache,
|
||||
)
|
||||
yield review
|
||||
|
||||
if changes and changes[-1].get('_more_changes', False):
|
||||
offset += batch_size
|
||||
else:
|
||||
break
|
||||
|
@ -56,43 +56,18 @@ class QueryChanges(command.Command):
|
||||
|
||||
cache = self.app._load_cache_file(preload=False)
|
||||
|
||||
offset = 0
|
||||
while True:
|
||||
changes = gerrit.query_gerrit(
|
||||
'changes/',
|
||||
params={
|
||||
'n': '100',
|
||||
'start': offset,
|
||||
'q': parsed_args.query_string,
|
||||
'o': gerrit.QUERY_OPTIONS,
|
||||
},
|
||||
)
|
||||
LOG.debug('%d changes', len(changes))
|
||||
factory = gerrit.ReviewFactory(cache)
|
||||
|
||||
for change in changes:
|
||||
review = gerrit.Review(
|
||||
change['_number'],
|
||||
change,
|
||||
review_source = factory.query(parsed_args.query_string)
|
||||
for review in review_source:
|
||||
team_name = team_data.get_repo_owner(review.project)
|
||||
if not parsed_args.include_unofficial and not team_name:
|
||||
LOG.debug(
|
||||
'filtered out %s based on repo governance status',
|
||||
review.project,
|
||||
)
|
||||
team_name = team_data.get_repo_owner(review.project)
|
||||
if not parsed_args.include_unofficial and not team_name:
|
||||
LOG.debug(
|
||||
'filtered out %s based on repo governance status',
|
||||
change['project'],
|
||||
)
|
||||
continue
|
||||
|
||||
gerrit.cache_review(
|
||||
change['_number'],
|
||||
change,
|
||||
cache,
|
||||
)
|
||||
review_ids.append(change['_number'])
|
||||
|
||||
if changes and changes[-1].get('_more_changes', False):
|
||||
offset += 100
|
||||
else:
|
||||
break
|
||||
continue
|
||||
review_ids.append(review.id)
|
||||
|
||||
with open(parsed_args.review_list, 'w', encoding='utf-8') as f:
|
||||
f.write('# QUERY: {}\n'.format(
|
||||
|
Loading…
Reference in New Issue
Block a user