Created
April 2, 2020 11:42
-
-
Save Miouge1/12f315ae69afccd44e20d5eaff53d4a1 to your computer and use it in GitHub Desktop.
git clone a whole gitlab group
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import configparser | |
import gitlab | |
import os | |
import sys | |
import argparse | |
import time | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--group') | |
parser.add_argument('--sleep', default=0, type=int) | |
args = parser.parse_args() | |
if __name__ == '__main__': | |
token = os.environ.get('GITLAB_TOKEN', '') | |
api = os.environ.get('GITLAB_API', 'https://gitlab.com') | |
gl = gitlab.Gitlab(api, token, api_version=4) | |
gl.auth() | |
config = configparser.ConfigParser() | |
projects = gl.projects.list(all=True, archived=False) | |
print("Found " + str(len(projects)) + " projects") | |
for project in projects: | |
if project.path_with_namespace.startswith(args.group): | |
project_path = './' + project.path_with_namespace[len(args.group):] | |
print('Cloning ' + project.ssh_url_to_repo + ' into project_path') | |
os.system('git clone ' + project.ssh_url_to_repo + ' ' + project_path) | |
time.sleep(args.sleep) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment