Make NoBlock and NoOp approval category functions work The approval category functions NoBlock and NoOp have not worked since the integration of Prolog, and this commit makes a number of changes to remedy this. MAY is being introduced as a new submit record status to complement OK, REJECT, NEED, and IMPOSSIBLE. This allows the expression of approval categories (labels) that are optional, i.e. could either be set or unset without ever influencing whether the change could be submitted. Previously there was no way to express this property in the submit record. This enables the NoBlock and NoOp approval category functions to work as they now emit may() terms from the Prolog rules. Previously they returned ok() terms lacking a nested user term, leading to exceptions in code that expected a user context if the label was OK. A side-effect is the addition of an "optional" boolean property of the LabelInfo JSON objects, indicating whether the label in question is may be omitted and still submit the change. Change-Id: I02bedf892564f759418fa7427ac226970f9a6ef5
diff --git a/gerrit-server/src/main/prolog/gerrit_common.pl b/gerrit-server/src/main/prolog/gerrit_common.pl index 5acc831..a75acc0 100644 --- a/gerrit-server/src/main/prolog/gerrit_common.pl +++ b/gerrit-server/src/main/prolog/gerrit_common.pl
@@ -149,6 +149,7 @@ is_all_ok([]). is_all_ok([label(_, ok(__)) | Ls]) :- is_all_ok(Ls). +is_all_ok([label(_, may(__)) | Ls]) :- is_all_ok(Ls). is_all_ok(_) :- fail. @@ -209,8 +210,8 @@ %% legacy_submit_rule('MaxWithBlock', Label, Id, Min, Max, T) :- !, max_with_block(Label, Min, Max, T). legacy_submit_rule('MaxNoBlock', Label, Id, Min, Max, T) :- !, max_no_block(Label, Max, T). -legacy_submit_rule('NoBlock', Label, Id, Min, Max, T) :- !, T = ok(_). -legacy_submit_rule('NoOp', Label, Id, Min, Max, T) :- !, T = ok(_). +legacy_submit_rule('NoBlock', Label, Id, Min, Max, T) :- !, T = may(_). +legacy_submit_rule('NoOp', Label, Id, Min, Max, T) :- !, T = may(_). legacy_submit_rule(Fun, Label, Id, Min, Max, T) :- T = impossible(unsupported(Fun)).