From 4ee322f25baf18f7920e77ecd875a141a04794fc Mon Sep 17 00:00:00 2001 From: Logan Chien Date: Mon, 19 Jul 2021 14:59:29 -0700 Subject: [PATCH] repo-review: Trim trailing slashes to avoid errors Bug: b/170858163 Change-Id: I3de16ad77f0436af97eae26816fc99493fba30c3 --- tools/repo_pull/gerrit.py | 10 ++++++++-- tools/repo_pull/repo_patch.py | 7 +++++-- tools/repo_pull/repo_pull.py | 7 +++++-- tools/repo_pull/repo_review.py | 8 +++++--- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/tools/repo_pull/gerrit.py b/tools/repo_pull/gerrit.py index 9679d9d0c..aeaba79c8 100755 --- a/tools/repo_pull/gerrit.py +++ b/tools/repo_pull/gerrit.py @@ -346,6 +346,11 @@ def find_gerrit_name(): raise ValueError('cannot find gerrit URL from manifest') +def normalize_gerrit_name(gerrit): + """Strip the trailing slashes because Gerrit will return 404 when there are + redundant trailing slashes.""" + return gerrit.rstrip('/') + def _parse_args(): """Parse command line options.""" parser = argparse.ArgumentParser() @@ -361,12 +366,13 @@ def _parse_args(): return parser.parse_args() - def main(): """Main function""" args = _parse_args() - if not args.gerrit: + if args.gerrit: + args.gerrit = normalize_gerrit_name(args.gerrit) + else: try: args.gerrit = find_gerrit_name() # pylint: disable=bare-except diff --git a/tools/repo_pull/repo_patch.py b/tools/repo_pull/repo_patch.py index f97d21104..55ce348b1 100755 --- a/tools/repo_pull/repo_patch.py +++ b/tools/repo_pull/repo_patch.py @@ -26,7 +26,8 @@ import os import sys from gerrit import ( - create_url_opener_from_args, find_gerrit_name, query_change_lists, get_patch + create_url_opener_from_args, find_gerrit_name, normalize_gerrit_name, + query_change_lists, get_patch ) def _parse_args(): @@ -49,7 +50,9 @@ def main(): """Main function""" args = _parse_args() - if not args.gerrit: + if args.gerrit: + args.gerrit = normalize_gerrit_name(args.gerrit) + else: try: args.gerrit = find_gerrit_name() # pylint: disable=bare-except diff --git a/tools/repo_pull/repo_pull.py b/tools/repo_pull/repo_pull.py index 157ede5f1..6c8c28293 100755 --- a/tools/repo_pull/repo_pull.py +++ b/tools/repo_pull/repo_pull.py @@ -32,7 +32,8 @@ import sys import xml.dom.minidom from gerrit import ( - create_url_opener_from_args, find_gerrit_name, query_change_lists, run + create_url_opener_from_args, find_gerrit_name, normalize_gerrit_name, + query_change_lists, run ) from subprocess import PIPE @@ -414,7 +415,9 @@ def main(): """Main function""" args = _parse_args() - if not args.gerrit: + if args.gerrit: + args.gerrit = normalize_gerrit_name(args.gerrit) + else: try: args.gerrit = find_gerrit_name() # pylint: disable=bare-except diff --git a/tools/repo_pull/repo_review.py b/tools/repo_pull/repo_review.py index e62820fbd..d33f790aa 100755 --- a/tools/repo_pull/repo_review.py +++ b/tools/repo_pull/repo_review.py @@ -32,8 +32,8 @@ except ImportError: from gerrit import ( abandon, add_reviewers, create_url_opener_from_args, delete_reviewer, - delete_topic, find_gerrit_name, query_change_lists, restore, set_hashtags, - set_review, set_topic, submit + delete_topic, find_gerrit_name, normalize_gerrit_name, query_change_lists, + restore, set_hashtags, set_review, set_topic, submit ) @@ -191,7 +191,9 @@ def main(): # Parse and check the command line options args = _parse_args() - if not args.gerrit: + if args.gerrit: + args.gerrit = normalize_gerrit_name(args.gerrit) + else: try: args.gerrit = find_gerrit_name() # pylint: disable=bare-except