Gerrit 项目管理者指南

项目拥有者必读,学习如何定制项目的工作流配置。

访问权限

项目的配置文件信息存储在特定的代码分支:refs/meta/config, 可以在本地拉取查看:

git fetch ssh://localhost:29418/project refs/meta/config & git checkout FETCH_HEAD
git log project.config

📑 所有配置项目说明

权限分配的粒度 References

  • refs/heads/* : 所有分支代码
  • refs/tags/* : 所有标签
  • refs/for/<ref> : changes 修改上传分支代码
  • ^refs/heads/rel-.* : 正则表达式,所有 rel-* 分支代码
  • Special references:
    • refs/changes/*
    • refs/meta/config
    • refs/meta/dashboards/*
    • refs/notes/review

Groups & User 权限

  • Gerrit also has a set of special system groups that you might find useful.
  • External groups need to be prefixed when assigning access rights to them, e.g. LDAP group names need to be prefixed with ldap/.
  • If the singleusergroup plugin is installed you can also directly assign access rights to users, by prefixing the username with user/ or the user’s account ID by userid/.

Access controls in Gerrit are group based.

  • 系统定义的用户组:Anonymous Users | Change Owner | Project Owners | Registered Users
  • 预定义的用户组:Administrators | Service Users
  • 自定义用户组

详细文档:https://gerrit-review.googlesource.com/Documentation/access-control.html

代码修改提交方式 Sumbit.type

这个方式选择影响整个代码的协作方式,以及开发舒适度的权衡。

  • Fast Forward Only: 限制非常严格,在提交一项修改后,所有基于此分支基础进行的分支都必须重新调整(rebase), 适用于变化很少的分支,但是可以确保目标分支永远不会被破坏。
  • Merge If Necessary:开发者友好,工程师只需要在有冲突时进行 rebase 调整,缺点是存在破坏目标分支的风险,推荐在开发阶段分支上面使用。
    • 等同于 git merge --ff
  • Merge Always: 提交更改时,直接创建合并请求,不关心是否可以快进。
    • 等同于 git merge --no-ff
  • Rebase if necessary: 在无法快进的状态下,自动进行 rebase 操作。
    • Using this submit action results in a linear history of the target branch, unless merge commits are being submitted. For some people this is an advantage since they find the linear history easier to read.
  • Rebase always:提交代码更改时,会直接进行 rebase 操作,不关心是否可以快进
    • rebase always 操作可以被认为与 cherry pick 操作类似,但有一个重要的区别,即 rebase always 不会忽略依赖关系,这就是为什么使用该操作应该优先于 cherry pick 提交操作
  • Cherry Pick: 通过此提交操作,在提交更改时,Gerrit 始终会对当前补丁集执行挑选。 这会忽略父沿袭,而是在目标分支的当前头之上创建一个全新的提交。 提交者成为新提交的提交者,并且保留原始提交作者。
    • 忽略依赖关系还意味着提交者需要以正确的顺序单独提交更改。 否则,提交可能会因冲突而失败,或者目标分支被破坏。
    • 不建议使用此提交操作,因为它会忽略更改依赖项,而应始终使用 rebase。

提交方式配置也可以从其他项目继承,默认是 'merge if necessary';

提交信息的检查

Plugins:

  • https://gerrit-review.googlesource.com/admin/repos/plugins/uploadvalidator,general
  • https://gerrit-review.googlesource.com/admin/repos/plugins/commit-message-length-validator,general

Review 流程 - 标签功能 Labels

CI 工具集成

  • https://gerrit-documentation.storage.googleapis.com/Documentation/3.9.1/intro-project-owner.html#continuous-integration

问题追踪 Issue Tracker Integration

飞书文档项目追踪示例:拼加项目工单

  • https://gerrit-documentation.storage.googleapis.com/Documentation/3.9.1/intro-project-owner.html#issue-tracker-integration

其他操作