Is it possible to add reviewers in Gerrit via a commit message? Consider this commit message:
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: [email protected]
Cc: [email protected]
Here, [email protected]
and [email protected]
must be added as reviewers when pushing to gerrit.
I am aware of a special branch specifier to add reviewers, but would like to have something more automated as I create commits. The changes are independent, though it would be nice if I could group them on a topic branch because they are related.
It is not possible to set per-commit reviewers, these are applied per push (see gerrit's git-receive-pack manual). Instead of executing git push origin HEAD
or git review
(assuming origin
to be the gerrit remote, and HEAD
the branch you want to push), you can run the following to add two reviewers for all new commits:
git push origin HEAD:refs/for/master%[email protected],[email protected]
That gets applied to all commits which is not what you want. Due to the above limitations, let's change the workflow to push changes first and then set some reviewers.
Since Gerrit distinguishes between Cc
(just send a mail notification) and reviewers (send a mail, but also mark the user as reviewer), I'll 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.
[email protected]
[email protected]
Change-Id: I4724e283214e0bfbb85a8e3d8db4971618e2609a
Given a number of commits, one can follow the following steps to add separate reviewers for each commit:
Change-Id
s). Example that assumes the master branch as base: git rev-list --reverse origin/master..
R=...
(reviewers) in the commit message. The commit message for a given commit can be found with git show --no-patch --format=%b COMMIT_ID
ssh -p 29418 user@host 'gerrit set-reviewers -a [email protected] COMMIT_ID'
(instead of COMMIT_ID
, you can also use the Change-Id
which is I4724e283214e0bfbb85a8e3d8db4971618e2609a
for the example).To perform the above steps (together with auto-detecting the user, host and port settings), I wrote a Bash script: https://git.lekensteyn.nl/scripts/tree/git/gerrit-add-reviewers
It is recommended to have a .gitreview
file in your repo with a remote that points to a Gerrit instance. Then execute ~/scripts/gerrit-add-reviews origin/master..
from within that git repo to scan commit messages and add reviewers.
There are few other ways of doing 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, when you want to push a review, just do: git push review and “reviewer1” and “reviewer2” will be added to your patchset.
I think you can also write some script/ hook to automate this. After commiting just grep the Change-id of the commit, and use it with below gerrit command:
ssh -p gerrit set-reviewers [--project (PROJECT) | -p (PROJECT)] [--add (REVIEWER) … | -a (REVIEWER) …] [--] {COMMIT | CHANGE-ID}
Example: ssh -p 29418 gerrit.example.com gerrit set-reviewers -a [email protected] Iac6b2ac2
I hope it will help you :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With