0

我正在使用python-gitlab来帮助配置项目。我正在尝试自动进入 GitLab 设置 > 存储库 > 受保护的分支,然后对于现有的主分支,将“允许合并”从“维护者”更改为“开发人员 + 维护者”。这是一个代码片段:

import gitlab
gl = gitlab.Gitlab.from_config()
project = project = gl.projects.get("my-team/my_project")
master_branch = project.protectedbranches.get("master")
print(master_branch.merge_access_levels)

数据类型只是一个字典列表;似乎没有办法像此 API 中的其他设置一样更新设置。即使你只是更新它:

master_branch.merge_access_levels[0]['access_level'] = 30
project.save()

什么都没发生。有没有办法用 python-gitlab 做到这一点?

谢谢!

4

1 回答 1

2

您正在寻找branch.protect()

    branch = project.branches.get('master')
    branch.protect(developers_can_push=True, developers_can_merge=True)
于 2021-07-31T20:18:26.720 回答