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._id = id
|
||||||
self._data = data
|
self._data = data
|
||||||
|
|
||||||
|
@property
|
||||||
|
def id(self):
|
||||||
|
return self._id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def raw_change(self):
|
||||||
|
return self._data
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def url(self):
|
def url(self):
|
||||||
return GERRIT_API_URL + self._id + '/'
|
return GERRIT_API_URL + self._id + '/'
|
||||||
@ -262,3 +270,36 @@ class ReviewFactory:
|
|||||||
response = Review(review_id, data)
|
response = Review(review_id, data)
|
||||||
cache_review(review_id, data, self._cache)
|
cache_review(review_id, data, self._cache)
|
||||||
return response
|
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)
|
cache = self.app._load_cache_file(preload=False)
|
||||||
|
|
||||||
offset = 0
|
factory = gerrit.ReviewFactory(cache)
|
||||||
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))
|
|
||||||
|
|
||||||
for change in changes:
|
review_source = factory.query(parsed_args.query_string)
|
||||||
review = gerrit.Review(
|
for review in review_source:
|
||||||
change['_number'],
|
|
||||||
change,
|
|
||||||
)
|
|
||||||
team_name = team_data.get_repo_owner(review.project)
|
team_name = team_data.get_repo_owner(review.project)
|
||||||
if not parsed_args.include_unofficial and not team_name:
|
if not parsed_args.include_unofficial and not team_name:
|
||||||
LOG.debug(
|
LOG.debug(
|
||||||
'filtered out %s based on repo governance status',
|
'filtered out %s based on repo governance status',
|
||||||
change['project'],
|
review.project,
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
review_ids.append(review.id)
|
||||||
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
|
|
||||||
|
|
||||||
with open(parsed_args.review_list, 'w', encoding='utf-8') as f:
|
with open(parsed_args.review_list, 'w', encoding='utf-8') as f:
|
||||||
f.write('# QUERY: {}\n'.format(
|
f.write('# QUERY: {}\n'.format(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user