first tool started
This commit is contained in:
parent
3d336af3bc
commit
8b41b7aa73
1
.gitignore
vendored
1
.gitignore
vendored
@ -29,6 +29,7 @@ develop-eggs
|
||||
.installed.cfg
|
||||
lib
|
||||
lib64
|
||||
.env
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
|
87
hc_tools/test.py
Normal file
87
hc_tools/test.py
Normal file
@ -0,0 +1,87 @@
|
||||
|
||||
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()
|
Loading…
x
Reference in New Issue
Block a user