使用python clone gitlab所有可见项目

import json
import shlex
import subprocess
import time
from urllib.request import urlopen

allProjects = urlopen("http://ip:port/api/v4/projects?membership=true&private_token=aaaaaaaaaaaaa")
allProjectsDict = json.loads(allProjects.read().decode())
for thisProject in allProjectsDict:
    try:
        thisProjectURL = thisProject['ssh_url_to_repo']
        name_with_namespace = thisProject['path_with_namespace']
        command = shlex.split('git clone %s %s' % (thisProjectURL, 'G:/gitClone/'+name_with_namespace))
        resultCode = subprocess.Popen(command)
    except Exception as e:
        print("Error on %s: %s" % (thisProjectURL, e.strerror))
    time.sleep(5)

另外urlopen中的api来源于api,可以酌情替换

你可能感兴趣的:(工具使用)