diff options
Diffstat (limited to 'Documentation/prolog-cookbook.txt')
-rw-r--r-- | Documentation/prolog-cookbook.txt | 68 |
1 files changed, 23 insertions, 45 deletions
diff --git a/Documentation/prolog-cookbook.txt b/Documentation/prolog-cookbook.txt index ad4530e842..19ed98aa6f 100644 --- a/Documentation/prolog-cookbook.txt +++ b/Documentation/prolog-cookbook.txt @@ -517,8 +517,9 @@ submit_rule(submit(Author)) :- Author = label('Author-is-John-Doe', need(_)). submit_rule(submit(Author)) :- - gerrit:commit_author(A, _, 'john.doe@example.com'), - Author = label('Author-is-John-Doe', ok(A)). + gerrit:commit_author(_, _, 'john.doe@example.com'), + gerrit:uploader(U), + Author = label('Author-is-John-Doe', ok(U)). ---- or by user id (assuming it is `1000000`): @@ -544,9 +545,9 @@ submit_rule(submit(Author)) :- Author = label('Author-is-John-Doe', need(_)). submit_rule(submit(Author)) :- - A = user(1000000), - gerrit:commit_author(A, 'John Doe', 'john.doe@example.com'), - Author = label('Author-is-John-Doe', ok(A)). + gerrit:commit_author(_, 'John Doe', 'john.doe@example.com'), + gerrit:uploader(U), + Author = label('Author-is-John-Doe', ok(U)). ---- === Example 7: Make change submittable if commit message starts with "Fix " @@ -572,8 +573,8 @@ submit_rule(submit(Fix)) :- submit_rule(submit(Fix)) :- gerrit:commit_message(M), name(M, L), starts_with(L, "Fix "), - gerrit:commit_author(A), - Fix = label('Commit-Message-starts-with-Fix', ok(A)). + gerrit:uploader(U), + Fix = label('Commit-Message-starts-with-Fix', ok(U)). starts_with(L, []). starts_with([H|T1], [H|T2]) :- starts_with(T1, T2). @@ -598,8 +599,8 @@ submit_rule(submit(Fix)) :- submit_rule(submit(Fix)) :- gerrit:commit_message_matches('^Fix '), - gerrit:commit_author(A), - Fix = label('Commit-Message-starts-with-Fix', ok(A)). + gerrit:uploader(U), + Fix = label('Commit-Message-starts-with-Fix', ok(U)). ---- The previous example could also be written so that it first checks if the commit @@ -611,8 +612,8 @@ further backtracking by using the cut `!` operator: ---- submit_rule(submit(Fix)) :- gerrit:commit_message_matches('^Fix '), - gerrit:commit_author(A), - Fix = label('Commit-Message-starts-with-Fix', ok(A)), + gerrit:uploader(U), + Fix = label('Commit-Message-starts-with-Fix', ok(U)), !. % Message does not start with 'Fix ' so Fix is needed to submit @@ -795,7 +796,7 @@ remove_verified_category([H|T], [H|R]) :- remove_verified_category(T, R). === Example 10: Combine examples 8 and 9 In this example we want to both remove the verified and have the four eyes -principle. This means we want a combination of examples 7 and 8. +principle. This means we want a combination of examples 8 and 9. `rules.pl` [source,prolog] @@ -979,30 +980,7 @@ add_apprentice_master(S1, S2) :- add_apprentice_master(S, S). ---- -=== Example 15: Only allow Author to submit change -This example adds a new needed category `Only-Author-Can-Submit` for any user -that is not the author of the patch. This effectively blocks all users except -the author from submitting the change. This could result in an impossible -situation if the author does not have permissions for submitting the change. - -`rules.pl` -[source,prolog] ----- -submit_rule(S) :- - gerrit:default_submit(In), - In =.. [submit | Ls], - only_allow_author_to_submit(Ls, R), - S =.. [submit | R]. - -only_allow_author_to_submit(S, S) :- - gerrit:commit_author(Id), - gerrit:current_user(Id), - !. - -only_allow_author_to_submit(S1, [label('Only-Author-Can-Submit', need(_)) | S1]). ----- - -=== Example 16: Make change submittable if all comments have been resolved +=== Example 15: Make change submittable if all comments have been resolved In this example we will use the `unresolved_comments_count` fact about a change. Our goal is to block the submission of any change with some unresolved comments. Basically, it can be achieved by the following rules: @@ -1013,8 +991,8 @@ unresolved comments. Basically, it can be achieved by the following rules: submit_rule(submit(R)) :- gerrit:unresolved_comments_count(0), !, - gerrit:commit_author(A), - R = label('All-Comments-Resolved', ok(A)). + gerrit:uploader(U), + R = label('All-Comments-Resolved', ok(U)). submit_rule(submit(R)) :- gerrit:unresolved_comments_count(U), @@ -1033,8 +1011,8 @@ submit_rule(submit(CR, V, R)) :- base(CR, V), gerrit:unresolved_comments_count(0), !, - gerrit:commit_author(A), - R = label('All-Comments-Resolved', ok(A)). + gerrit:uploader(U), + R = label('All-Comments-Resolved', ok(U)). submit_rule(submit(CR, V, R)) :- base(CR, V), @@ -1052,7 +1030,7 @@ It's only used to show `'Needs All-Comments-Resolved'` in the UI to clearly indicate to the user that all the comments have to be resolved for the change to become submittable. -=== Example 17: Make change submittable if it is a pure revert +=== Example 16: Make change submittable if it is a pure revert In this example we will use the `pure_revert` fact about a change. Our goal is to block the submission of any change that is not a pure revert. Basically, it can be achieved by the following rules: @@ -1063,8 +1041,8 @@ pure revert. Basically, it can be achieved by the following rules: submit_rule(submit(R)) :- gerrit:pure_revert(1), !, - gerrit:commit_author(A), - R = label('Is-Pure-Revert', ok(A)). + gerrit:uploader(U), + R = label('Is-Pure-Revert', ok(U)). submit_rule(submit(R)) :- gerrit:pure_revert(U), @@ -1083,8 +1061,8 @@ submit_rule(submit(CR, V, R)) :- base(CR, V), gerrit:pure_revert(1), !, - gerrit:commit_author(A), - R = label('Is-Pure-Revert', ok(A)). + gerrit:uploader(U), + R = label('Is-Pure-Revert', ok(U)). submit_rule(submit(CR, V, R)) :- base(CR, V), |