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

后端 未结 15 1516
[愿得一人]
[愿得一人] 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:50

    An alternative based on Dmitriy's answer -- in the case you were to clone repositories in a whole group tree recursively.

    #!/usr/bin/python3
    import os
    import sys
    import gitlab
    import subprocess
    
    glab = gitlab.Gitlab(f'https://{sys.argv[1]}', f'{sys.argv[3]}')
    groups = glab.groups.list()
    root = sys.argv[2]
    
    def visit(group):
        name = group.name
        real_group = glab.groups.get(group.id)
    
        os.mkdir(name)
        os.chdir(name) 
    
        clone(real_group.projects.list(all=True))
    
        for child in real_group.subgroups.list():
            visit(child)
    
        os.chdir("../")
    
    def clone(projects):
        for repo in projects:
            command = f'git clone {repo.ssh_url_to_repo}'
            process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
            output, _ = process.communicate()
            process.wait()
    
    glab = gitlab.Gitlab(f'https://{sys.argv[1]}', f'{sys.argv[3]}')
    groups = glab.groups.list()
    root = sys.argv[2]
    
    for group in groups:
        if group.name == root:
            visit(group)
    

提交回复
热议问题