From ff57cd775c914b7cf146f5b50380081c1f9442f8 Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Wed, 21 Mar 2012 11:28:53 +0000 Subject: [PATCH] Retrieve project & team name from fetch url Change to use urlparse to extract the path which corresponds to the project name in gerrit. And improve how the team name is extracted. Previously if fed: ssh://dbailey-k@review.openstack.org:29418/openstack-ci/git-review.git parse_git_show returned: (review.openstack.org, None, dbailey-k, 29418, git-review) Instead of: (review.openstack.org, openstack-ci, dbailey-k, 29418, openstack-ci/git-review) Change-Id: Ib945c4c0b93623e524c0f536cb4059762eca301e --- git-review | 58 ++++++++++++++++++++---------------------------------- 1 file changed, 21 insertions(+), 37 deletions(-) diff --git a/git-review b/git-review index 9bf0e5f..08a36a2 100755 --- a/git-review +++ b/git-review @@ -212,12 +212,24 @@ def add_remote(hostname, port, project, remote): print -def split_hostname(fetch_url): +def parse_git_show(remote, verb): + fetch_url = "" + for line in run_command("git remote show -n %s" % remote).split("\n"): + if line.strip().startswith("%s" % verb): + fetch_url = line.split()[2] parsed_url = urlparse(fetch_url) - username = None + project_name = parsed_url.path.lstrip("/") + if project_name.endswith(".git"): + project_name = project_name[:-4] + hostname = parsed_url.netloc - port = 22 + team = None + username = None + port = parsed_url.port + + if VERBOSE: + print "Found origin %s URL:" % verb, fetch_url # Workaround bug in urlparse on OSX if parsed_url.scheme == "ssh" and parsed_url.path[:2] == "//": @@ -229,42 +241,14 @@ def split_hostname(fetch_url): (hostname, port) = hostname.split(":") # Is origin an ssh location? Let's pull more info - if parsed_url.scheme == "ssh": - return (username, hostname, port) - else: - return (None, hostname, None) + if parsed_url.scheme == "ssh" and port == None: + port = 22 + team = project_name.split("/")[-2] + if team.startswith("git@github.com"): + team = team.split(':')[1] -def parse_git_show(remote, verb): - fetch_url = "" - for line in run_command("git remote show -n %s" % remote).split("\n"): - if line.strip().startswith("%s" % verb): - fetch_url = ":".join(line.split(":")[1:]).strip() - - project_name = fetch_url.split("/")[-1] - if project_name.endswith(".git"): - project_name = project_name[:-4] - - hostname = None - team = None - username = None - port = None - - if VERBOSE: - print "Found origin %s URL:" % verb, fetch_url - - # Special-case git@github urls - the rest can be parsed with urlparse - if fetch_url.startswith("git@github.com"): - hostname = "github.com" - else: - (username, hostname, port) = split_hostname(fetch_url) - - if hostname == "github.com": - team = fetch_url.split("/")[-2] - if team.startswith("git@github.com"): - team = team.split(':')[1] - - return (hostname, team, username, port, project_name) + return (hostname, team, username, str(port), project_name) def git_config_get_value(section, option):