Wikimedia Developer Support

Writing a bot that gives CR+2 on gerrit


#1

There are some bots that apply changes to repos in gerrit and afterwards git a CR+2 to their changes (e.g. ‘libraryupgrader’, ‘translatewiki’, …).

I’ve found the following implementation: https://github.com/wikimedia/labs-libraryupgrader/blob/485fae291a6e5d443218115a043e81b80ff3d26b/container/thing.py#L78-L81

But when I try to run

git push origin refs/for/REL1_31%topic=Some_topic_branch,l=Code-Review+2

or

git push ssh://myuser@gerrit.wikimedia.org:29418/mediawiki/extensions/MyRepo refs/for/REL1_31%topic=Some_topic_branch,l=Code-Review+2

I receive

remote: Processing changes: refs: 1, done            
To ssh://myuser@gerrit.wikimedia.org:29418/mediawiki/extensions/MyRepo
 ! [remote rejected] HEAD -> refs/for/REL1_31%topic=Some_topic_branch,l=Code-Review+2 (no new changes)

I would have expected to run into a permission issue because my user may not be allowed to push, but this error message suggests something else.

Can anyone give me an advice please?


#2

Normally you get that error when you have already pushed the changeset earlier and the version you are trying to push now is identical to the version on Gerrit.


#3

Thanks! Yes, this is true. I thought it’s a two step process:

  1. execute git review in the repo to create the review in gerrit

  2. execute git push origin refs/for/REL1_31%topic=Some_topic_branch,l=Code-Review+2 in the repo to vote +2 on Code Review

Do I need to reset my changes (git reset --hard origin/REL1_31) or switch to the base branch (git checkout REL1_31) before step 2?


#4

To me it seems you have already pushed the change with git review and then push again with the second command. The second command is probably enough alone, or if you do it in two steps, the vote command needs to be done differently (compare with L10n-bot code).


#5

Indeed, Gerrit does everything with normal git commands (it pretends to be a remote repository you can push commits to), git review is just a human-friendly wrapper around those commands. (And a third-party one at that, it’s maintained by the Openstack community, not the Gerrit developers.) So it would do the same refs/for/... push, except I don’t think git review supports setting review flags during the push.

Gerrit has pretty good documentation (git-review not so much…), see Uploading Changes # git push for details.


#6

Thanks for all your input! I believe I will do something like this

  1. execute git review in the repo to create the review in gerrit

  2. extract commit-id (e.g. 57a937f2)

  3. execute ssh myuser@gerrit.wikimedia.org -p 29418 gerrit review 57a937f2 --code-review 2 [1]

This is basically what the L10n-bot script does that @Nikerabbit pointed to. Did not test it yet, but it sounds promising. Thanks again!

[1] https://review.openstack.org/Documentation/cmd-review.html


#7

Just tested it. Works. Thanks to all.