From 87927a95b8a0f5f0c54a21e41915b5ad44d9ee19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bj=C3=B6rk?= Date: Thu, 25 Oct 2012 15:00:36 -0400 Subject: [PATCH 1/2] Documentation: Add prolog submit-rule example 'Master and Apprentice'. Bug: Issue 703 Change-Id: I3e0d64457adefd78a4bdcb1ac9c779e41da9f269 --- Documentation/prolog-cookbook.txt | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Documentation/prolog-cookbook.txt b/Documentation/prolog-cookbook.txt index 08626bae2f..c4a0589f0e 100644 --- a/Documentation/prolog-cookbook.txt +++ b/Documentation/prolog-cookbook.txt @@ -684,6 +684,43 @@ gerrit:remove_label is a built-in helper that is implemented similarly to the S =.. [submit | Labels]. ==== +Example 13: Master and apprentice +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The master and apprentice example allow you to specify a user (the `master`) +that must approve all changes done by another user (the `apprentice`). + +The code first checks if the commit author is in the apprentice database. +If the commit is done by an apprentice, it will check if there is a +2 +review by the associated `master`. + +.rules.pl +[caption=""] +==== + % master_apprentice(Master, Apprentice). + % Extend this with appropriate user-id's for your master/apprentice setup. + master_apprentice(user(1000064), user(1000000)). + + submit_rule(S) :- + gerrit:default_submit(In), + In =.. [submit | Ls], + add_apprentice_master(Ls, R), + S =.. [submit | R]. + + check_master_approval(S1, S2, Master) :- + gerrit:commit_label(label('Code-Review', 2), R), + R = Master, !, + S2 = [label('Master-Approval', ok(R)) | S1]. + check_master_approval(S1, [label('Master-Approval', need(_)) | S1], _). + + add_apprentice_master(S1, S2) :- + gerrit:commit_author(Id), + master_apprentice(Master, Id), + !, + check_master_approval(S1, S2, Master). + + add_apprentice_master(S, S). +==== + GERRIT ------ Part of link:index.html[Gerrit Code Review] From 0f13254156adf367daad830e4248fb15c644fe78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bj=C3=B6rk?= Date: Fri, 26 Oct 2012 10:16:07 -0400 Subject: [PATCH 2/2] Documentation: Add prolog submit-rule example Submit by Author Issue 1631 has been filed to track the need of a way to query if a certain user has Submit permissions. Bug: Issue 891 Change-Id: I6f78343012fb0bbcdc7ed90fde1b4189dfcd28c7 --- Documentation/prolog-cookbook.txt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Documentation/prolog-cookbook.txt b/Documentation/prolog-cookbook.txt index c4a0589f0e..e660067a87 100644 --- a/Documentation/prolog-cookbook.txt +++ b/Documentation/prolog-cookbook.txt @@ -721,6 +721,30 @@ review by the associated `master`. add_apprentice_master(S, S). ==== +Example 14: Only allow Author to submit change +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +This example adds a new needed category `Patchset-Author` 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 +[caption=""] +==== + 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('Patchset-Author', need(_)) | S1]). +==== + GERRIT ------ Part of link:index.html[Gerrit Code Review]