88 lines
2.1 KiB
Python
88 lines
2.1 KiB
Python
|
|
import logging
|
|
import git
|
|
import json
|
|
import pathlib
|
|
import os
|
|
import argparse
|
|
|
|
from github import Auth
|
|
from github import Github
|
|
|
|
|
|
def get_git_token(args):
|
|
auth = ''
|
|
print(args.git_token)
|
|
if args.git_token:
|
|
auth = args.git_token
|
|
elif os.environ('GIT_TOKEN'):
|
|
auth = os.environ('GIT_TOKEN')
|
|
else:
|
|
raise Exception('No valid Auth Token ')
|
|
return auth
|
|
|
|
|
|
def fix_repos(args):
|
|
# get Auth information
|
|
auth = get_git_token(args)
|
|
workdir = pathlib.Path(args.work_dir)
|
|
branch = "main"
|
|
|
|
if args.target_environment == 'public':
|
|
g = Github(auth=auth)
|
|
org = g.get_organization("opentelekomcloud-docs")
|
|
|
|
repos = []
|
|
|
|
for repo in org.get_repos():
|
|
repos.append(repo.full_name)
|
|
|
|
for r in repos:
|
|
repo = g.get_repo(r)
|
|
print(repo.clone_url)
|
|
git.Repo.clone_from(repo.clone_url, to_path=workdir + repo.name, branch=branch)
|
|
break
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(
|
|
description="Update conf.py file in repositories."
|
|
)
|
|
parser.add_argument(
|
|
"--git-token",
|
|
help="Git Token for git Authentication"
|
|
)
|
|
parser.add_argument(
|
|
"--target-environment",
|
|
required=True,
|
|
choices=['public', 'internal', 'public-swiss', 'internal-swiss'],
|
|
help="Environment to be used as a source\n"
|
|
"public: Github Org: opentelekomcloud-docs/\n"
|
|
"internal: Gitea Org: docs/\n"
|
|
"internal-swiss: Gitea Org: docs/\n"
|
|
"public-swiss: GitHub Org: opentelekomcloud-docs-swiss/\n"
|
|
)
|
|
parser.add_argument(
|
|
"--work-dir",
|
|
required=True,
|
|
help="Working directory to use for repository checkout.",
|
|
)
|
|
parser.add_argument(
|
|
"--commit-description",
|
|
default=(
|
|
"Update tox.ini && conf.py file\n\n"
|
|
"Performed-by: gitea/infra/hc-tools/"
|
|
"/test.py"
|
|
),
|
|
help="Commit description for the commit",
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
fix_repos(args)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|