git 通过提交消息添加审阅者

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24576855/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:10:23  来源:igfitidea点击:

Add reviewers via the commit message

gitgerrit

提问by Lekensteyn

Is it possible to add reviewers in Gerrit via a commit message? Consider this commit message:

是否可以通过提交消息在 Gerrit 中添加审阅者?考虑这个提交消息:

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.

在这里,[email protected]并且[email protected]必须在推送到 gerrit 时添加为审阅者。

I am aware of a special branch specifierto 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.

我知道有一个特殊的分支说明符来添加审阅者,但希望在我创建提交时有一些更自动化的东西。这些更改是独立的,但如果我可以将它们分组到一个主题分支中会很好,因为它们是相关的。

回答by love

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 reviewand “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

  1. 只需将这些行添加到您的 .git/config

    【远程“回顾”】

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

    push = HEAD:refs/for/master

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

    现在,当您想要推送评论时,只需执行:git push review并且“reviewer1”和“reviewer2”将被添加到您的补丁集中。

  2. 我想你也可以写一些脚本/钩子来自动化这个。提交后只需 grep 提交的 Change-id,并在以下 gerrit 命令中使用它:

    ssh -p gerrit set-reviewers [--project (PROJECT) | -p (项目)] [--add (审阅者) … | -a(审稿人)……] [--] {提交 | 更改 ID}

    示例:ssh -p 29418 gerrit.example.com gerrit set-reviewers -a [email protected] Iac6b2ac2

I hope it will help you :)

我希望它会帮助你:)

回答by Lekensteyn

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 HEADor git review(assuming originto be the gerrit remote, and HEADthe branch you want to push), you can run the following to add two reviewers for all new commits:

无法设置每个提交的审阅者,这些是按推送应用的(请参阅gerrit 的 git-receive-pack 手册)。而不是执行的git push origin HEADgit review(假设origin到很远的格里特,并HEAD要推的分支),你可以运行下面添加两个审阅所有新提交:

git push origin HEAD:refs/for/master%[email protected],[email protected]

That gets applied to allcommits 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.

这适用于所有不是您想要的提交。由于上面的限制,我们把工作流改成先push变化,再设置一些reviewer。



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:

由于 Gerrit 区分Cc(只发送邮件通知)和审阅者(发送邮件,但也将用户标记为审阅者),我将修改提交消息如下:

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:

给定多个提交,可以按照以下步骤为每个提交添加单独的审阅者:

  1. Gather a list of commits IDs (or Change-Ids). Example that assumes the master branch as base: git rev-list --reverse origin/master..
  2. For each commit ID, scan for 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
  3. If reviewers exist for a commit message, add them with the command ssh -p 29418 user@host 'gerrit set-reviewers -a [email protected] COMMIT_ID'(instead of COMMIT_ID, you can also use the Change-Idwhich is I4724e283214e0bfbb85a8e3d8db4971618e2609afor the example).
  1. 收集提交 ID(或Change-Ids)的列表。假设主分支为基础的示例:git rev-list --reverse origin/master..
  2. 对于每个提交 ID,R=...在提交消息中扫描(reviewers)。可以找到给定提交的提交消息git show --no-patch --format=%b COMMIT_ID
  3. 如果存在提交消息的审阅者,请使用命令添加它们ssh -p 29418 user@host 'gerrit set-reviewers -a [email protected] COMMIT_ID'COMMIT_ID您也可以使用Change-IdwhichI4724e283214e0bfbb85a8e3d8db4971618e2609a用于示例)。

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

为了执行上述步骤(连同自动检测用户、主机和端口设置),我编写了一个 Bash 脚本:https: //git.lekensteyn.nl/scripts/tree/git/gerrit-add-reviewers

It is recommended to have a .gitreviewfile 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.

建议.gitreview在您的 repo 中有一个文件,其中有一个指向 Gerrit 实例的远程文件。然后~/scripts/gerrit-add-reviews origin/master..从该 git 存储库中执行以扫描提交消息并添加审阅者。

回答by andersonvom

I put together a script where you can pass the email addresses of the reviewers you want to add and it will take care of the rest for you. You can even fuzzy-find in existing committers (email and name), so that you don't have to type a lot.

我整理了一个脚本,您可以在其中传递要添加的审阅者的电子邮件地址,它会为您处理其余的工作。您甚至可以在现有提交者(电子邮件和姓名)中进行模糊查找,这样您就不必输入太多内容。

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

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

Just call it using:

只需使用以下方法调用它:

$ greview [<rev1> [<rev2> [...]]]

回答by u9192085

Send a review for a change on the master branch to [email protected]:

将 master 分支上的更改评论发送至 [email protected]

git push ssh://review.example.com:29418/project HEAD:refs/for/master%[email protected]

Send reviews, but tagging them with the topic name 'bug42':

发送评论,但用主题名称“bug42”标记它们:

git push ssh://review.example.com:29418/project HEAD:refs/for/master%[email protected],topic=bug42

Also CC two other parties:

还抄送另外两方:

git push ssh://review.example.com:29418/project HEAD:refs/for/master%[email protected],[email protected],[email protected]

Configure a 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%[email protected],[email protected],[email protected]

afterwards .git/config contains the following:

之后 .git/config 包含以下内容:

[remote "charlie"]
  url = ssh://review.example.com:29418/project
  push = HEAD:refs/for/master%[email protected],[email protected],[email protected]

and now sending a new change for review to charlie, CC'ing both alice and bob is much easier:

现在向查理发送一个新的更改以供,抄送爱丽丝和鲍勃要容易得多:

git push charlie

回答by The Godfather

There is very nice Git-reviewtool for simplifying your life with Gerrit. Apart of other syntax sugar advantages, it allows you to add reviewers via command-line like:

有一个非常好的Git-review工具可以简化你的 Gerrit 生活。除了其他语法糖优势外,它还允许您通过命令行添加审阅者,例如:

git review --reviewers [email protected] [email protected]

And of course you can create git aliases out of it to make it simpler like:

当然,您可以从中创建 git 别名以使其更简单,例如:

#git review --reviewers [email protected] [email protected]
git publish

It's not directly answering your question "how to add reviewers from commit message", but it can be used, for example, to create custom pre-commit hook and extract emails first and push them to gerrit second

它不是直接回答您的问题“如何从提交消息添加审阅者”,但它可以用于,例如,创建自定义预提交挂钩并首先提取电子邮件,然后将它们推送到 gerrit

回答by Muralidhar BN

Below solution works

以下解决方案有效

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

ssh -p gerrit set-reviewers [--project (PROJECT) | -p (项目)] [--add (审阅者) … | -a(审稿人)……] [--] {提交 | 更改 ID}

Example: ssh -p 29418 gerrit.example.com gerrit set-reviewers -a [email protected] Iac6b2ac2

示例:ssh -p 29418 gerrit.example.com gerrit set-reviewers -a [email protected] Iac6b2ac2

回答by liuyang1

Combine gerrit stream-events and set-reviewers, you can do this.

结合 gerrit 流事件和设置器,你可以做到这一点。

Actually, you first need get the CL's status (create, update & ...), then execute corresponding action, such as add reviewers, even submit CL.

其实,你首先需要获取CL的状态(创建,更新......),然后执行相应的操作,例如添加评论者,甚至提交CL。

  1. get gerrit events from "gerrit stream-events" command.

  2. parse the JSON format event as each line. In the JSON event, we can get project, branch, Change-Id, CL-number, subject of Commit(not entire commit), and a lot information.

  1. 从“ gerrit stream-events”命令获取gerrit事件。

  2. 将 JSON 格式事件解析为每一行。在 JSON 事件中,我们可以得到项目、分支、Change-Id、CL-number、提交的主题(不是整个提交)和很多信息。

if you really need entire commit message, "gerrit query" is useful.

如果你真的需要完整的提交信息,“ gerrit query”很有用。

filter the "patchset-created", patchSet's number is 1(if you only like do this for new patchSet), parse the subject of commit, and get the reviewers as you predefined.

过滤“patchset-created”,patchSet 的编号为 1(如果您只喜欢对新的 patchSet 执行此操作),解析提交的主题,并按照您的预定义获取审阅者。

  1. use "gerrit set-reviewers" command, to add reviewer.
  1. 使用“ gerrit set-reviewers”命令,添加审阅者。

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

作为我的习惯,使用python,这一切都很容易。

Its flow is like a tiny Jenkins.

它的流动就像一个小小的詹金斯。