2 # -*- coding: utf-8 -*-
4 """Create configuration for code search."""
10 ONAP_GERRIT = "https://gerrit.onap.org/r"
11 ONAP_CGIT = "https://git.onap.org"
12 API_PROJECTS = "/projects/"
17 def get_projects_list():
18 """Request list of all available projects from ONAP Gerrit."""
19 resp = urllib.request.urlopen(ONAP_GERRIT + API_PROJECTS)
20 resp_body = resp.read()
22 no_magic = resp_body[len(MAGIC_PREFIX):]
23 decoded = no_magic.decode("utf-8")
24 projects = json.loads(decoded)
26 return projects.keys()
29 def create_repos_list(projects):
30 """Create a map of all projects to their repositories' URLs."""
31 return {p: {"url": "{}/{}".format(ONAP_CGIT, p), "url-pattern": {"base-url": "{url}/tree/{path}{anchor}", "anchor": "#n{line}"}} for p in projects}
35 """Main entry point for the script."""
36 repos = create_repos_list(get_projects_list())
38 "max-concurrent-indexers": 2,
40 "health-check-uri": "/healthz",
43 print(json.dumps(config, sort_keys=True, indent=4, separators=(',', ': ')))
46 if __name__ == '__main__':