Я только что написал этот пролог-фильтр для нашей установки Gerrit. Я сделал это как 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).
Преимущества (IMO) этого правила по сравнению с правилом №8 из кулинарной книги< /а> являются:
- Метка
Self-Reviewed
отображается только тогда, когда изменение заблокировано, а не добавляется метка Non-Author-Code-Review
к каждому изменению.
- Использование правила
reject(O)
приводит к тому, что метка Self-Reviewed
буквально становится красным флажком.
- Как
submit_filter
вместо submit_rule
, это правило устанавливается в родительском проекте и применяется ко всем подпроектам.
Обратите внимание: это правило создано для предотвращения самостоятельной проверки изменения Owner
, в то время как пример из поваренной книги сравнивается с Author
. В зависимости от вашего рабочего процесса вы можете заменить 2 предиката gerrit:change_owner(O)
на gerrit:commit_author(O)
или gerrit:commit_committer(O)
.
person
hair raisin
schedule
16.06.2016