批量迁移GitLab项目

使用Python2.7编写的脚本,能够高效地批量迁移GitLab上的项目,帮助用户实现便捷的数据迁移。

该脚本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))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

枫叶Fy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值