diff options
author | Johan Björk <jbjoerk@gmail.com> | 2012-10-24 12:06:33 -0400 |
---|---|---|
committer | Johan Björk <jbjoerk@gmail.com> | 2012-10-24 12:15:16 -0400 |
commit | ef02854218d06b4c9f49c02774a1ef56cd338614 (patch) | |
tree | f2ed6de690847447e17b2ceeefd2b3df336602bb | |
parent | 547bb9a661d58d40f9a7bfc8e6a8c00199a5e59f (diff) |
Documentation: Add submit rule example on how to implement 1+1=2
Adds an example that demonstrates how to write a submit-rule that
implements accumulative voting scores.
Bug: Issue 757
Change-Id: Ia36e29495b5cc77ea2254519f5485eb9f29154eb
-rw-r--r-- | Documentation/prolog-cookbook.txt | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Documentation/prolog-cookbook.txt b/Documentation/prolog-cookbook.txt index 99773c6743..105929a40e 100644 --- a/Documentation/prolog-cookbook.txt +++ b/Documentation/prolog-cookbook.txt @@ -638,6 +638,42 @@ we have to do that in the `rules.pl` of the `All-Projects` project. remove_verified_category([H|T], [H|R]) :- remove_verified_category(T, R). ==== +Example 12: 1+1=2 Code-Review +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +In this example we introduce accumulative voting to determine if a change is +submittable or not. We modify the standard Code-Review to be accumulative, and make the +change submittable if the total score is 2 or higher. + +The code in this example is very similar to Example 8, with the addition of findall/3 +and gerrit:remove_label. +The findall/3 embedded predicate is used to form a list of all objects that satisfy a +specified Goal. In this example it is used to get a list of all the 'Code-Review' scores. +gerrit:remove_label is a built-in helper that is implemented similarly to the +'remove_verified_category' as seen in the previous example. + +.rules.pl +[caption=""] +==== + sum_list([], 0). + sum_list([H | Rest], Sum) :- sum_list(Rest,Tmp), Sum is H + Tmp. + + add_category_min_score(In, Category, Min, P) :- + findall(X, gerrit:commit_label(label(Category,X),R),Z), + sum_list(Z, Sum), + Sum >= Min, !, + P = [label(Category,ok(R)) | In]. + + add_category_min_score(In, Category,Min,P) :- + P = [label(Category,need(Min)) | In]. + + submit_rule(S) :- + gerrit:default_submit(X), + X =.. [submit | Ls], + gerrit:remove_label(Ls,label('Code-Review',_),NoCR), + add_category_min_score(NoCR,'Code-Review', 2, Labels), + S =.. [submit | Labels]. +==== + GERRIT ------ Part of link:index.html[Gerrit Code Review] |