I want to disallow the author of a change to review his/her own changes in gerrit. I'm aware of this suggested hack, but that doesn't really solve the issue.
Now I learned from the gerrit issues that gerrit's hardcoded rules can be modified by custom prolog code, so it should potentially be possible to modify the workflow as I want. However, I have never modified gerrit's workflow before and I don't know much prolog.
Does anyone have a small working example of custom rules for gerrit using this prolog engine?
I will happily accept other alternatives of how to forbid authors doing a self-review, given they do not require my team to change the current workflow.
I'm not sure that this what you are looking for but it might give you some inspiration. According to this discussion the following fragment approves changes only if the reviewer and the change owner are not the same person.
If you haven't found it already, here is the official description on how to do this using 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
I found a very easy answer in this google group: groups.google.com/disable-self-review
In a parent project (default is the All-Projects project) add this to the project.config file in refs/meta/config branch:
and in the groups file in the same branch add this line
Then take the statement that allows the right into the child project's project.config:
Make sure to do write the block statement in the parent project and give the rights in the child project. If allow and block are in the same file the allow will overrule (See this). This will block the owner of a change to give -2 or +2. It will leave the -1 and +1 options intact. You can add a similar statement for any other custom labels you might use.
I posted this answer to the question that you linked to, but it may lead you in the right direction:
I wrote this prolog filter for our Gerrit installation. I did it as a submit_filter in the parent project because I wanted it to apply to all projects in our system.
The benefits (IMO) of this rule over rule #8 from the cookbook are:
Self-Reviewed
label is only shown when the the change is being blocked, rather than adding aNon-Author-Code-Review
label to every changereject(O)
the rule causes theSelf-Reviewed
label to literally be a red flagsubmit_filter
instead of asubmit_rule
, this rule is installed in a parent project and applies to all sub-projectsPlease Note: This rule is authored to prevent the
Owner
from self-reviewing a change, while the example from the cookbook compares against theAuthor
. Depending on your workflow, you may want to replace the 2gerrit:change_owner(O)
predicates withgerrit:commit_author(O)
orgerrit:commit_committer(O)