Merge 'stable-2.5'
* stable-2.5: Documentation: Add prolog submit-rule example Submit by Author Documentation: Add prolog submit-rule example 'Master and Apprentice'. Change-Id: Ie1ccb949d4bea7e34b802ccff08cb1a61bd9dab8 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
commit
960cedb8e3
@ -684,6 +684,67 @@ 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).
|
||||
====
|
||||
|
||||
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]
|
||||
|
Loading…
Reference in New Issue
Block a user