在 GitHub 中自定义 Gemini Code Assist 行为

您可以通过将 config.yaml 文件添加到位于代码库根目录中的 .gemini/ 文件夹,为各个代码库修改 GitHub 中的 Gemini Code Assist 行为。config.yaml 文件包含各种可配置的功能,您可以启用或停用这些功能。您可以针对 GitHub 中的 Gemini Code Assist 行为的子集,跨多个代码库执行群组配置。

Gemini Code Assist 还支持将 styleguide.md 文件添加到 .gemini/ 文件夹,该文件会指示 Gemini Code Assist 在执行代码审核时遵循一些特定规则。 如需详细了解 Gemini Code Assist 的样式指南, 请参阅 代码审核样式指南

配置字段

本部分介绍了 GitHub 中的 Gemini Code Assist 中特定可自定义字段的注意事项。如需查看 字段的完整列表,请参阅 config.yaml 架构

config.yaml 架构

以下代码段是 config.yaml 文件的架构。它定义了所有可能的配置选项及其接受的值:

$schema: "http://json-schema.org/draft-07/schema#"
title: RepoConfig
description: Configuration for Gemini Code Assist on a repository. All fields are optional and have default values.
type: object
properties:
  have_fun:
    type: boolean
    description: Enables fun features such as a poem in the initial pull request summary. Default: false.
  ignore_patterns:
    type: array
    items:
      type: string
    description: A list of glob patterns for files and directories that Gemini Code Assist should ignore. Default: [].
  memory_config:
    type: object
    description: Configuration for persistent memory, which is used to improve responses.
    properties:
      disabled:
        type: boolean
        description: Whether to disable persistent memory for this specific repository. Default: false.
  code_review:
    type: object
    description: Configuration for code reviews. All fields are optional and have default values.
    properties:
      disable:
        type: boolean
        description: Disables Gemini from acting on pull requests. Default: false.
      comment_severity_threshold:
        type: string
        enum:
          - LOW
          - MEDIUM
          - HIGH
          - CRITICAL
        description: The minimum severity of review comments to consider. Default: MEDIUM.
      max_review_comments:
        type: integer
        format: int64
        description: The maximum number of review comments to consider. Use -1 for unlimited. Default: -1.
      pull_request_opened:
        type: object
        description: Configuration for pull request opened events. All fields are optional and have default values.
        properties:
          help:
            type: boolean
            description: Posts a help message on pull request open. Default: false.
          summary:
            type: boolean
            description: Posts a pull request summary on the pull request open. Default: true.
          code_review:
            type: boolean
            description: Posts a code review on pull request open. Default: true.
          include_drafts:
            type: boolean
            description: Enables agent functionality on draft pull requests. Default: true.

config.yaml 示例

以下代码段是 config.yaml 文件的示例。在此示例中,每个属性都设置为 Gemini Code Assist 使用的默认值。您可以使用此代码段作为模板来创建自己的 config.yaml 文件:

have_fun: false
memory_config:
  disabled: false
code_review:
  disable: false
  comment_severity_threshold: MEDIUM
  max_review_comments: -1
  pull_request_opened:
    help: false
    summary: true
    code_review: true
    include_drafts: true
ignore_patterns: []

跨多个代码库管理配置

GitHub 中的 Gemini Code Assist 的某些方面可以跨多个代码库进行管理:

  • 如果您使用的是消费者版本,则可以为与账号关联的所有代码库切换某些设置。

  • 如果您使用的是企业版,则可以为按 Developer Connect 连接分组的多个代码库切换某些设置。执行此操作后,您可以通过 Google Cloud 控制台管理其集体设置。

如果代码库作为群组的一部分进行管理,但也有自己的 config.yaml,则代码库的 config.yaml 设置会替换群组设置。

如需了解特定设置行为和例外情况, 请查看 config.yaml 架构

以下步骤展示了如何跨多个代码库控制一组配置。这些步骤假定您之前已 设置 GitHub 中的 Gemini Code Assist

使用方

  1. 在 Gemini Code Assist 中,前往设置页面。

    前往设置

  2. 如果系统提示,请点击使用 GitHub 登录 ,然后按照提示从 Gemini Code Assist 内登录 GitHub。

  3. Gemini 页面中,选择要使用的账号,查看服务条款,然后点击继续

  4. 自由代理 页面中,根据需要更新设置。

  5. 点击保存

企业版

  1. 在 Google Cloud 控制台中,前往 Gemini Code Assist 代理和工具 页面。

    前往“代理和工具”

  2. 代理 部分中,找到 Code Assist 源代码管理 卡片,然后点击高级

    系统会打开修改 Code Assist 源代码管理 窗格。

  3. 连接 表格中,点击要应用配置的连接的名称。

    系统会打开连接的详情页面。

  4. 设置 标签页中,更新要更改的设置。

  5. 点击保存

后续步骤