Gerrit作为审查工具,而不是记录的存储库 [英] Gerrit as a review tool, not as the repository of record

查看:177
本文介绍了Gerrit作为审查工具,而不是记录的存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从快速入门指南中创建了一个gerrit实例。

我的公司使用BitBucket进行拉取请求,偶尔用于代码评论的坩埚。我们使用Jenkins的一个与BitBucket绑定的广泛构建/部署管道。



我们希望集成gerrit以进行代码审查,因为它具有阶段提交和构建/验证他们在审查之前被接受。

基本上,我希望gerrit的提交按钮将上游推送到BitBucket。 (我宁愿不处理试图通过复制来做到这一点;我想因为企业惯性而将BitBucket保持为上游/记录存储库。)



有没有人有有关如何完成此任务的任何建议?该功能是否存在,或者这是一个新颖的想法?

解决方案

Gerrit通过提供(更多或无论)在Gerrit自身托管的实际Git存储库周围的瘦包装器。据我所知,没有可能直接在Gerrit中整合一个外部Git仓库。



这意味着在使用Gerrit时,需要托管Git仓库在Gerrit本身内。因此,您需要在Gerrit实例中维护BitBucket存储库的完整副本。所以这个问题基本归结为保持两个Git仓库同步

从BitBucket同步到Gerrit的新提交



由于您已经在使用Jenkins,因此每当将新提交推送到BitBucket存储库时,我都会推荐一个Jenkins版本来更新您的Gerrit存储库。为此,您需要:


  1. 具有直接推送功能的Gerrit用户。为此,您需要在Gerrit项目中的 refs / heads / * ref上授予 Push 特权。 Jenkins将使用此用户。注意不要将此特权授予任何最终用户,否则他们将能够通过直接推送绕过代码审查。

  2. Jenkins作业配置为每当将新提交推送到你的BitBucket存储库。在该工作中,只需将所有分支推送到您的Gerrit实例即可。

  3. 配置BitBucket服务钩子来触发您的Jenkins构建(为此,您的Jenkins实例需要公开访问;否则只需简单地将您的Jenkins作业的计划设置为一个很短的时间间隔以最小化同步延迟)。
    同步从Gerrit到BitBucket的新提交

    在Gerrit中提交代码评论时,新提交将需要推回到BitBucket。通常,我会推荐使用复制插件。以下是相应的配置文件的样子(在Gerrit目录中进入 etc / replication.config ):

      [remotebitbucket] 
    url = ssh://git@bitbucket.org/< your-user> / $ {name} .git
    push = + refs / tags / *:refs / tags / *
    push = + refs / heads / *:refs / heads / *
    mirror = true
    replicateOnStartup = true
    replicatePermissions = false

    既然你提到过你想避免使用复制,你也可以使用Jenkins从Gerrit同步提交到BitBucket的作业。为了尽量减少延迟,您可以使用 Gerrit触发器插件对于詹金斯(你会希望用于预先提交检查)。或者,您可以使用放置在 hooks / ref-updated 中的自定义Gerrit钩子触发Jenkins构建(如果您希望我详细说明)。



    希望这有助于!


    I've spun up an instance of gerrit from the quick start guide.

    My company uses BitBucket with pull requests and occasionally crucible for code reviews. We use Jenkins with an extensive build/deploy pipeline tied to BitBucket.

    We'd like to integrate gerrit for code review because of its ability to stage commits and build/verify them before the review is accepted.

    Basically, I want gerrit's "submit" button to push upstream to BitBucket. (I'd rather not deal with trying to do this by replication; I want to maintain BitBucket as upstream/repository of record because of corporate inertia.)

    Does anyone have any suggestions for how to accomplish this? Does the capability exist, or is this a novel idea?

    解决方案

    Gerrit implements it's code review functionalities by providing a (more-or-less) thin wrapper around an actual Git repository that is hosted within Gerrit itself. To my knowledge, there is no possibility to integrate an external Git repository directly in Gerrit.

    This means that when using Gerrit, the Git repository needs to be hosted within Gerrit itself. In consequence of that, you will need to maintain a full copy of your BitBucket repository within your Gerrit instance. So this question basically boils down to keeping two Git repositories in sync.

    Synchronizing new commits from BitBucket to Gerrit

    As you're already using Jenkins, I'd recommend a Jenkins build to update your Gerrit repository whenever new commits are pushed to the BitBucket repository. For this, you'll need:

    1. A Gerrit user with direct push capabilities. For this, you'll need to grant Push privileges on the refs/heads/* ref in your Gerrit project. This user will be used by Jenkins. Be careful not to grant this privilege to any end-users, or they'll be able to bypass code review by pushing directly.
    2. A Jenkins job configured to build whenever new commits are pushed to your BitBucket repository. Within that job, simply push all branches to your Gerrit instance.
    3. Configure a BitBucket service hook to trigger your Jenkins build (for this, your Jenkins instance will need to be publicly accessible; otherwise simply set the schedule of your Jenkins job to a short interval to minimize the delay in synchronization).

    Synchronizing new commits from Gerrit to BitBucket

    When submitting code reviews in Gerrit, the new commits will need to be pushed back to BitBucket. Usually, I'd recommend using the replication plugin for that. Here's how a respective configuration file might look like (goes in etc/replication.config in your Gerrit directory):

    [remote "bitbucket"]
        url = ssh://git@bitbucket.org/<your-user>/${name}.git
        push = +refs/tags/*:refs/tags/*
        push = +refs/heads/*:refs/heads/*
        mirror = true
        replicateOnStartup = true
        replicatePermissions = false
    

    Since you mentioned that you'd like to avoid using replication, you can also use a Jenkins job for synchronizing commits from Gerrit back to BitBucket. To minimize the delay, you can use the Gerrit Trigger plugin for Jenkins (which you'll want to be using anyway for your pre-commit checks). Alternatively, you can use a custom Gerrit hook that you place in hooks/ref-updated to trigger a Jenkins build (drop a comment if you'd like me to elaborate on that).

    Hope this helps!

    这篇关于Gerrit作为审查工具,而不是记录的存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆