在腳本的同目錄下需要創(chuàng)建一個名為“add-list.txt”的文件,用于存放需要創(chuàng)建的projects,運行時要輸入projects需要加入的指定組的ID,也可以都扔到一個組中,建完projects后直接transfer到相關(guān)組。
新民網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),新民網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為新民近千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)要多少錢,請找那個售后服務(wù)好的新民做網(wǎng)站的公司定做!
#/usr/bin/Python27
# coding=utf-8
import gitlab
gl = gitlab.Gitlab('http://10.50.30.33/', private_token='fffghjjjkkllljwj')
gid = int(raw_input('GroupID: ')) #project需要放置的Group的ID
group = gl.groups.get(gid)
print group.name
pid = []
path = 'add-list.txt'
with open(path,'r') as f:
for line in f.readlines():
serv = line.strip()
project = gl.projects.create({'name': serv, 'namespace_id': gid,'path':serv})
branch = project.branches.create({'branch': 'develop','ref': 'master'}) #創(chuàng)建分支1:develop,可以自己修改
branch = project.branches.create({'branch': 'qa_release','ref': 'develop'}) #創(chuàng)建分支2:qa_release,可以自己修改調(diào)整
branches = project.branches.list()
print project.name,project.id,branches
pid.append(project.id)
for num in pid:
i = int(num)
project = gl.projects.get(i)
project.default_branch = 'develop' #設(shè)置默認分支為develop,可自行修改
project.save()
print project.name,project.http_url_to_repo,project.default_branch