diff options
author | Pawel Wieczorek <p.wieczorek2@samsung.com> | 2020-01-07 15:28:53 +0100 |
---|---|---|
committer | Pawel Wieczorek <p.wieczorek2@samsung.com> | 2020-01-07 15:28:53 +0100 |
commit | 5af7684a91ceac2616aa7fb05a4d328054b2ba8c (patch) | |
tree | 77ce41d583d92162537b0f8676717094061b6188 /bootstrap | |
parent | b4436f2b737ac9186e36eac10982f2e66b33aa6e (diff) |
Add support for using gitweb
There are projects which do not provide git mirror for code URLs apart
from Gerrit's gitweb interface (e.g. OpenDaylight [1]).
[1] https://www.opendaylight.org
Issue-ID: ONAPARC-540
Change-Id: I48c26b81f4886a12e5cdc4dfbfc99538f180449e
Signed-off-by: Pawel Wieczorek <p.wieczorek2@samsung.com>
Diffstat (limited to 'bootstrap')
-rwxr-xr-x | bootstrap/codesearch/create_config.py | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/bootstrap/codesearch/create_config.py b/bootstrap/codesearch/create_config.py index 109219d2f..aef99e778 100755 --- a/bootstrap/codesearch/create_config.py +++ b/bootstrap/codesearch/create_config.py @@ -14,6 +14,9 @@ API_PROJECTS = "/projects/" MAGIC_PREFIX = ")]}'" +GITWEB_ANCHOR = "#l{line}" +GIT_ANCHOR = "#n{line}" + def get_projects_list(gerrit): """Request list of all available projects from ONAP Gerrit.""" @@ -27,15 +30,30 @@ def get_projects_list(gerrit): return projects.keys() -def create_repos_list(projects, git): +def create_repos_list(projects, gitweb, git, gerrit): """Create a map of all projects to their repositories' URLs.""" + gerrit_project_url = "{}/{}.git" + gitweb_code_url = "{}/gitweb?p={}.git;hb=HEAD;a=blob;f={{path}}{{anchor}}" + + git_project_url = "{}/{}" + git_code_url = "{url}/tree/{path}{anchor}" + repos_list = {} for project in projects: + if gitweb: + project_url = gerrit_project_url.format(gerrit, project) + code_url = gitweb_code_url.format(gerrit, project) + anchor = GITWEB_ANCHOR + else: + project_url = git_project_url.format(git, project) + code_url = git_code_url + anchor = GIT_ANCHOR + repos_list[project] = { - "url": "{}/{}".format(git, project), + "url": project_url, "url-pattern": { - "base-url": "{url}/tree/{path}{anchor}", - "anchor": "#n{line}" + "base-url": code_url, + "anchor": anchor } } @@ -46,7 +64,9 @@ def parse_arguments(): """Return parsed command-line arguments.""" parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--gerrit', help='Gerrit address', default=DEFAULT_GERRIT) - parser.add_argument('--git', help='git address', default=DEFAULT_GIT) + access = parser.add_mutually_exclusive_group() + access.add_argument('--gitweb', help='use Gerrit\'s gitweb (bool)', action='store_true') + access.add_argument('--git', help='use external git (address)', default=DEFAULT_GIT) return parser.parse_args() @@ -55,7 +75,8 @@ def main(): """Main entry point for the script.""" arguments = parse_arguments() - repos = create_repos_list(get_projects_list(arguments.gerrit), arguments.git) + projects = get_projects_list(arguments.gerrit) + repos = create_repos_list(projects, arguments.gitweb, arguments.git, arguments.gerrit) config = { "max-concurrent-indexers": 2, "dbpath": "data", |