Add a new max_with_block predicate for more convenient usage
Based on Shawn's Prolog examples from the last Gerrit User Summit this
predicate should become a part of the standard library supplied by
Gerrit to rules.
For example, the typical default submit rule can be implemented as:
submit_rule(submit(V, CR)) :-
max_with_block(-2, 2, 'Code-Review', CR),
max_with_block(-1, 1, 'Verified', V).
Change-Id: Id6d9d248e5b131f8625a912f62f30492b9ebf564
Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
diff --git a/gerrit-server/src/main/prolog/gerrit_common.pl b/gerrit-server/src/main/prolog/gerrit_common.pl
index 59289c0..113f996 100644
--- a/gerrit-server/src/main/prolog/gerrit_common.pl
+++ b/gerrit-server/src/main/prolog/gerrit_common.pl
@@ -244,7 +244,6 @@
legacy_submit_rule('NoOp', Label, Id, Min, Max, T) :- !, T = may(_).
legacy_submit_rule(Fun, Label, Id, Min, Max, T) :- T = impossible(unsupported(Fun)).
-
%% max_with_block:
%%
%% - The minimum is never used.
@@ -252,6 +251,10 @@
%%
:- public max_with_block/4.
%%
+max_with_block(Min, Max, Label, label(Label, S)) :-
+ number(Min), number(Max), atom(Label),
+ !,
+ max_with_block(Label, Min, Max, S).
max_with_block(Label, Min, Max, reject(Who)) :-
check_label_range_permission(Label, Min, ok(Who)),
!