我刚刚为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
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).
此规则在rule #8 from the cookbook的好处(IMO)是:
- 当所述变化被阻止的
Self-Reviewed
标签中仅示出,而不是添加Non-Author-Code-Review
标签每变化
- 通过使用
reject(O)
该规则导致Self-Reviewed
标签字面上成为红色标志
- 作为
submit_filter
代替submit_rule
,这个规则被安装在一个父项目,并适用于所有的子项目
请注意:此规则编写,以防止自我审查的变化Owner
,而例如从食谱与Author
比较。根据您的工作流程,您可能需要用gerrit:commit_author(O)
或替换2 gerrit:change_owner(O)
谓词或
你确定你必须强制吗?程序员是聪明的人,只是把它作为一个规则。在某些角落案例中,审查自己的代码可能很有用(例如,代码已经过审查,但您在提交消息中修复了拼写错误,在这种情况下,其他审阅将会失去时间)。 – 2011-12-05 21:57:47
@TomaszWysocki我只能说,程序员在处理过程中远非聪明。我一直在Gerrit寻找这个功能,因为愚蠢的开发人员。您想要查看您自己的工作的具体示例会打开整个系统,导致错误使用。是否要求另一位同行评论者回顾简单的改变!只需添加我是一名开发人员。 – Tnem 2012-01-13 08:34:03
看到这个答案:[使用块语句](https://stackoverflow.com/questions/11560812/exclude-author-from-gerrit-review/47887713#47887713) – very 2017-12-19 13:09:35