Gerrit accumulative 2 +1s to allow submit

306 views
Skip to first unread message

Brandon Lee

unread,
May 5, 2015, 4:47:25 AM5/5/15
to repo-d...@googlegroups.com
Hi

I was trying to setup a gerrit project to allow contributors to perform +1 and reviewers +2.  I noticed that even thou i had 2 contributors who each posted +1, the "submit" did not appear.

After searching through the list and web, i had setup my rules.pl in refs/meta/config with the below:

sum_list([], 0).
sum_list([H | Rest], Sum) :- sum_list(Rest,Tmp), Sum is H + Tmp.

first_list([], _).
first_list([F], F).
first_list([F | Rest], F).

score(Category, Score, User) :-
  gerrit:commit_label(label(Category, Score), User).

add_category_min_score(In, Category, Min,  P) :-
  findall(Score, score(Category, Score, User), Scores),
  findall(User, score(Category, Score, User), Users),
  sum_list(Scores, Sum),
  Sum >= Min, !,
  first_list(Users, FirstUser),
  P = [label(Category, ok(FirstUser)) | 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].

Result:
$ cat rules.pl | ssh -p 29418 localhost gerrit test-submit rule -s <Change-Id>
[
  {
    "status": "OK",
    "ok": {
      "Code-Review": {
        "_account_id": XX,
        "name": "<First, Last Name>",
        "email": "<us...@domain.com>",
        "username": "<userid>"
      },
      "Verified": {
        "_account_id": XX,
        "name": "<First, Last Name>",
        "email": "<us...@domain.com>",
        "username": "<userid>"
      }
    }
  }
]


However, when i get to my Gerrit WebUI.  The change shows "+1" under CR column.  In the PatchSet page, there is no submit button even though it showed 2 contributors performed "+1" each and Verified is "+1".

Does Gerrit integrate rules.pl in the webUI?  Am i missing something to make 2 "+1"s submittable?

Regards
Brandon Lee



Saša Živkov

unread,
May 5, 2015, 11:19:43 AM5/5/15
to Brandon Lee, repo-d...@googlegroups.com
Have you pushed your rules.pl change(s) to the refs/meta/config branch?
What is the result of the test-submit rule comment if tested against the server side rules.pl:
$ ssh -p 29418 localhost gerrit test-submit rule <Change-Id>

 
[
  {
    "status": "OK",
    "ok": {
      "Code-Review": {
        "_account_id": XX,
        "name": "<First, Last Name>",
        "email": "<us...@domain.com>",
        "username": "<userid>"
      },
      "Verified": {
        "_account_id": XX,
        "name": "<First, Last Name>",
        "email": "<us...@domain.com>",
        "username": "<userid>"
      }
    }
  }
]


However, when i get to my Gerrit WebUI.  The change shows "+1" under CR column.  In the PatchSet page, there is no submit button even though it showed 2 contributors performed "+1" each and Verified is "+1".

Does Gerrit integrate rules.pl in the webUI?
Yes 

Am i missing something to make 2 "+1"s submittable?
Let's first verify that you pushed your rules.pl changes. 
 

Regards
Brandon Lee



--
--
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.

Brandon Lee

unread,
May 5, 2015, 10:17:23 PM5/5/15
to repo-d...@googlegroups.com, bra...@xcodes.net

Hi Zivkov

Here is the full run to to checkout the refs/meta/config and run of rules.pl by stdin and via gerrit test-submit output:

$ mkdir config
$ cd config
$ git init
Initialized empty Git repository in /home/user1/config/.git/

$ git remote add origin ssh://user1@localhost:29418/All-Projects

$ git fetch origin refs/meta/config:refs/remotes/origin/meta/config
remote: Counting objects: 86, done
remote: Finding sources: 100% (86/86)
Unpacking objects: 100% (86/86), done.
remote: Total 86 (delta 20), reused 55 (delta 20)
From ssh://localhost:29418/All-Projects
 * [new branch]      refs/meta/config -> origin/meta/config


$ git checkout meta/config
Branch meta/config set up to track remote branch meta/config from origin.
Switched to a new branch 'meta/config'


$ ls -l
total 12
-rw-r--r-- 1 user1 users  330 May  6 02:01 groups
-rw-r--r-- 1 user1 users 2298 May  6 02:01 project.config
-rw-r--r-- 1 user1 users  817 May  6 02:01 rules.pl


$ more rules.pl

sum_list([], 0).
sum_list([H | Rest], Sum) :- sum_list(Rest,Tmp), Sum is H + Tmp.

first_list([], _).
first_list([F], F).
first_list([F | Rest], F).

score(Category, Score, User) :-
  gerrit:commit_label(label(Category, Score), User).

add_category_min_score(In, Category, Min,  P) :-
  findall(Score, score(Category, Score, User), Scores),
  findall(User, score(Category, Score, User), Users),
  sum_list(Scores, Sum),
  Sum >= Min, !,
  first_list(Users, FirstUser),
  P = [label(Category, ok(FirstUser)) | 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].


$ cat rules.pl | ssh -p 29418 localhost gerrit test-submit rule -s I3db6270994e04fde3d14d578f11b0253eed9cc3a

[
  {
    "status": "OK",
    "ok": {
      "Code-Review": {
        "_account_id": 21,
        "name": "<Full Name>",

        "email": "<us...@domain.com>",
        "username": "<userid>"
      },
      "Verified": {
        "_account_id": 21,
        "name": "<Full Name>",

        "email": "<us...@domain.com>",
        "username": "<userid>"
      }
    }
  }
]


$ ssh -p 29418 localhost gerrit test-submit rule I3db6270994e04fde3d14d578f11b0253eed9cc3a  [
  {
    "status": "NOT_READY",
    "ok": {
      "Verified": {
        "_account_id": 21,
        "name": "<Full Name>",

        "email": "<us...@domain.com>",
        "username": "<userid>"
      }
    },
    "need": {
      "Code-Review": {}
    }
  }
]

Seems like something not quite right.

Regards
Brandon



 

Edwin Kempin

unread,
May 6, 2015, 2:14:12 AM5/6/15
to Brandon Lee, Repo and Gerrit Discussion
Have you done the push? I don't see any push in the steps that you have performed.
A rules.pl file only effects the project for which is is defined (not the child projects).
Are developing anything in the All-Projects project?
If you wanted to define this for all child projects, you need to define a submit filter as described in
  https://gerrit-review.googlesource.com/Documentation/prolog-cookbook.html#SubmitFilter

Did you commit and push the commit back to the refs/meta/config branch of the remote repository?

 

$ ssh -p 29418 localhost gerrit test-submit rule I3db6270994e04fde3d14d578f11b0253eed9cc3a  [
  {
    "status": "NOT_READY",
    "ok": {
      "Verified": {
        "_account_id": 21,
        "name": "<Full Name>",
        "email": "<us...@domain.com>",
        "username": "<userid>"
      }
    },
    "need": {
      "Code-Review": {}
    }
  }
]

Seems like something not quite right.

Regards
Brandon



 

--

Brandon Lee

unread,
May 6, 2015, 5:38:04 AM5/6/15
to Edwin Kempin, Repo and Gerrit Discussion

Thank Edwin.

I was working on All-Projects branch and thats why it didnt work.

Another question, if i have another rule to prevent self +2.  Do i need to combine those submit_rule functions together or will the commit be parsed through both submit_rules functions and prevent submit if one function fails?

Regards
Brandon

Edwin Kempin

unread,
May 6, 2015, 6:36:58 AM5/6/15
to Brandon Lee, Repo and Gerrit Discussion
2015-05-06 11:37 GMT+02:00 Brandon Lee <bra...@xcodes.net>:

Thank Edwin.

I was working on All-Projects branch and thats why it didnt work.

Another question, if i have another rule to prevent self +2.  Do i need to combine those submit_rule functions together or will the commit be parsed through both submit_rules functions and prevent submit if one function fails?

You need to combine them.

Philip Stefanov

unread,
Jun 18, 2017, 8:34:19 PM6/18/17
to Repo and Gerrit Discussion
This example is working fine the only problem i found is when i change the rule
add_category_min_score(NoCR, 'Code-Review',3, Labels),
And my change has CR+2 and V+1 submit button is not present but the change status is Change - Ready to Submit
However fast ssh test shows:
$ ssh gerrit.localhost gerrit test-submit rule I1c2af66ad0f04e871839367c3b83b67c132e4c79

[
  {
    "status": "NOT_READY",
    "ok": {
      "Verified": {
        "_account_id": 1000000,
        "name": "Administrator",
        "email": "",
        "username": "admin"
      }
    },
    "need": {
      "Code-Review": {}
    },
    "may": {
      "Lock": {}
    },
    "prolog_reduction_count": 604
  }
]

UI status should be
Needs Code-Review Label.
How can i fix that?

Saša Živkov

unread,
Jun 19, 2017, 4:11:56 AM6/19/17
to Philip Stefanov, Repo and Gerrit Discussion
Please create a new discussion thread instead of reviving discussion threads from 2015.

--
--
To unsubscribe, email repo-discuss+unsubscribe@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+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages