repopick: Use hostname of the URL to determine lineage gerrit

Change-Id: Ifd3883917bc4acd7d58179235d880f2e4a43b670
This commit is contained in:
dianlujitao 2024-02-08 20:23:35 +08:00
parent 68642ca994
commit 77e5f117f7

View file

@ -34,9 +34,6 @@ from concurrent.futures import ThreadPoolExecutor
from functools import cmp_to_key, partial from functools import cmp_to_key, partial
from xml.etree import ElementTree from xml.etree import ElementTree
# Default to LineageOS Gerrit
DEFAULT_GERRIT = "https://review.lineageos.org"
# cmp() is not available in Python 3, define it manually # cmp() is not available in Python 3, define it manually
# See https://docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons # See https://docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons
@ -187,6 +184,11 @@ def is_closed(status):
return status not in ("OPEN", "NEW", "DRAFT") return status not in ("OPEN", "NEW", "DRAFT")
def is_lineage_gerrit(remote_url):
p = urllib.parse.urlparse(remote_url)
return p.hostname == "review.lineageos.org"
def commit_exists(project_path, revision): def commit_exists(project_path, revision):
return ( return (
subprocess.call( subprocess.call(
@ -285,7 +287,7 @@ def main():
parser.add_argument( parser.add_argument(
"-g", "-g",
"--gerrit", "--gerrit",
default=DEFAULT_GERRIT, default="https://review.lineageos.org",
metavar="", metavar="",
help="Gerrit Instance to use. Form proto://[user@]host[:port]", help="Gerrit Instance to use. Form proto://[user@]host[:port]",
) )
@ -635,8 +637,8 @@ def do_git_fetch_pull(args, item):
cmd.append("--quiet") cmd.append("--quiet")
cmd.extend(["", item["fetch"][method]["ref"]]) cmd.extend(["", item["fetch"][method]["ref"]])
# Try fetching from GitHub first if using default gerrit # Try fetching from GitHub first if using lineage gerrit
if args.gerrit == DEFAULT_GERRIT: if is_lineage_gerrit(args.gerrit):
if args.verbose: if args.verbose:
print("Trying to fetch the change from GitHub") print("Trying to fetch the change from GitHub")
@ -649,9 +651,9 @@ def do_git_fetch_pull(args, item):
return return
print("ERROR: git command failed") print("ERROR: git command failed")
# If not using the default gerrit or github failed, fetch from gerrit. # If not using the lineage gerrit or github failed, fetch from gerrit.
if args.verbose: if args.verbose:
if args.gerrit == DEFAULT_GERRIT: if is_lineage_gerrit(args.gerrit):
print( print(
"Fetching from GitHub didn't work, trying to fetch the change from Gerrit" "Fetching from GitHub didn't work, trying to fetch the change from Gerrit"
) )