cq_label: Defer results
If setting or clearing the label fails on one CL we should continue
trying on other CLs.
Bug: b/231587812
Change-Id: If73125ae7dc9853599ed8be00c95093cd81daaa7
Reviewed-on: https://pigweed-review.googlesource.com/c/infra/recipes/+/93721
Reviewed-by: Ted Pudlik <tpudlik@google.com>
Pigweed-Auto-Submit: Rob Mohr <mohrr@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
diff --git a/recipes/cq_label.py b/recipes/cq_label.py
index 09663a9..a143101 100644
--- a/recipes/cq_label.py
+++ b/recipes/cq_label.py
@@ -58,13 +58,17 @@
'{project_part} '
).format(label=label, cq_account=cq_account, project_part=project_part,)
- changes = api.gerrit.change_query(
- name='get unlabeled changes',
- query_string=query_string,
- host=host,
- max_attempts=5,
- timeout=30,
- ).json.output
+ changes = (
+ api.gerrit.change_query(
+ name='get unlabeled changes',
+ query_string=query_string,
+ host=host,
+ max_attempts=5,
+ timeout=30,
+ )
+ .get_result()
+ .json.output
+ )
for change in changes or ():
change_id = str(change['_number'])
@@ -74,12 +78,16 @@
api.gerrit.normalize_host(host), change_id,
)
- details = api.gerrit.change_details(
- 'details',
- change_id,
- query_params=['CURRENT_REVISION'],
- host=host,
- ).json.output
+ details = (
+ api.gerrit.change_details(
+ 'details',
+ change_id,
+ query_params=['CURRENT_REVISION'],
+ host=host,
+ )
+ .get_result()
+ .json.output
+ )
if project and project != details['project']:
continue
@@ -149,13 +157,17 @@
'{project_part} '
).format(label=label, cq_account=cq_account, project_part=project_part,)
- changes = api.gerrit.change_query(
- name='get labeled changes',
- query_string=query_string,
- host=host,
- max_attempts=5,
- timeout=30,
- ).json.output
+ changes = (
+ api.gerrit.change_query(
+ name='get labeled changes',
+ query_string=query_string,
+ host=host,
+ max_attempts=5,
+ timeout=30,
+ )
+ .get_result()
+ .json.output
+ )
for change in changes or ():
change_id = str(change['_number'])
@@ -192,27 +204,28 @@
actions = []
- actions.extend(
- _label_completed_unlabelled(
- api=api,
- host=props.host,
- label=props.label,
- cq_account=props.cq_account,
- project=props.project,
- dry_run=props.dry_run,
+ with api.step.defer_results():
+ actions.extend(
+ _label_completed_unlabelled(
+ api=api,
+ host=props.host,
+ label=props.label,
+ cq_account=props.cq_account,
+ project=props.project,
+ dry_run=props.dry_run,
+ )
)
- )
- actions.extend(
- _remove_running_labelled(
- api=api,
- host=props.host,
- label=props.label,
- cq_account=props.cq_account,
- project=props.project,
- dry_run=props.dry_run,
+ actions.extend(
+ _remove_running_labelled(
+ api=api,
+ host=props.host,
+ label=props.label,
+ cq_account=props.cq_account,
+ project=props.project,
+ dry_run=props.dry_run,
+ )
)
- )
return result.RawResult(
summary_markdown='\n\n'.join(actions), status=common.SUCCESS,