作者:starry-night--_848 | 来源:互联网 | 2023-07-19 19:48
在脚本的同目录下需要创建一个名为“add-list.txt”的文件,用于存放需要创建的projects,运行时要输入projects需要加入的指定组的ID,也可以都扔
在脚本的同目录下需要创建一个名为“add-list.txt”的文件,用于存放需要创建的projects,运行时要输入projects需要加入的指定组的ID,也可以都扔到一个组中,建完projects后直接transfer到相关组。
#/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'}) #创建分支1:develop,可以自己修改
branch = project.branches.create({'branch': 'qa_release','ref': 'develop'}) #创建分支2:qa_release,可以自己修改调整
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' #设置默认分支为develop,可自行修改
project.save()
print project.name,project.http_url_to_repo,project.default_branch