将作者排除在gerrit审查之外



我想禁止更改的作者在gerrit中查看他/她自己的更改。我知道这个建议的破解,但这并不能真正解决问题。

现在,我从gerrit问题中了解到,gerrit的硬编码规则可以通过自定义prolog代码进行修改,因此应该可以根据我的需要修改工作流。然而,我以前从未修改过gerrit的工作流程,我对prolog也不太了解。

有人使用这个prolog引擎为gerrit提供自定义规则的小示例吗?

我很乐意接受如何禁止作者进行自我审查的其他选择,因为他们不需要我的团队更改当前的工作流程。

我在这个谷歌小组中找到了一个非常简单的答案:groups.google.com/disable-self-review

在父项目(默认为All Projects项目)中,将其添加到refs/meta/config分支中的project.config文件中:

[access "refs/*"]
label-Code-Review = block -2..+2 group Change Owner

并且在同一分支中的组文件中添加这一行

global:Change-Owner Change Owner

然后将允许权限进入子项目的project.config:的语句

label-Code-Review = -2..+2 group Developers

确保在父项目中编写block语句,并在子项目中授予权限。如果allow和block在同一个文件中,allow将否决(请参阅此)。这将阻止更改为-2或+2的所有者。它将保留-1和+1选项不变。您可以为可能使用的任何其他自定义标签添加类似的语句。

我不确定这是你想要的,但它可能会给你一些灵感。根据这一讨论,只有当审阅者和更改所有者不是同一个人时,以下片段才会批准更改。

  % If a reviewer approved the change, its OK.
  submit_rule(submit(CR)) :-
    change_owner(Owner),
    max_with_block('Code-Review', -2, 2, ok(Reviewer)),
    not_same(Owner, Reviewer),
    CR = label('Code-Review', ok(Reviewer)),
    !.

如果您还没有找到它,下面是关于如何使用prolog实现这一点的官方描述:

https://gerrit-review.googlesource.com/Documentation/prolog-cookbook.html#_example_8_make_change_submittable_only_if_tt_code_review_2_tt_is_given_by_a_non_author

我发布了你链接到的问题的答案,但它可能会引导你朝着正确的方向前进:

我为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标签实际上是一个红旗
  • 作为submit_filter而不是submit_rule,此规则安装在父项目中并适用于所有子项目

请注意:编写此规则是为了防止Owner自行审查更改,同时将食谱中的示例与Author进行比较。根据您的工作流程,您可能希望用gerrit:commit_author(O)gerrit:commit_committer(O) 替换2个gerrit:change_owner(O)谓词

下面的prolog代码将绕过用户/管理员帐户的自我审查阻止,并阻止所有其他提交作者在Gerrit repo中进行自我审查。这个代码对我有效。

submit_rule(S) :-
    gerrit:default_submit(X),
    X =.. [submit | Ls],
    add_non_author_approval(Ls, R),
    S =.. [submit | R].
add_non_author_approval(S1, S2) :-
    C = user(000000),
    gerrit:commit_author(C),
    gerrit:commit_label(label('Code-Review', 2), R),
    R == C, !,
    S2 = [label('Non-Author-Code-Review', ok(C)) | S1].
add_non_author_approval(S1, S2) :-
    gerrit:commit_author(A),
    gerrit:commit_label(label('Code-Review', 2), R),
    R = A, !,
    S2 = [label('Non-Author-Code-Review', ok(A)) | S1].
add_non_author_approval(S1, [label('Non-Author-Code-Review', need(_)) | S1]).

最新更新