自动导出gitab 有权限的所有仓库

下面是一个脚本,自动导出所有仓库

import requests
import os

# Replace these with your GitLab details
GITLAB_URL = 'https://gitlab.com'
PRIVATE_TOKEN = 'your_private_token'
GROUP_ID = 'your_group_id'

# Function to get all repositories in the group
def get_repositories():
    headers = {'PRIVATE-TOKEN': PRIVATE_TOKEN}
    repos = []
    page = 1
    while True:
        response = requests.get(f'{GITLAB_URL}/api/v4/groups/{GROUP_ID}/projects?page={page}&per_page=100', headers=headers)
        if response.status_code != 200:
            break
        data = response.json()
        if not data:
            break
        repos.extend(data)
        page += 1
    return repos

# Function to clone repositories
def clone_repositories(repos):
    for repo in repos:
        repo_name = repo['name']
        repo_http_url = repo['http_url_to_repo']
        os.system(f'git clone {repo_http_url}')

if __name__ == '__main__':
    repos = get_repositories()
    clone_repositories(repos)

分类: 默认 标签: GitLab repositories clone requests os 发布于: 2024-11-22 15:18:41, 点击数: