GitHub で Gemini Code Assist の動作をカスタマイズする

GitHub の Gemini Code Assist の動作は、リポジトリのルートにある .gemini/ フォルダに config.yaml ファイルを追加することで、個々のリポジトリごとに変更できます。config.yaml ファイルには、有効または無効にできるさまざまな構成可能な機能が含まれています。GitHub の Gemini Code Assist の動作のサブセットに対して、複数のリポジトリにわたるグループ構成を行うことができます。

Gemini Code Assist は、.gemini/ フォルダへの styleguide.md ファイルの追加もサポートしています。このファイルには、コードレビューの実行時に Gemini Code Assist に従わせる特定のルールが記述されています。Gemini Code Assist のスタイルガイドの詳細については、コードレビューのスタイルガイドをご覧ください。

構成フィールド

このセクションでは、GitHub の Gemini Code Assist の特定のカスタマイズ可能なフィールドに関する考慮事項について説明します。フィールドの完全なリストについては、config.yaml スキーマをご覧ください。

  • code_review: comment_severity_threshold: このフィールドは、Gemini Code Assist がコメントを投稿する最小の重大度を設定します。たとえば、code_review: comment_severity_threshold: HIGH を設定している場合、Gemini Code Assist は、軽微なリファクタリングなど、LOW または MEDIUM の重大度と見なされる問題について、pull リクエストのコメントを提供しません。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: 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 スキーマをご確認ください

次の手順では、複数のリポジトリで 1 つの構成セットを制御する方法を示します。以下の手順は、GitHub で Gemini Code Assist を設定していることを前提としています。

一般ユーザー

  1. Gemini Code Assist で、設定ページに移動します。

    設定に移動

  2. プロンプトが表示されたら、[Log in with GitHub] をクリックし、プロンプトに沿って Gemini Code Assist 内から GitHub にログインします。

  3. [Gemini] ページで、使用するアカウントを選択し、利用規約を確認して、[続行] をクリックします。

  4. [Free agent] ページで、必要に応じて設定を更新します。

  5. [保存] をクリックします。

Enterprise

  1. Google Cloud コンソールで、Gemini Code Assist の [エージェントとツール] ページに移動します。

    [エージェントとツール] に移動

  2. [エージェント] セクションで、[Code Assist ソースコード管理] カードを見つけて [詳細] をクリックします。

    [ソースコード管理用 Code Assist を編集] ペインが開きます。

  3. [接続] テーブルで、構成を適用する接続の名前をクリックします。

    接続の詳細ページが開きます。

  4. [設定] タブで、変更する設定を更新します。

  5. [保存] をクリックします。

次のステップ