cros_merge_to_branch: auto drop reviewers when gerrit rejects them
Sometimes the reviewers used in earlier CLs are rejected by gerrit on new
ones. Sometimes it's due to the account being deleted (people leave the
company), and sometimes it's due to gerrit being dumb. In either case,
let's just ignore that and upload w/out reviewers when things fail.
BUG=None
TEST=`cros_merge_to_branch *33021 r25 -n` drops reviewer and retries
Change-Id: Id36fc84b678e5811a3575abd652bdbde557f062d
Reviewed-on: https://gerrit.chromium.org/gerrit/44335
Reviewed-by: Chris Sosa <sosa@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/scripts/cros_merge_to_branch.py b/scripts/cros_merge_to_branch.py
index aca2d02..8cb7ca7 100644
--- a/scripts/cros_merge_to_branch.py
+++ b/scripts/cros_merge_to_branch.py
@@ -129,9 +129,19 @@
local_patch = cros_patch.LocalPatch(
work_dir, patch.project_url, constants.PATCH_BRANCH,
patch.tracking_branch, patch.remote, new_sha1)
- return local_patch.Upload(
- patch.project_url, 'refs/%s/%s' % (upload_type, branch),
- carbon_copy=False, dryrun=dryrun, reviewers=reviewers)
+ for reviewers in (reviewers, ()):
+ try:
+ ret = local_patch.Upload(
+ patch.project_url, 'refs/%s/%s' % (upload_type, branch),
+ carbon_copy=False, dryrun=dryrun, reviewers=reviewers)
+ except cros_build_lib.RunCommandError as e:
+ if (e.result.returncode == 128 and
+ re.search('fatal: user ".*?" not found', e.result.error)):
+ logging.warning('Some reviewers were not found (%s); '
+ 'dropping them & retrying upload', ' '.join(reviewers))
+ continue
+ raise
+ return ret
def _SetupWorkDirectoryForPatch(work_dir, patch, branch, manifest, email):