Add reviewers via the commit message

Lekensteyn picture Lekensteyn · Jul 4, 2014 · Viewed 17.7k times · Source

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.

Answer

love picture love · Jul 5, 2014

There are few other ways of doing this.

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

  2. 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 :)