mirror of
https://github.com/Balshgit/get-gitlab-projects.git
synced 2025-09-11 20:40:40 +03:00
add projects from gitlab
This commit is contained in:
commit
68b8e4d9f9
1
get_project_core/.env.example
Normal file
1
get_project_core/.env.example
Normal file
@ -0,0 +1 @@
|
|||||||
|
X5_SCM_TOKEN=-xczQ_2we3ms8BAzkMNZ
|
1
get_project_core/.gitignore
vendored
Normal file
1
get_project_core/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.env
|
4
get_project_core/__init__.py
Normal file
4
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)
|
28
get_project_core/settings.py
Normal file
28
get_project_core/settings.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import importlib.util
|
||||||
|
import logging
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
current_dir = Path(__file__).parent.parent
|
||||||
|
|
||||||
|
|
||||||
|
# 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_project_core/update-repos.sh
Executable file
3
get_project_core/update-repos.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
git pull --all
|
46
get_projects.py
Normal file
46
get_projects.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import json # noqa # pylint: disable=unused-import
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
import requests
|
||||||
|
from get_project_core.settings import current_dir, logger # ,config
|
||||||
|
|
||||||
|
|
||||||
|
MY_GITLAB_TOKEN=''
|
||||||
|
headers = {'PRIVATE-TOKEN': MY_GITLAB_TOKEN}
|
||||||
|
|
||||||
|
|
||||||
|
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__':
|
||||||
|
args = sys.argv[1:]
|
||||||
|
try:
|
||||||
|
group = args[0]
|
||||||
|
logger.info(group)
|
||||||
|
except IndexError:
|
||||||
|
logger.error('Gitlab group id must be set')
|
Loading…
x
Reference in New Issue
Block a user