Compare commits

..

5 Commits

Author SHA1 Message Date
Dmitry Afanasyev
4704763995
Merge pull request #1 from Balshgit/gitea
add binary file
2023-10-15 14:45:50 +03:00
161517c0e9 build binary file 2023-10-15 14:44:01 +03:00
2a683e09f3 update README.md file 2022-06-07 21:46:47 +03:00
438bf4197c Merge branch 'gitea' 2022-06-07 21:43:40 +03:00
c1b716b310 update .gitignore 2022-03-14 01:58:09 +03:00
8 changed files with 35 additions and 24 deletions

2
.gitignore vendored
View File

@ -63,7 +63,7 @@ __pycache__/
.Python .Python
env/ env/
develop-eggs/ develop-eggs/
dist/ # dist/
downloads/ downloads/
eggs/ eggs/
lib/ lib/

View File

@ -1 +0,0 @@
3.9.1

View File

@ -2,6 +2,12 @@
Use python version > 3.8 Use python version > 3.8
## Build
```bash
pyinstaller -F github_mirror.py
```
## Argumetns: ## Argumetns:
@ -46,3 +52,10 @@ python3 github_mirror.py [-h] [-g GROUP] (-u URLS [URLS ...] | -f FILE) -t TOKEN
python3 github_mirror.py -f github_mirrors.txt -u "https://github.com/s3rius/FastAPI-template.git" -t "gtb-QwertY125kde" python3 github_mirror.py -f github_mirrors.txt -u "https://github.com/s3rius/FastAPI-template.git" -t "gtb-QwertY125kde"
python3 github_mirror.py --giturl "https://gitea.company.ru" -t "gtb-QwertY1245kde" -u "https://github.com/Balshgit/sonar-scanner.git" -g "Personal" -T "ghb-Qwerty321ldf" python3 github_mirror.py --giturl "https://gitea.company.ru" -t "gtb-QwertY1245kde" -u "https://github.com/Balshgit/sonar-scanner.git" -g "Personal" -T "ghb-Qwerty321ldf"
## Create Bin
```bash
pyinstaller github_mirror.py -F
```

View File

@ -1,5 +1,6 @@
import random import random
from typing import Union from typing import Union
from http import HTTPStatus
import requests import requests
from requests import Response from requests import Response
@ -9,11 +10,20 @@ from core.utils import logger
class RepositoryCreator: class RepositoryCreator:
def __init__(self, git_url: str, headers: dict): def __init__(self, git_url: str, headers: dict) -> None:
self.git_url = git_url self.git_url = git_url
self.headers = headers self.headers = headers
self.HTTP_201_CREATED = 201
self.HTTP_200_OK = 200 def create_repository_mirror(self, github_url: str, group_id: str, auth_token: str) -> None:
"""
Base action for one thread. Creates repository, add mirror url and triggers pull at te end
:param github_url: GitGub url which will be mirrored
:param group_id: Gitlab group id which contains created repository
:param auth_token: GitGub token to access private repositories
"""
self.__create_new_project(github_url, group_id, auth_token)
def __git_request(self, method: str, url: str, data: dict = None) -> Union[Response, None]: def __git_request(self, method: str, url: str, data: dict = None) -> Union[Response, None]:
""" """
@ -53,26 +63,14 @@ class RepositoryCreator:
request = self.__git_request('POST', f'{self.git_url}/api/v1/repos/migrate', git_data) request = self.__git_request('POST', f'{self.git_url}/api/v1/repos/migrate', git_data)
try: try:
if request.status_code == self.HTTP_201_CREATED: if request.status_code == HTTPStatus.CREATED:
repo_data = request.json() response = request.json()
name_with_namespace = repo_data.get('full_name', None) name_with_namespace = response.get('full_name', None)
if name_with_namespace: if name_with_namespace:
logger.info(f'Repository {name_with_namespace} has been created') logger.info(f'Repository {name_with_namespace} has been created')
else: else:
logger.info(f'Repository {repo_data["name"]} has been created') logger.info(f'Repository {response["name"]} has been created')
return repo_data['id']
else: else:
logger.error(f'Cant create {name} project. Status code: {request.status_code}. Reason: {request.text}') logger.error(f'Cant create {name} project. Status code: {request.status_code}. Reason: {request.text}')
except AttributeError: except AttributeError:
pass pass
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
:param github_url: GitGub url which will be mirrored
:param group_id: Gitlab group id which contains created repository
:param auth_token: GitGub token to access private repositories
"""
self.__create_new_project(github_url, group_id, auth_token)

View File

@ -27,7 +27,7 @@ else:
logger.addHandler(console_handler) logger.addHandler(console_handler)
def threads_ready_statistic(threads: List[Thread]): def threads_ready_statistic(threads: List[Thread]) -> None:
""" """
Getting information how many threads are running right now Getting information how many threads are running right now

BIN
dist/github_mirror vendored Executable file

Binary file not shown.

View File

@ -6,7 +6,7 @@ from core.repo_creator import RepositoryCreator
from core.utils import logger, threads_ready_statistic from core.utils import logger, threads_ready_statistic
def main(): def main() -> None:
parser = create_parser() parser = create_parser()
args = parser.parse_args(sys.argv[1:]) args = parser.parse_args(sys.argv[1:])

View File

@ -1 +1,2 @@
requests requests
pyinstaller