mirror of
https://github.com/Balshgit/github_mirror.git
synced 2025-09-11 22:40:44 +03:00
Compare commits
No commits in common. "4704763995b29ad66f486f93deae903d5d004aee" and "2a683e09f3b7d13a929b28c87e9a433aa0cb6aee" have entirely different histories.
4704763995
...
2a683e09f3
2
.gitignore
vendored
2
.gitignore
vendored
@ -63,7 +63,7 @@ __pycache__/
|
|||||||
.Python
|
.Python
|
||||||
env/
|
env/
|
||||||
develop-eggs/
|
develop-eggs/
|
||||||
# dist/
|
dist/
|
||||||
downloads/
|
downloads/
|
||||||
eggs/
|
eggs/
|
||||||
lib/
|
lib/
|
||||||
|
1
.python-version
Normal file
1
.python-version
Normal file
@ -0,0 +1 @@
|
|||||||
|
3.9.1
|
@ -2,12 +2,6 @@
|
|||||||
|
|
||||||
Use python version > 3.8
|
Use python version > 3.8
|
||||||
|
|
||||||
## Build
|
|
||||||
|
|
||||||
```bash
|
|
||||||
pyinstaller -F github_mirror.py
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Argumetns:
|
## Argumetns:
|
||||||
|
|
||||||
@ -31,7 +25,7 @@ pyinstaller -F github_mirror.py
|
|||||||
- ```Please provide github token to get access to private repositories``` [github tokens](https://github.com/settings/tokens)
|
- ```Please provide github token to get access to private repositories``` [github tokens](https://github.com/settings/tokens)
|
||||||
|
|
||||||
|
|
||||||
- -l GITURL, --giturl GITURL ```Provide git url. Default link``` https://git.mywistr.ru
|
- -l GITURL, --giturl GITURL ```Provide git url. Default link``` https://git.mywistr.com
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
GIT_URL = 'https://git.mywistr.ru'
|
GIT_URL = 'https://git.mywistr.com'
|
||||||
|
|
||||||
USAGE = '''github_mirror [-h] [-g GROUP] (-u URLS [URLS ...] | -f FILE) -t TOKEN [-T GitHubTOKEN]
|
USAGE = '''github_mirror [-h] [-g GROUP] (-u URLS [URLS ...] | -f FILE) -t TOKEN [-T GitHubTOKEN]
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
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
|
||||||
@ -10,22 +9,13 @@ from core.utils import logger
|
|||||||
|
|
||||||
class RepositoryCreator:
|
class RepositoryCreator:
|
||||||
|
|
||||||
def __init__(self, git_url: str, headers: dict) -> None:
|
def __init__(self, gitlab_url: str, headers: dict):
|
||||||
self.git_url = git_url
|
self.gitlab_url = gitlab_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:
|
def __gitlab_request(self, method: str, url: str, data: dict = None) -> Union[Response, 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]:
|
|
||||||
"""
|
"""
|
||||||
Create request to gitlab
|
Create request to gitlab
|
||||||
|
|
||||||
@ -61,16 +51,28 @@ class RepositoryCreator:
|
|||||||
if auth_token:
|
if auth_token:
|
||||||
git_data['auth_token'] = auth_token
|
git_data['auth_token'] = auth_token
|
||||||
|
|
||||||
request = self.__git_request('POST', f'{self.git_url}/api/v1/repos/migrate', git_data)
|
request = self.__gitlab_request('POST', f'{self.gitlab_url}/api/v1/repos/migrate', git_data)
|
||||||
try:
|
try:
|
||||||
if request.status_code == HTTPStatus.CREATED:
|
if request.status_code == self.HTTP_201_CREATED:
|
||||||
response = request.json()
|
repo_data = request.json()
|
||||||
name_with_namespace = response.get('full_name', None)
|
name_with_namespace = repo_data.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 {response["name"]} has been created')
|
logger.info(f'Repository {repo_data["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)
|
||||||
|
@ -27,7 +27,7 @@ else:
|
|||||||
logger.addHandler(console_handler)
|
logger.addHandler(console_handler)
|
||||||
|
|
||||||
|
|
||||||
def threads_ready_statistic(threads: List[Thread]) -> None:
|
def threads_ready_statistic(threads: List[Thread]):
|
||||||
"""
|
"""
|
||||||
Getting information how many threads are running right now
|
Getting information how many threads are running right now
|
||||||
|
|
||||||
|
BIN
dist/github_mirror
vendored
BIN
dist/github_mirror
vendored
Binary file not shown.
@ -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() -> None:
|
def main():
|
||||||
|
|
||||||
parser = create_parser()
|
parser = create_parser()
|
||||||
args = parser.parse_args(sys.argv[1:])
|
args = parser.parse_args(sys.argv[1:])
|
||||||
@ -24,10 +24,10 @@ def main() -> None:
|
|||||||
# parse gitlab group of repositories if it exists
|
# parse gitlab group of repositories if it exists
|
||||||
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.ru
|
git_url = args.giturl # if not provided used default value https://git.mywistr.com
|
||||||
headers = {'Authorization': f'token {args.token}'} # git user token must be provided
|
headers = {'Authorization': f'token {args.token}'} # git user token must be provided
|
||||||
|
|
||||||
repository_creator = RepositoryCreator(git_url=git_url, headers=headers)
|
repository_creator = RepositoryCreator(gitlab_url=git_url, headers=headers)
|
||||||
|
|
||||||
github_token = args.githubtoken if args.githubtoken else None # used for access to personal GitHub repositories
|
github_token = args.githubtoken if args.githubtoken else None # used for access to personal GitHub repositories
|
||||||
|
|
||||||
|
@ -1,2 +1 @@
|
|||||||
requests
|
requests
|
||||||
pyinstaller
|
|
Loading…
x
Reference in New Issue
Block a user