mirror of
https://github.com/Balshgit/different
synced 2025-09-11 02:50:41 +03:00
add gitlab submodules script
This commit is contained in:
parent
0553e40711
commit
9e71c4cb53
4
.gitignore
vendored
4
.gitignore
vendored
@ -221,8 +221,8 @@ media/
|
|||||||
|
|
||||||
|
|
||||||
# Configuration file with private data:
|
# Configuration file with private data:
|
||||||
# *.env
|
*.env
|
||||||
# .env
|
.env
|
||||||
|
|
||||||
# Local settings files:
|
# Local settings files:
|
||||||
*local.py
|
*local.py
|
||||||
|
1
get-gitlab-projects/get_project_core/.gitignore
vendored
Normal file
1
get-gitlab-projects/get_project_core/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.env
|
4
get-gitlab-projects/get_project_core/__init__.py
Normal file
4
get-gitlab-projects/get_project_core/__init__.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import requests
|
||||||
|
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
||||||
|
|
||||||
|
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
30
get-gitlab-projects/get_project_core/settings.py
Normal file
30
get-gitlab-projects/get_project_core/settings.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import importlib.util
|
||||||
|
import logging
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from decouple import AutoConfig
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
current_dir = Path(__file__).parent.parent
|
||||||
|
config = AutoConfig(search_path=current_dir.joinpath('get_project_core'))
|
||||||
|
|
||||||
|
|
||||||
|
# use loguru if it is possible for color output
|
||||||
|
if importlib.util.find_spec('loguru') is not None:
|
||||||
|
from loguru import logger
|
||||||
|
logger.remove()
|
||||||
|
logger.add(sink=sys.stdout, colorize=True, level='DEBUG',
|
||||||
|
format="<cyan>{time:DD.MM.YYYY HH:mm:ss}</cyan> | <level>{level}</level> | "
|
||||||
|
"<magenta>{message}</magenta>")
|
||||||
|
|
||||||
|
# use standard logging
|
||||||
|
else:
|
||||||
|
logger = logging.getLogger()
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
console_handler = logging.StreamHandler()
|
||||||
|
console_handler.setLevel(logging.INFO)
|
||||||
|
log_formatter = logging.Formatter("%(asctime)s | %(levelname)s | %(message)s")
|
||||||
|
console_handler.setFormatter(log_formatter)
|
||||||
|
|
||||||
|
logger.addHandler(console_handler)
|
3
get-gitlab-projects/get_project_core/update-repos.sh
Executable file
3
get-gitlab-projects/get_project_core/update-repos.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
git pull --all
|
40
get-gitlab-projects/get_projects.py
Normal file
40
get-gitlab-projects/get_projects.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import json # noqa # pylint: disable=unused-import
|
||||||
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
from get_project_core.settings import logger, config, current_dir
|
||||||
|
|
||||||
|
headers = {'PRIVATE-TOKEN': config('X5_SCM_TOKEN', cast=str)}
|
||||||
|
|
||||||
|
|
||||||
|
def create_repositories(group_id: int):
|
||||||
|
"""
|
||||||
|
Create submodules from gitlab group
|
||||||
|
|
||||||
|
:param group_id: Can be find under group name
|
||||||
|
"""
|
||||||
|
request = requests.get(f'https://scm.x5.ru/api/v4/groups/{group_id}/projects', headers=headers, verify=False)
|
||||||
|
# logger.info(f'{json.dumps(request.json(), indent=4, separators=(",", ":"))}')
|
||||||
|
|
||||||
|
repos = request.json()
|
||||||
|
|
||||||
|
for repo in repos:
|
||||||
|
name = str(repo.get("ssh_url_to_repo", None)).strip()
|
||||||
|
subprocess.Popen(['git', 'submodule', 'add', name])
|
||||||
|
logger.info(f'Created: {name}')
|
||||||
|
time.sleep(15)
|
||||||
|
|
||||||
|
|
||||||
|
def update_submodules():
|
||||||
|
"""
|
||||||
|
Update all submodules
|
||||||
|
|
||||||
|
"""
|
||||||
|
subprocess.Popen(['git', 'submodule', 'foreach', f'{current_dir}/get-project-core/update-repos.sh'])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
create_repositories(group_id=3574)
|
||||||
|
# update_submodules()
|
Loading…
x
Reference in New Issue
Block a user