我的团队正在使用Gitlab Premium。在项目设置中,根据合并请求批准,有一个批准规则部分。在第一行中,我们将所需的批准编号提高到1,以便每个合并请求必须至少由其他一个队友批准。到目前为止,一切都很好。
我可以看到,还有一个许可检查规则和 coverage-check-check 规则,可以启用,而他们所做的事情是相当不言自明的。还有一个添加批准规则按钮,您可以在其中为新规则设置名称和批准者,但是您实际上无法描述/选择实际规则应该是什么。我能找到的所有文档只需说明如何单击该UI即可。
您如何实际设置新规则,并且可以编写自己的自定义规则吗?
例如,我们想设置一个规则,只有团队的一个子集才能批准“大”合并请求(其中“大”是由更改的行数定义的,如GIT日志所报告)。我想这将类似于许可检查或覆盖范围检查,但由我们写。有可能吗?
My team is using GitLab Premium. In the project settings, under Merge request approvals, there is an Approval rules section. In the first row, we increased the Approvals required number to 1 so that every merge request must be approved by at least one other teammate. So far so good.
I can see there is also a License-Check rule and Coverage-Check rule that can be enabled and what they do is pretty self-explanatory. There is also an Add approval rule button where you can set a name and approvers for a new rule, but you can't actually describe/choose what the actual rule should be. All the documentation I could find simply explains how to click around that UI.
How do you actually set new rules and is it possible to write own custom rules?
For example, we'd like to set a rule that only a subset of the team can approve "large" merge requests (where "large" is defined by the number of lines changed, as reported by git log). I imagine that would be something similar to License-Check or Coverage-Check, but written by us. Is that possible?
发布评论
评论(2)
我认为这是不可能的。目前,批准规则是特定于分支机构的。合并请求的内容无关紧要。
但是,我认为您有一个解决方案:GitLab允许您编写可以访问Gitlab API的机器人。您需要的是聆听新合并请求的外部服务。然后,您的工具将不得不以某种方式找出实际进行了多少个更改(合并请求api )。根据此的不同,您可以通过API通过API进行相应的MR()。
这种方法对您有帮助吗?
您也可以在
I don't think this is possible yet. For now, approval rules are branch-specific. The content of a merge request doesn't matter.
Nevertheless, I think there is a solution for you: GitLab allows you to write bots that can access the GitLab API. What you'd need is an external service listening to new merge requests. Your tool would then have to find out in some way how many changes were actually made (this is not yet possible with the Merge Request API as far as I can tell). Depending on this, you can then adjust the approval rules via the API for the corresponding MR (API reference).
Does this approach help you?
You can also ask a question in the GitLab Community Forum, there you might get better help.
实际上,批准规则将适用于分支机构,或所有分支机构,或者,因为 gitlab 15.3 (2022年8月):
但这与其他规则不同,这些规则无法轻易通过批准规则复制。
gitlab 15.9 (2023年2月)提供了一种新选择,但仅用于高级或最终:
请注意,拒绝许可检查(在gitlab 16.0+中删除)。
Gitlab Ultimate提出。
Actually, an Approval Rule would apply to a branch, or all branches or, since GitLab 15.3 (August 2022):
But that differs other rules, which cannot easily be replicated through Approval rules.
GitLab 15.9 (February 2023) provides a new option, but only for Premium or Ultimate:
Note that License-Check is deprecated (to be removed in GitLab 16.0+).
GitLab Ultimate proposes flexible license approval policies.