在 GitHub 中自訂 Gemini Code Assist 的行為

GitHub 上的 Gemini Code Assist 可讓您為個別存放區調整程式碼審查行為,或在多個存放區套用群組設定。

GitHub 上的 Gemini Code Assist 也支援新增 styleguide.md 檔案。如要進一步瞭解這項功能,請參閱「程式碼審查樣式指南」。

設定欄位

如要修改 GitHub 上的 Gemini Code Assist 行為,請在每個存放區的根目錄中,將 config.yaml 檔案新增至 .gemini/ 資料夾。config.yaml 檔案包含各種可設定的功能,您可以啟用或停用這些功能。如需完整欄位清單,請參閱 config.yaml 結構定義。

以下是在 GitHub 專用 Gemini Code Assist 中,自訂特定欄位時的注意事項:

  • code_review: comment_severity_threshold:這個欄位會設定 Gemini Code Assist 發布註解的最低嚴重程度。舉例來說,如果設定為 code_review: comment_severity_threshold: HIGH,Gemini Code Assist 就不會針對它認為嚴重程度為 LOW 或 MEDIUM 的問題提供提取要求註解,例如次要重構。Gemini Code Assist 會根據考量的問題類型和重要性,判斷註解的嚴重程度,通常違反自訂風格指南的註解會達到或超過嚴重程度閾值。

  • ignore_patterns:這個欄位會使用 glob 模式。與存放區互動時,Gemini Code Assist 會忽略符合這份清單中任何模式的檔案。

  • memory_config:如果您先前已為多個存放區啟用提升回覆品質功能,則適用此欄位。為多個存放區啟用提升回覆品質功能後,您可以為群組中的特定存放區設定 memory_config: disabled: true,停用該存放區的功能。

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: false.
          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: false
    code_review: true
    include_drafts: true
ignore_patterns: []

管理多個存放區的設定

如果存放區是依Developer Connect 連線分組,您可以切換多個存放區的特定設定。這些集體設定是透過 Google Cloud 控制台管理。

如果存放區是群組的一部分,但也有自己的 config.yaml,則存放區的 config.yaml 設定會覆寫群組設定。

如要瞭解特定設定行為和例外狀況,請查看 config.yaml 結構定義。

下列步驟說明如何跨多個存放區控管一組設定。這些步驟假設您先前已在 GitHub 上設定 Gemini Code Assist。

  1. 前往 Google Cloud 控制台的「Gemini Code Assist Agents & Tools」(Gemini Code Assist 代理程式和工具) 頁面。

    前往「代理程式與工具」

  2. 在「Agents」部分中,找出「Code Assist Source Code Management」資訊卡,然後按一下「Advanced」。

    「Edit Code Assist Source Code Management」(編輯 Code Assist 原始碼管理) 窗格隨即開啟。

  3. 在「連線」表格中,按一下要套用設定的連線名稱。

    系統會開啟連線的詳細資料頁面。

  4. 在「設定」分頁中,更新要變更的設定。

  5. 按一下 [儲存]。

後續步驟