找了好久,终于搞定了。只能master分支保护只能限制在no one,如果需要开的话,再取消保护
import gitlab
gl = gitlab.Gitlab(url, private_token='******')
project = · gl.projects.get('project-test')
#加保护
p_branch = project.protectedbranches.create({
'name':'master',
'merge_access_level':0,
'push_access_level':0
})
#去保护
branch = project.branches.get('master')
branch.unprotect()