[CODESEARCH] Rework how --git option works 11/122411/1
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>
Fri, 2 Jul 2021 09:00:30 +0000 (11:00 +0200)
committerBartek Grzybowski <b.grzybowski@partner.samsung.com>
Fri, 2 Jul 2021 09:10:16 +0000 (11:10 +0200)
"--git" will not only affect the "base-url" in Hound config for
code browser but also the "url" for the repository clone string.
This is the most sane behavior as git protocol is the most efficient
one in terms of speed.

"git" and "ssh" options are also set to be mutually exclusie as
according to the above change using git protocol based clone and
passing ssh credentials would not make sense as git protocol does
not support any kind of authentication.

Change-Id: I9897bc2aec2707ca4ed7543b1576686fb8e2b2da
Issue-ID: INT-1940
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
bootstrap/codesearch/create_config.py

index 4ff059d..b881476 100755 (executable)
@@ -35,8 +35,10 @@ def get_projects_list(gerrit):
 def create_repos_list(projects, gerrit, ssh, git, poll):
     """Create a map of all projects to their repositories' URLs."""
     gerrit_url = "https://{}{}".format(gerrit, API_PREFIX)
+    git_url = "git://{}".format(git)
     gerrit_project_url_base = "{}/{{}}.git".format(gerrit_url)
     gitweb_code_url_base = "{}/gitweb?p={{}}.git;hb=HEAD;a=blob;f=".format(gerrit_url)
+    git_project_url_base = "{}/{{}}.git".format(git_url)
 
     repos_list = {}
     for project in projects:
@@ -49,6 +51,7 @@ def create_repos_list(projects, gerrit, ssh, git, poll):
             project_url = "ssh://{}@{}:{}/{}.git".format(user, gerrit, port, project)
         if git:
             code_url = "https://{}/{}/tree/".format(git, project) + CODE_LOCATION
+            project_url = git_project_url_base.format(project)
             anchor = GIT_ANCHOR
 
         repos_list[project] = {
@@ -66,10 +69,11 @@ def create_repos_list(projects, gerrit, ssh, git, poll):
 def parse_arguments():
     """Return parsed command-line arguments."""
     parser = argparse.ArgumentParser(description=__doc__)
+    group = parser.add_mutually_exclusive_group()
     parser.add_argument('--gerrit', help='Gerrit address', default=DEFAULT_GERRIT)
-    parser.add_argument('--ssh', help='SSH information: user, port', nargs=2)
-    parser.add_argument('--git', help='external git address')
-    parser.add_argument('--poll-interval', help='repositories polling interval in seconds', type=int, default=DEFAULT_POLL)
+    group.add_argument('--ssh', help='SSH information for Gerrit access: user, port', nargs=2)
+    group.add_argument('--git', help='External git address. Does not support --ssh')
+    parser.add_argument('--poll-interval', help='Repositories polling interval in seconds', type=int, default=DEFAULT_POLL)
 
     return parser.parse_args()