remove commented code

This commit is contained in:
Dmitry Afanasyev 2022-03-14 00:33:41 +03:00
parent 77f515efe9
commit bb87c1658f
3 changed files with 13 additions and 48 deletions

View File

@ -5,15 +5,15 @@ GIT_URL = 'https://git.mywistr.com'
USAGE = '''github_mirror [-h] [-g GROUP] (-u URLS [URLS ...] | -f FILE) -t TOKEN USAGE = '''github_mirror [-h] [-g GROUP] (-u URLS [URLS ...] | -f FILE) -t TOKEN
-------------------------------------------------- --------------------------------------------------
python3 github_mirror -u "https://github.com/s3rius/FastAPI-template.git" -g 2059 -t "git-QwertY1245kde" python3 github_mirror.py -u "https://github.com/s3rius/FastAPI-template.git" -g 2059 -t "glb-QwertY1245kde"
python3 github_mirror -u "https://github.com/s3rius/FastAPI-template.git" "https://github.com/sqlalchemy/sqlalchemy.git" -t "git-QwertY1245kde" python3 github_mirror.py -u "https://github.com/s3rius/FastAPI-template.git" "https://github.com/sqlalchemy/sqlalchemy.git" -t "glb-QwertY1245kde"
python3 github_mirror -f github_mirrors.txt -g 59563 -t "git-QwertY1245kde" python3 github_mirror.py -f github_mirrors.txt -g 59563 -t "glb-QwertY1245kde"
python3 github_mirror -f github_mirrors.txt -u "https://github.com/s3rius/FastAPI-template.git" -t "git-QwertY1245kde" python3 github_mirror.py -f github_mirrors.txt -u "https://github.com/s3rius/FastAPI-template.git" -t "glb-QwertY125kde"
python3 github_mirror.py --gitlab "https://gitlab.company.ru" -t "git-QwertY1245kde" -g 2059 python3 github_mirror.py --gitlab "https://gitlab.company.ru" -t "glb-QwertY1245kde" -g Personal -T "ghb-Qwerty321ldf"
-------------------------------------------------- --------------------------------------------------
@ -53,6 +53,6 @@ def create_parser() -> ArgumentParser:
'to private repositories') 'to private repositories')
parser.add_argument('-l', '--giturl', required=False, default=GIT_URL, parser.add_argument('-l', '--giturl', required=False, default=GIT_URL,
help=f'Provide gitlab url. Default link {GIT_URL}') help=f'Provide git url where you want store your repositories. Default link {GIT_URL}')
return parser return parser

View File

@ -35,15 +35,15 @@ class RepositoryCreator:
""" """
Create new project in gitlab with name based on provided url Create new project in gitlab with name based on provided url
:param url: github url to mirror with: :param url: GitHub url to mirror with:
:param group_name: namespace in gitlab to combine repos :param group_name: namespace in gitlab to combine repos
:param auth_token: github token to access private repositories :param auth_token: GitHub token to access private repositories
:return: repo_id as string or None if any error :return: repo_id as string or None if any error
""" """
# name of repository will generate automatically from link # name of repository will generate automatically from link
name = url.split('/')[-1].replace('.git', '') name = url.split('/')[-1].replace('.git', '')
update_time = random.randint(48, 96) update_time = random.randint(48, 96) # prevent update all repos at the same time
git_data = {'repo_name': name, "wiki": True, "private": False, 'mirror_interval': f'{update_time}h0m0s', git_data = {'repo_name': name, "wiki": True, "private": False, 'mirror_interval': f'{update_time}h0m0s',
"mirror": True, "lfs": True, "clone_addr": url} "mirror": True, "lfs": True, "clone_addr": url}
if group_name: if group_name:
@ -66,47 +66,13 @@ class RepositoryCreator:
except AttributeError: except AttributeError:
pass pass
# def __add_pull_mirror(self, url: str, repo_id: str) -> Union[str, None]:
# """
# Add pull mirror to Settings -> Repository -> Mirroring repositories
#
# :param url: github url to mirror with
# :param repo_id: id of repository which will be updated
# :return: github url which will be mirrored
# """
#
# if repo_id:
# git_data = {"mirror": True, "import_url": url}
# request = self.__gitlab_request('PUT', f'{self.gitlab_url}/api/v4/projects/{repo_id}', git_data)
# if request and request.status_code == self.HTTP_200_OK:
# return url
# elif request.status_code != self.HTTP_200_OK:
# logger.error(f'Cant add mirror url to project. Status code: {request.status_code}. '
# f'Reason: {request.text}')
#
# def __pull_github_repo(self, url: str, repo_id: str):
# """
# Initiate pull request for gitlab repository
#
# :param url: github url to mirror with
# :param repo_id: id of repository which will be updated
# """
#
# if repo_id:
# request = self.__gitlab_request('POST', f'{self.gitlab_url}/api/v4/projects/{repo_id}/mirror/pull')
# if request and request.status_code == self.HTTP_200_OK:
# logger.info(f'Repository: {url} has been pulled')
# elif request.status_code != self.HTTP_200_OK:
# logger.error(f'Error pull repository. Status code: {request.status_code}. Reason: {request.text}')
def create_repository_mirror(self, github_url: str, group_id: str, auth_token: str): def create_repository_mirror(self, github_url: str, group_id: str, auth_token: str):
""" """
Base action for one thread. Creates repository, add mirror url and triggers pull at te end Base action for one thread. Creates repository, add mirror url and triggers pull at te end
:param github_url: Github url which will be mirrored :param github_url: GitGub url which will be mirrored
:param group_id: Gitlab group id which contains created repository :param group_id: Gitlab group id which contains created repository
:param auth_token: Github token to access private repositories :param auth_token: GitGub token to access private repositories
""" """
self.__create_new_project(github_url, group_id, auth_token) self.__create_new_project(github_url, group_id, auth_token)

View File

@ -25,11 +25,11 @@ def main():
group_id = args.group if args.group else None group_id = args.group if args.group else None
git_url = args.giturl # if not provided used default value https://git.mywistr.com git_url = args.giturl # if not provided used default value https://git.mywistr.com
headers = {'Authorization': f'token {args.token}'} # gitlab users token must be provided headers = {'Authorization': f'token {args.token}'} # git user token must be provided
repository_creator = RepositoryCreator(gitlab_url=git_url, headers=headers) repository_creator = RepositoryCreator(gitlab_url=git_url, headers=headers)
github_token = args.githubtoken if args.githubtoken else None github_token = args.githubtoken if args.githubtoken else None # used for access to personal GitHub repositories
threads = [] threads = []
if mirror_urls: if mirror_urls:
@ -51,4 +51,3 @@ def main():
if __name__ == '__main__': if __name__ == '__main__':
main() main()