How to clone all projects of a group at once in GitLab?

后端 未结 15 1485
[愿得一人]
[愿得一人] 2020-12-23 02:02

In my GitLab repository, I have a group with 20 projects. I want to clone all projects at once. Is that possible?

15条回答
  •  自闭症患者
    2020-12-23 02:49

    An updated Python 3 script that accomplishes this really effectively using Gitlab's latest api and proper pagination:

    import requests
    import subprocess, shlex
    import os
    
    print('Starting getrepos process..')
    
    key = '12345678901234567890' # your gitlab key
    base_url = 'https://your.gitlab.url/api/v4/projects?simple=true&per_page=10&private_token='
    url = base_url + key
    
    base_dir = os.getcwd()
    
    while True:
        print('\n\nRetrieving from ' + url)
        response = requests.get(url, verify = False)
        projects = response.json()
    
        for project in projects:
            project_name = project['name']
            project_path = project['namespace']['full_path']
            project_url = project['ssh_url_to_repo']
    
            os.chdir(base_dir)
            print('\nProcessing %s...' % project_name)
    
            try:
                print('Moving into directory: %s' % project_path)
                os.makedirs(project_path, exist_ok = True)
                os.chdir(project_path)
                cmd = shlex.split('git clone --mirror %s' % project_url)
                subprocess.run(cmd)
            except Exception as e:
                print('Error: ' + e.strerror)
    
        if 'next' not in response.links:
            break
    
        url = response.links['next']['url'].replace('127.0.0.1:9999', 'your.gitlab.url')
    
    
    print('\nDone')
    

    Requires the requests library (for navigating to the page links).

提交回复
热议问题