Add config and rule to ignore self approval on labels

A frequently used Prolog rule is to ignore self approvals when
evaluating labels. The simple-submit-rules plugin has created such a
rule in Java instead of Prolog. All of the other label functions are
handled directly in core so it seems like a good fit, to also just port
this one into Gerrit core given that it is used quite often.

The new rule gets added as a separate rule so that we grow the
SubmitRules implementations more atomically (instead of just adding it
to DefaultRule).

We add tests that are mainly also just ported from simple-submit-rules.
Besides BUILD file and reference changes, the code was migrated to use
Flogger and we are more indicative to the user in case the uploader is the
only one who approved the change by adding an additional requirement.

The rule uses the uploader to make it easier to explain it to users.
Basing it on the author would come with the confusion that when you
cherry pick a change, you can self approve in case the author of the
original patch set was someone else. Basing it on the change owner would
mean you can hijack any change by uploading a patch set to submit
self-reviewed code.

Change-Id: I78b97f60ca1bb4aaf5386103c9228f76974feea4
This commit is contained in:
Patrick Hiesel
2018-09-03 13:19:08 +02:00
parent 460a3f3c35
commit 12c87c7b78
9 changed files with 402 additions and 0 deletions

View File

@@ -170,6 +170,7 @@ import com.google.gerrit.server.query.change.ConflictsCacheImpl;
import com.google.gerrit.server.restapi.change.SuggestReviewers;
import com.google.gerrit.server.restapi.group.GroupModule;
import com.google.gerrit.server.rules.DefaultSubmitRule;
import com.google.gerrit.server.rules.IgnoreSelfApprovalRule;
import com.google.gerrit.server.rules.PrologModule;
import com.google.gerrit.server.rules.RulesCache;
import com.google.gerrit.server.rules.SubmitRule;
@@ -244,6 +245,7 @@ public class GerritGlobalModule extends FactoryModule {
install(new NoteDbModule(cfg));
install(new PrologModule());
install(new DefaultSubmitRule.Module());
install(new IgnoreSelfApprovalRule.Module());
install(new ReceiveCommitsModule());
install(new SshAddressesModule());
install(ThreadLocalRequestContext.module());