您可以向位于代码库根目录中的 .gemini/ 文件夹添加 config.yaml 文件,从而修改 GitHub 中的 Gemini Code Assist 针对各个代码库的行为。config.yaml 文件包含各种可配置的功能,您可以启用或停用这些功能。您可以针对 GitHub 上 Gemini Code Assist 的部分行为跨多个代码库执行群组配置。
Gemini Code Assist 还支持向 .gemini/ 文件夹添加 styleguide.md 文件,该文件会指示 Gemini Code Assist 在执行代码审核时遵循一些特定规则。如需详细了解 Gemini Code Assist 的样式指南,请参阅代码审核样式指南。
配置字段
本部分介绍了 Gemini Code Assist on GitHub 中特定可自定义字段的注意事项。如需查看完整字段列表,请参阅 config.yaml 架构。
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。
在 Google Cloud 控制台中,前往 Gemini Code Assist 代理和工具页面。
在代理部分中,找到 Code Assist 源代码管理卡片,然后点击高级。
系统会打开 Edit Code Assist Source Code Management 窗格。
在连接表格中,点击要应用配置的连接的名称。
系统会打开相应连接的详情页面。
在设置标签页中,更新您要更改的设置。
点击保存。