From a18ca7e2a4bd87d02bd849f032b342ce0c4d1ba6 Mon Sep 17 00:00:00 2001 From: Artem Goncharov Date: Thu, 27 Oct 2022 17:22:05 +0200 Subject: [PATCH] finetune repos --- otc_metadata/templates/conf.py.j2 | 3 +++ tools/convert_data.py | 18 +++++++++---- tools/generate_doc_confpy.py | 37 ++++++++++++++++++++++++-- tools/generate_doc_gitcontrol_repos.py | 3 ++- 4 files changed, 53 insertions(+), 8 deletions(-) diff --git a/otc_metadata/templates/conf.py.j2 b/otc_metadata/templates/conf.py.j2 index 8aecb78d..bd7f8b6a 100644 --- a/otc_metadata/templates/conf.py.j2 +++ b/otc_metadata/templates/conf.py.j2 @@ -42,6 +42,9 @@ sys.path.insert(0, os.path.abspath('../')) sys.path.insert(0, os.path.abspath('./')) # -- General configuration ---------------------------------------------------- +# https://docutils.sourceforge.io/docs/user/smartquotes.html - it does not +# what it is expected +smartquotes = False # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. diff --git a/tools/convert_data.py b/tools/convert_data.py index 0765069b..735933f0 100644 --- a/tools/convert_data.py +++ b/tools/convert_data.py @@ -6,12 +6,20 @@ from ruamel.yaml import YAML data = otc_metadata.services.Services() new_data = data._service_data -services = data.service_dict +#services = data.service_dict -for srv in new_data["services"]: - srv["teams"] = [ - {"name": f"docs-{srv['service_category']}-rw", "permission": "write"} - ] +for doc in new_data["documents"]: + hc_location = None + if "type" in doc: + if doc["type"] == "api-ref": + hc_location = "api" + elif doc["type"] == "umn": + hc_location = "usermanual" + elif doc["type"] == "dev": + hc_location = "devg" + if hc_location: + hc_location += f"/{doc['service_type']}" + doc["hc_location"] = hc_location _yaml = YAML() diff --git a/tools/generate_doc_confpy.py b/tools/generate_doc_confpy.py index 6b6ba98b..b6eb9792 100644 --- a/tools/generate_doc_confpy.py +++ b/tools/generate_doc_confpy.py @@ -17,6 +17,7 @@ import argparse import logging import os import pathlib +import requests import subprocess import warnings @@ -32,6 +33,8 @@ import otc_metadata.services data = otc_metadata.services.Services() +api_session = requests.Session() + def process_repositories(args, service): """Checkout repositories @@ -119,7 +122,7 @@ def process_repositories(args, service): try: new_branch = repo_to.create_head(branch_name, 'main') except Exception: - logging.warn(f"Skipping service {service}") + logging.warning(f"Skipping service {service}") return new_branch.checkout() @@ -160,6 +163,35 @@ def process_repositories(args, service): cwd=copy_to, check=True ) + elif 'gitea' in url_to and args.token: + open_pr( + args, + repo["repo"], + dict( + head=branch_name, + ), + ) + + +def open_pr(args, repository, pr_data): + req = dict( + base=pr_data.get("base", "main"), + head=pr_data["head"], + ) + if "title" in pr_data: + req["title"] = pr_data["title"] + if "body" in pr_data: + req["body"] = pr_data["body"].replace("\\n", "\n") + if "assignees" in pr_data: + req["assignees"] = pr_data["assignees"] + if "labels" in pr_data: + req["labels"] = pr_data["labels"] + rsp = api_session.post( + f"{args.api_url}/repos/{repository}/pulls", json=req + ) + if rsp.status_code != 201: + print(rsp.text) + print(f"Going to open PR with title {pr_data['title']} in {repository}") def main(): @@ -189,7 +221,8 @@ def main(): action='store_true', help='Whether to force branch recreation.' ) - + parser.add_argument("--token", metavar="token", help="API token") + parser.add_argument("--api-url", help="API base url of the Git hoster") args = parser.parse_args() logging.basicConfig(level=logging.DEBUG) diff --git a/tools/generate_doc_gitcontrol_repos.py b/tools/generate_doc_gitcontrol_repos.py index 82d5db55..2aff1924 100644 --- a/tools/generate_doc_gitcontrol_repos.py +++ b/tools/generate_doc_gitcontrol_repos.py @@ -76,6 +76,7 @@ def process_services(args, services): allow_merge_commit=False, allow_squash_merge=True, allow_rebase_merge=False, + allow_update_branch=True, branch_protections=[] ) @@ -127,7 +128,7 @@ def process_services(args, services): data = copy.deepcopy(github_repo_template) data["description"] = ( f"Open Telekom Cloud {service['service_title']} " - f"Service docs" + f"docs" ) data["branch_protections"].append({"branch": "main", "template": "zuul"})