How to make a category MaxWithBlocking and displayed on Gerrit UI if it matches a branch with prolog

526 views
Skip to first unread message

Indra Gunawan

unread,
Aug 4, 2014, 4:17:16 PM8/4/14
to repo-d...@googlegroups.com
To all,

I hope I can get assistance on creating a rule.
I have a new category called "Sanity" such that I do not want it to show on Gerrit UI unless the change branch matches certain 'refs/head/<branch-name>'.
Hence, I defined the category as non-blocking in the project.config of the project not in "All-Projects":

[label "Sanity"]
        function = NoBlock
        value = -1 Fails
        value =  0 No score
        value = +1 Passed

And I added the rules.pl for that project as such:

sanity('refs/heads/develop').

submit_rule(S) :-
  gerrit:default_submit(In),
  In =.. [submit | Ls],
  make_sanity_blocking(Ls,R),
  S =.. [submit | R].


make_sanity_blocking(S1, S2) :-
  gerrit:change_branch(Branch),
  sanity(Branch),
  !,
  rule(-1, 1, 'Sanity', label('Sanity', ST)).

rule(Min, Max, Label, label(Label,S)) :-
  gerrit:max_with_block(Label, Min, Max, S).

It does not work.  It caused that project to be submittable regardless of the branch without any category shown.
I want to make the "Sanity" category to be blocking only for 'refs/for/develop' and show 'Sanity' category for that branch and do not show it on other branches (i.e. non-blocking).

Any clue?

Thank you.
-Indra

Saša Živkov

unread,
Aug 5, 2014, 4:11:23 AM8/5/14
to Indra Gunawan, repo-d...@googlegroups.com
There are several issues with your approach... and one very simple solution
if you are running Gerrit 2.8 or newer...


On Mon, Aug 4, 2014 at 10:17 PM, Indra Gunawan <ind...@gmail.com> wrote:
To all,

I hope I can get assistance on creating a rule.
I have a new category called "Sanity" such that I do not want it to show on Gerrit UI unless the change branch matches certain 'refs/head/<branch-name>'.
Hence, I defined the category as non-blocking in the project.config of the project not in "All-Projects":

[label "Sanity"]
        function = NoBlock
 
The NoBlock means that this label is purely informational and values are not considered when determining whether a change is submittable.
If you wanted that Sanity-1 prevents submit and the Sanity+1 is mandatory (besides other labels) for the submitability then
use the MaxWithBlock function.

        value = -1 Fails
        value =  0 No score
        value = +1 Passed

And I added the rules.pl for that project as such:

If your Gerrit is at least 2.8 then you dont' need any prolog rules for what you are trying to do.
Just add the following line under the [label "Sanity"] section:

  branch = refs/heads/develop

and it will apply only to this branch.

Only if you are running Gerrit older than 2.8 read further :-)


sanity('refs/heads/develop').

submit_rule(S) :-
  gerrit:default_submit(In),
  In =.. [submit | Ls],
  make_sanity_blocking(Ls,R),
  S =.. [submit | R].

Since you added the new label via the configuration in All-Projects you only need to care
to remove this label when the branch is not refs/heads/develop.
Therefere, I would rename the make_sanity_blocking to remove_sanity_label and make it remove
the Sanity label if the change_branch is not refs/heads/develop.


make_sanity_blocking(S1, S2) :- 
  gerrit:change_branch(Branch),
  sanity(Branch),
  !,
  rule(-1, 1, 'Sanity', label('Sanity', ST)).
 
Both S1 and S2 are ignored in this rule. No wonder that all changes are then made submittable.


rule(Min, Max, Label, label(Label,S)) :-
  gerrit:max_with_block(Label, Min, Max, S).

It does not work.  It caused that project to be submittable regardless of the branch without any category shown.
I want to make the "Sanity" category to be blocking only for 'refs/for/develop' and show 'Sanity' category for that branch and do not show it on other branches (i.e. non-blocking).

Any clue?

Thank you.
-Indra

--
--
To unsubscribe, email repo-discuss...@googlegroups.com
More info at http://groups.google.com/group/repo-discuss?hl=en

---
You received this message because you are subscribed to the Google Groups "Repo and Gerrit Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to repo-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Indra Gunawan

unread,
Aug 6, 2014, 2:27:00 AM8/6/14
to Saša Živkov, repo-d...@googlegroups.com
Thank you for the suggestion.  Yes I am running gerrit version 2.8.3.  branch key/value pair here : http://review.cyanogenmod.org/Documentation/config-labels.html#label_branch  works perfectly.

Do you know if the abbreviation key/value pair is honored at all since the table does not show "ST" that I specifically set to in the children project's project.config (I make it blocking for /refs/heads/develop):  Not all projects require sanity as category for now.

[label "Sanity"]
        abbreviation = ST
        branch = refs/heads/develop
        function = MaxWithBlock

        value = -1 Fails
        value =  0 No score
        value = +1 Passed

It only displays it as "S".

Can you show me the way to remove_sanity_label and make it remove
the Sanity label if the change_branch is not refs/heads/develop?  I presume it must be a submit_filter?

Before you suggested the simple solution of "branch" key/value pair I adopted one of the example where in All-Projects' rules.pl I have:

sanity('pi/da_user_web_cache','refs/heads/develop').

submit_filter(In, Out) :-
  gerrit:change_branch(Branch),
  gerrit:change_project(Project),
  sanity(Project, Branch),
  !,
  In =.. [submit | I],
  gerrit:max_with_block(-1, 1, 'Sanity', ST),
  Out =.. [submit, ST | I].

submit_filter(In, Out) :- In = Out.

It sorted of working but I don't see the "Need for Sanity" for refs/heads/develop.  I think because I made it NoBlock to begin with so non-matching branch won't get the sanity label.

Thank you.  I really appreciate your insight! 

-Indra

Edwin Kempin

unread,
Aug 6, 2014, 3:09:45 AM8/6/14
to Indra Gunawan, Saša Živkov, repo-d...@googlegroups.com
2014-08-06 0:48 GMT+02:00 Indra Gunawan <ind...@gmail.com>:
Thank you for the suggestion.  Yes I am running gerrit version 2.8.3.  branch key/value pair here : http://review.cyanogenmod.org/Documentation/config-labels.html#label_branch  works perfectly.

Do you know if the abbreviation key/value pair is honored at all since the table does not show "ST" that I specifically set to in the children project's project.config
The label abbreviations do not work and this is why the support for abbreviations was removed in current master:
  https://gerrit-review.googlesource.com/57822

Saša Živkov

unread,
Aug 6, 2014, 4:56:33 AM8/6/14
to Indra Gunawan, repo-d...@googlegroups.com
On Wed, Aug 6, 2014 at 12:48 AM, Indra Gunawan <ind...@gmail.com> wrote:
Thank you for the suggestion.  Yes I am running gerrit version 2.8.3.  branch key/value pair here : http://review.cyanogenmod.org/Documentation/config-labels.html#label_branch  works perfectly.

Do you know if the abbreviation key/value pair is honored at all since the table does not show "ST" that I specifically set to in the children project's project.config (I make it blocking for /refs/heads/develop):  Not all projects require sanity as category for now.

[label "Sanity"]
        abbreviation = ST
        branch = refs/heads/develop
        function = MaxWithBlock

        value = -1 Fails
        value =  0 No score
        value = +1 Passed

It only displays it as "S".

Can you show me the way to remove_sanity_label and make it remove
the Sanity label if the change_branch is not refs/heads/develop?  I presume it must be a submit_filter?
 
Before doing that with a prolog submit_filter please check if the existing label configuration
mechanism already provides what you need [1]. Note that it is possible to override and/or
remove an inherited label in a child project. You could also have a common parent project
for all those projects who do need the sanity check and introduce the "Sanity" label in
that project only.

To remove an existing label do something like:

%% do nothing if the project/branch should have the Sanity label
submit_filter(In, In) :-
  gerrit:change_branch(B),
  gerrit:change_project(P),
  sanity(P, B),
  !.

%% otherwise remove the Sanity label
submit_filter(In, Out) :-
  In =.. [submit | Ls],
  remove_sanity_label(Ls, R),
  Out =.. [submit | R].

Implementing the "remove_sanity_label" is as simple as removing an element from a list.
Look at [2] for an example.



 

Before you suggested the simple solution of "branch" key/value pair I adopted one of the example where in All-Projects' rules.pl I have:

sanity('pi/da_user_web_cache','refs/heads/develop').

submit_filter(In, Out) :-
  gerrit:change_branch(Branch),
  gerrit:change_project(Project),
  sanity(Project, Branch),
  !,
  In =.. [submit | I],
  gerrit:max_with_block(-1, 1, 'Sanity', ST),
  Out =.. [submit, ST | I].

submit_filter(In, Out) :- In = Out.
This could be written simpler:
  submit_filter(In, In). 

Indra Gunawan

unread,
Aug 29, 2014, 2:12:24 PM8/29/14
to Saša Živkov, repo-d...@googlegroups.com
I added the new category "Sanity" only in the project.config of the child project and did not define it in "All-Projects" the parent.
However, as anonymous user the gerrit review does not about the new category:

gerrit review {COMMIT | CHANGE,PATCHSET} ... [--] [--abandon] [--delete] [--help (-h)] [--label (-l) LABEL=VALUE] [--message (-m) MESSAGE] [--project (-p) PROJECT] [--publish] [--restore] [--submit (-s)] [--code-review N] [--verified N] [--throttle-mode N]

 {COMMIT | CHANGE,PATCHSET} : list of commits or patch sets to review
 --                         : end of options
 --abandon                  : abandon the specified change(s)
 --delete                   : delete the specified draft patch set(s)
 --help (-h)                : display this help text
 --label (-l) LABEL=VALUE   : custom label(s) to assign
 --message (-m) MESSAGE     : cover message to publish on change(s)
 --project (-p) PROJECT     : project containing the specified patch set(s)
 --publish                  : publish the specified draft patch set(s)
 --restore                  : restore the specified abandoned change(s)
 --submit (-s)              : submit the specified patch set(s)
 --code-review N            : score for Code-Review
                              -2 Do not submit
                              -1 I would prefer that you didn't submit this
                               0 No score
                              +1 Looks good to me, but someone else must approve
                              +2 Looks good to me, approved
 --verified N               : score for Verified
                              -1 Fails
                               0 No score
                              +1 Verified
 --throttle-mode N          : score for Throttle-Mode
                              -1 Throttle Rejected
                               0 No score
                              +1 Throttle Approved

Should it be defined in "All-Projects"?  I do not want suddenly all "develop" branch of the children project needs this Sanity category.  I want to test and isolate it on a test gerrit/git repository.


Here is the child project's project.config:

INGUNAWA-M-50HZ:da_user_web_cache-cfg ingunawa$ more project.config
[access]
        inheritFrom = All-Projects
[project]
        description = da_user_web_cache POC project
[access "refs/for/refs/*"]
        push = group Registered Users
        pushMerge = group Registered Users
[access "refs/heads/*"]
        read = group Registered Users
        label-Verified = -1..+1 group Non-Interactive Users
        label-Verified = -1..+1 group Registered Users
        submit = group Registered Users
        label-Code-Review = -2..+2 group Non-Interactive Users
        label-Code-Review = -2..+2 group Registered Users
        label-Sanity = -1..+1 group Non-Interactive Users
        abandon = group Registered Users
        push = +force group Administrators
[access "refs/*"]
        read = group Non-Interactive Users
        read = group Registered Users
        owner = group PI DA User Web Cache Admins
[receive]
[access "refs/tags/*"]
        read = group PI DA User Web Cache Admins
        push = +force group Non-Interactive Users
        push = +force group PI DA User Web Cache Admins
        pushMerge = group Non-Interactive Users
        pushMerge = group PI DA User Web Cache Admins
        exclusiveGroupPermissions = push
[access "refs/heads/ref/*"]
        exclusiveGroupPermissions = push
        push = +force group Administrators

[label "Sanity"]
        abbreviation = ST
        branch = refs/heads/develop
        function = MaxWithBlock
        value = -1 Fails
        value =  0 No score
        value = +1 Passed


Any clues?

Thank you.
-Indra

Zu, Bruce

unread,
Aug 31, 2014, 10:44:09 PM8/31/14
to Indra Gunawan, Saša Živkov, repo-d...@googlegroups.com

> Can you show me the way to remove_sanity_label and make it remove the Sanity label if the change_branch is not refs/heads/develop? 

 

The easy way is in one of my  abandoned change. but no one buy it.

 

/Bruce

Saša Živkov

unread,
Sep 4, 2014, 10:26:22 AM9/4/14
to Indra Gunawan, repo-d...@googlegroups.com
You could use the --label option to vote in your Sanity label:
ssh ... gerrit review ... --label Sanity=+1 ...

this should work even if your custom label doesn't appear in the help text.
The help text will only include those labels defined in All-Projects.
See [1] for more details:

Reply all
Reply to author
Forward
0 new messages