Add reviewers via post commit

Can reviewers be added to Gerrit via post commit? View this post:

component: make foo more bar Foo was not bar enough, this change adds more bar to make foo fit better in baz. Change-Id: I4724e283214e0bfbb85a8e3d8db4971618e2609a Cc: alice@example.com Cc: bob@example.net 

Here alice@example.com and bob@example.net should be added as reviewers when clicking on gerrit.

I know the industry-specific qualifier qualifier to add reviewers, but would like to have something more automatic when I commit. The changes are independent, although it would be nice if I could group them in a topic thread, because they are related.

+6
source share
7 answers

There are several other ways to do this.

  • Just add these lines to your .git / config

    [remote "review"]

    pushurl = ssh: // user @gerrit: 29418 / project

    push = HEAD: refs / for / master

    receivepack = git receive-pack --reviewer reviewer1 --reviewer reviewer2

    Now that you want to click review, just do: git click review and "reviewer1" and "reviewer2" will be added to your patch set.

  • I think you can also write some script / hook to automate this. After running the grep command, change the commit identifier and use the command below gerrit:

    ssh -p gerrit set-reviewers [-project (PROJECT) | -P (PROJECT)] [--add (REVIEWER) ... | -a (REVIEW) ...] [-] {COMMIT | CHANGE-ID}

    Example: ssh -p 29418 gerrit.example.com gerrit set-reviewers -a anuj@example.com Iac6b2ac2

Hope this helps you :)

+7
source

It is not possible to set per-commit reviewers, they are applied for every click (see gerrit git -receive-pack manual ), Instead of doing git push origin HEAD or git review (assuming origin is the remote gerrit and HEAD branch you want to click) , you can run the following to add two reviewers for all new commits:

 git push origin HEAD:refs/for/master% r=alice@example.com , r=bob@example.com 

This applies to all commits you don't need. Due to the above limitations, let me modify the workflow to make changes first and then install some reviewers.


Since Gerrit distinguishes between Cc (just send a notification by mail) and reviewers (send mail, but also mark the user as a reviewer), I will modify the commit message as follows:

 component: make foo more bar Foo was not bar enough, this change adds more bar to make foo fit better in baz. R=alice@example.com R=bob@example.net Change-Id: I4724e283214e0bfbb85a8e3d8db4971618e2609a 

Given the number of commits, you can follow these steps to add individual browsers for each commit:

  • Gather a list of commit identifiers (or Change-Id s). An example that assumes the main branch is the base: git rev-list --reverse origin/master..
  • For each commit identifier, scan R=... (reviewers) in the commit message. The commit message for this commit can be found using git show --no-patch --format=%b COMMIT_ID
  • If reviewers exist for the commit message, add them using the command ssh -p 29418 user@host 'gerrit set-reviewers -a bob@example.net COMMIT_ID' (instead of COMMIT_ID , you can also use Change-Id , which is I4724e283214e0bfbb85a8e3d8db4971618e2609a for example )

To follow the steps above (along with automatically detecting user, host and port settings), I wrote a Bash script: https://git.lekensteyn.nl/scripts/tree/git/gerrit-add-reviewers

It is recommended that you use the .gitreview file in your repo with the remote pointing to the Gerrit instance. Then run ~/scripts/gerrit-add-reviews origin/master.. from within this git repository to scan commit messages and add reviewers.

+5
source

I put together a script where you can pass the email addresses of the reviewers you want to add, and it takes care of the rest. You can even fuzzy find in existing committers (email address and name), so you don’t have to enter a lot.

https://gist.github.com/andersonvom/924fdc5f92aefa5eca9c

Just call it using:

 $ greview [<rev1> [<rev2> [...]]] 
+2
source

Combine the gerrit event streams and set-reviewers, you can do this.

In fact, you first need to get the status of CL (create, update and ...), and then perform the appropriate action, for example, add reviewers, even send CL.

  • get gerrit events from gerrit stream-events ".

  • parse a JSON format event on each line. In the JSON event, we can get the project, branch, Change-Id, CL number, Commit object (not full commit) and a lot of information.

if you really need a message with the whole message, gerrit query "is useful.

filter out the “created set of patches”, the number of the set patch is 1 (if you like only this for the new patch), analyze the fixation topic and get reviewers as you predetermined.

  1. use " gerrit set-reviewers " to add a reviewer.

as my practice, use python, all this is easy.

Its stream looks like tiny Jenkins.

0
source

Send feedback for changes on the main branch to charlie@example.com :

 git push ssh://review.example.com:29418/project HEAD:refs/for/master% r=charlie@example.com 

Send feedback, but tag them with the theme name "bug42":

 git push ssh://review.example.com:29418/project HEAD:refs/for/master% r=charlie@example.com ,topic=bug42 

Also CC are two other sides:

 git push ssh://review.example.com:29418/project HEAD:refs/for/master% r=charlie@example.com , cc=alice@example.com , cc=bob@example.com 

Configure the push macro to perform the last action:

 git config remote.charlie.url ssh://review.example.com:29418/project git config remote.charlie.push HEAD:refs/for/master% r=charlie@example.com , cc=alice@example.com , cc=bob@example.com 

after that .git / config contains the following:

 [remote "charlie"] url = ssh://review.example.com:29418/project push = HEAD:refs/for/master% r=charlie@example.com , cc=alice@example.com , cc=bob@example.com 

and now submitting a new change for review to charlie, CCing and alice and bob is much simpler:

 git push charlie 
0
source

Below solutions work

ssh -p gerrit set-reviewers [-project (PROJECT) | -p (PROJECT)] [--add (REVIEWER) ... | -a (REVIEW) ...] [-] {COMMIT | CHANGE-ID}

Example: ssh -p 29418 gerrit.example.com gerrit set-reviewers -a anuj@example.com Iac6b2ac2

0
source

A very good git-review tool to simplify your life with Gerrit. Among other advantages of syntactic sugar, it allows you to add reviewers through the command line, for example:

 git review --reviewers someone@someone.com someoneelse@someone.com 

And of course, you can create git aliases from it to simplify:

 #git review --reviewers someone@someone.com someoneelse@someone.com git publish 

It does not directly answer your question "how to add reviewers from a posting commit," but it can be used, for example, to create custom pre-commits and retrieve emails in the first place and then translate them to gerrit second

0
source

Source: https://habr.com/ru/post/971772/


All Articles