finetune repos

This commit is contained in:
Artem Goncharov 2022-10-27 17:22:05 +02:00
parent 0f9f4cf295
commit a18ca7e2a4
4 changed files with 53 additions and 8 deletions

View File

@ -42,6 +42,9 @@ sys.path.insert(0, os.path.abspath('../'))
sys.path.insert(0, os.path.abspath('./')) sys.path.insert(0, os.path.abspath('./'))
# -- General configuration ---------------------------------------------------- # -- 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 # Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.

View File

@ -6,12 +6,20 @@ from ruamel.yaml import YAML
data = otc_metadata.services.Services() data = otc_metadata.services.Services()
new_data = data._service_data new_data = data._service_data
services = data.service_dict #services = data.service_dict
for srv in new_data["services"]: for doc in new_data["documents"]:
srv["teams"] = [ hc_location = None
{"name": f"docs-{srv['service_category']}-rw", "permission": "write"} 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() _yaml = YAML()

View File

@ -17,6 +17,7 @@ import argparse
import logging import logging
import os import os
import pathlib import pathlib
import requests
import subprocess import subprocess
import warnings import warnings
@ -32,6 +33,8 @@ import otc_metadata.services
data = otc_metadata.services.Services() data = otc_metadata.services.Services()
api_session = requests.Session()
def process_repositories(args, service): def process_repositories(args, service):
"""Checkout repositories """Checkout repositories
@ -119,7 +122,7 @@ def process_repositories(args, service):
try: try:
new_branch = repo_to.create_head(branch_name, 'main') new_branch = repo_to.create_head(branch_name, 'main')
except Exception: except Exception:
logging.warn(f"Skipping service {service}") logging.warning(f"Skipping service {service}")
return return
new_branch.checkout() new_branch.checkout()
@ -160,6 +163,35 @@ def process_repositories(args, service):
cwd=copy_to, cwd=copy_to,
check=True 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(): def main():
@ -189,7 +221,8 @@ def main():
action='store_true', action='store_true',
help='Whether to force branch recreation.' 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() args = parser.parse_args()
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)

View File

@ -76,6 +76,7 @@ def process_services(args, services):
allow_merge_commit=False, allow_merge_commit=False,
allow_squash_merge=True, allow_squash_merge=True,
allow_rebase_merge=False, allow_rebase_merge=False,
allow_update_branch=True,
branch_protections=[] branch_protections=[]
) )
@ -127,7 +128,7 @@ def process_services(args, services):
data = copy.deepcopy(github_repo_template) data = copy.deepcopy(github_repo_template)
data["description"] = ( data["description"] = (
f"Open Telekom Cloud {service['service_title']} " f"Open Telekom Cloud {service['service_title']} "
f"Service docs" f"docs"
) )
data["branch_protections"].append({"branch": "main", data["branch_protections"].append({"branch": "main",
"template": "zuul"}) "template": "zuul"})