我发布了对您链接到的问题的答案,但它可能会引导您朝着正确的方向前进:
我为我们的 Gerrit 安装编写了这个 prolog 过滤器。我在父项目中将其作为 submit_filter 进行,因为我希望它适用于我们系统中的所有项目。
%filter to require all projects to have a code-reviewer other than the owner
submit_filter(In, Out) :-
%unpack the submit rule into a list of code reviews
In =.. [submit | Ls],
%add the non-owner code review requiremet
reject_self_review(Ls, R),
%pack the list back up and return it (kinda)
Out =.. [submit | R].
reject_self_review(S1, S2) :-
%set O to be the change owner
gerrit:change_owner(O),
%find a +2 code review, if it exists, and set R to be the reviewer
gerrit:commit_label(label('Code-Review', 2), R),
%if there is a +2 review from someone other than the owner, then the filter has no work to do, assign S2 to S1
R \= O, !,
%the cut (!) predicate prevents further rules from being consulted
S2 = S1.
reject_self_review(S1, S2) :-
%set O to be the change owner
gerrit:change_owner(O),
%find a +2 code review, if it exists, and set R to be the reviewer - comment sign was missing
gerrit:commit_label(label('Code-Review', 2), R),
R = O, !,
%if there isn't a +2 from someone else (above rule), and there is a +2 from the owner, reject with a self-reviewed label
S2 = [label('Self-Reviewed', reject(O))|S1].
%if the above two rules didn't make it to the ! predicate, there aren't any +2s so let the default rules through unfiltered
reject_self_review(S1, S1).
这条规则相对于食谱中的规则 #8的好处 (IMO)是:
- 标签仅在
Self-Reviewed
更改被阻止时显示,而不是为每个更改添加Non-Author-Code-Review
标签
- 通过使用
reject(O)
该规则,Self-Reviewed
标签实际上是一个危险信号
- 作为 a
submit_filter
而不是 a submit_rule
,此规则安装在父项目中并适用于所有子项目
请注意:创建此规则是为了防止Owner
自我审查更改,而食谱中的示例与Author
. 根据您的工作流程,您可能希望将 2 个gerrit:change_owner(O)
谓词替换为gerrit:commit_author(O)
orgerrit:commit_committer(O)