该脚本Python2.7可用,批量将GitLab项目进行迁移
# -*- coding: UTF-8 -*-
# 在Python3.0测试通过
# 需要在gitlab里面新建一个AccessToken
import urllib
import json
import subprocess, shlex
import time
import os
gitlabAddr = '[GitLab具体地址]'
gitlabToken = '[Access Token]'
group = '[具体项目分组]'
for index in range(10):
url = "http://%s/api/v4/groups/%s/projects?private_token=%s&per_page=100&page=%d&order_by=name" % (gitlabAddr, group, gitlabToken, index)
print(url)
allProjects = urllib.urlopen(url)
allProjectsDict = json.loads(allProjects.read().decode(encoding='UTF-8'))
if len(allProjectsDict) == 0:
break
for thisProject in allProjectsDict:
try:
thisProjectURL = thisProject['ssh_url_to_repo']
thisProjectPath = thisProject['path_with_namespace']
print(thisProjectURL + ' ' + thisProjectPath)
if os.path.exists(thisProjectPath):
command = shlex.split('git -C "%s" pull' % (thisProjectPath))
else:
command = shlex.split('git clone %s %s' % (thisProjectURL, thisProjectPath))
resultCode = subprocess.Popen(command)
time.sleep(1)
except Exception as e:
print("Error on %s: %s" % (thisProjectURL, e.strerror))
使用Python2.7编写的脚本,能够高效地批量迁移GitLab上的项目,帮助用户实现便捷的数据迁移。

4840

被折叠的 条评论
为什么被折叠?



