使用 Gemini Code Assist 查看 GitHub 代码
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Gemini Code Assist for GitHub 可充当代码审核者,将 Gemini 的强大功能引入拉取请求流程。Gemini Code Assist 使用 Gemini 赋能的代理自动总结拉取请求并提供深入的代码审核,从而加快代码编写速度并提高代码质量。您可以在拉取请求的任何阶段调用 Gemini Code Assist 来审核代码。
您可以通过以下方式直接在拉取请求评论中与 Gemini 互动:
- 针对 Gemini 创建的评价提出澄清性问题。
- 通过在评论中添加
/gemini
标记来提示 Gemini,以便在拉取请求的上下文中提出问题。
Gemini 会自动从代码库和拉取请求中检索有用信息,以执行其任务。
本文档适用于各种技能水平的开发者。本教程假定您具备 GitHub 的相关知识。
准备工作
如需测试本文档中的步骤,请确保您执行以下操作之一:
安装 Gemini Code Assist for GitHub
您可以按照以下步骤安装 Gemini Code Assist:
前往 GitHub 专用 Gemini Code Assist 应用页面。
如果您尚未登录 GitHub 账号,请先登录。
点击安装。
系统会显示提示,要求为用户或组织安装 Gemini Code Assist。
当系统提示为用户或组织安装 Gemini Code Assist 时,请选择您打算使用它的组织。
为 GitHub 组织安装 Gemini Code Assist 后,系统会提示您选择要启用代码审核集成功能的代码库。
系统会将您重定向至 Gemini Code Assist 管理控制台。
使用您的 GitHub 账号登录。
从下拉菜单中选择 GitHub 组织或个人账号。
查看并接受《Google 服务条款》《生成式 AI 使用限制政策》和《隐私权政策》,然后点击完成设置。
Gemini Code Assist 已添加到您所选代码库中的 pull 请求。
创建后,每当拉取请求作者或其他人工审核员在拉取请求中添加带有 /gemini
标记的注释时,Gemini Code Assist 都会为您的代码审核提供建议。
现在,Gemini Code Assist 已针对您所选代码库中的所有拉取请求处于活跃状态!在下一部分中,您将了解如何获取拉取请求摘要和反馈。
获取拉取请求摘要和反馈
如需让 Gemini Code Assist 为拉取请求提供初步审核,请创建新的拉取请求。
当您打开新的拉取请求时,Gemini Code Assist 会提供初步审核。审核准备就绪后,gemini-code-assist[bot]
会自动作为审核者添加到拉取请求中。Gemini Code Assist 会在拉取请求的对话标签页中添加包含其反馈的问题注释,然后继续添加有关代码修改部分的注释。
评价包含以下信息:
- 问题的严重程度,分为“严重”“高”“中”和“低”
- 针对问题提供反馈
- 可直接从 GitHub 提交的代码建议
- 对用户提供的样式指南的引用
手动调用 Gemini Code Assist
Gemini Code Assist 会监听任何拉取请求贡献者的评论,并决定是否应做出回应。
如需手动调用 Gemini Code Assist,您可以在拉取请求的主评论页面中使用以下命令作为问题评论。
命令 |
说明 |
/gemini summary |
发布拉取请求中的更改摘要 |
/gemini review |
发布拉取请求中更改的代码审核 |
/gemini |
在注释中手动调用 Gemini Code Assist |
/gemini help |
可用命令概览 |
管理 Gemini Code Assist 设置
有权修改组织的 GitHub 应用设置的任何人都可以管理 Gemini Code Assist 设置。您可以查看向 Gemini Code Assist 授予的权限、管理代码库访问权限,以及卸载 Gemini Code Assist。
如需修改设置,请按以下步骤操作:
- 在 GitHub 上,点击您的个人资料照片,然后点击设置。
- 在集成部分,点击应用。
系统会显示 GitHub 应用列表。
- 在 Gemini Code Assist 旁边,点击配置。
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[],[],null,["# Review GitHub code using Gemini Code Assist\n\nGemini Code Assist for GitHub brings the power of\nGemini to the pull request process by acting as a code reviewer.\nGemini Code Assist speeds up and increases the quality of code\nusing a Gemini-powered agent that automatically summarizes pull\nrequests and provides in-depth code reviews. You can invoke\nGemini Code Assist at any stage of the pull request to review the code.\n\nYou can interact with Gemini in the pull request comments directly by:\n\n- Asking clarifying questions on the review that Gemini creates.\n- Prompting Gemini by adding the `/gemini` tag to your comments to ask questions in the context of the pull request.\n\nGemini will automatically retrieve helpful information from the\nrepository and pull request to perform its tasks.\n\nThis document is intended for developers of all skill levels. It assumes that\nyou have a working knowledge of GitHub.\n\nBefore you begin\n----------------\n\nTo test the steps in this document, make sure you do one of the following:\n\n- Use your own GitHub repository. Gemini Code Assist\n doesn't support organizations that enable private connectivity.\n\n- Create a fork of [our sample repository](https://github.com/GoogleCloudPlatform/microservices-demo).\n\nInstall Gemini Code Assist for GitHub\n-------------------------------------\n\nYou can install Gemini Code Assist by following these\nsteps:\n\n1. Go to the [Gemini Code Assist for GitHub](https://github.com/apps/gemini-code-assist)\n app page.\n\n2. Sign in to your GitHub account if you haven't already.\n\n3. Click **Install**.\n\n A prompt to install Gemini Code Assist for a user or\n organization is displayed.\n4. When prompted to install Gemini Code Assist for a user or\n organization, select the organization you intend to use it on.\n\n After you've installed Gemini Code Assist for your\n GitHub organization, you're prompted to select the repositories to\n enable the Code Review integration.\n\n You're redirected to the Gemini Code Assist Admin Console.\n5. Login with your GitHub account.\n\n6. Select a GitHub organization or personal account from the drop-down\n menu.\n\n7. Review and accept the Google Terms of Service, Generative AI Prohibited Use\n Policy and Privacy Policy, and then click **Complete setup**.\n\n Gemini Code Assist is added to the pull requests within your\n selected repositories.\n\nAfter creation, Gemini Code Assist provides suggestions to your\ncode review every time the pull request author or other human reviewers add\ncomments with the `/gemini` tag on the pull request.\n\nGemini Code Assist is now active for all the pull\nrequests within your selected repositories! In the next section, you learn\nhow to get pull request summaries and feedback.\n\nGet pull request summary and feedback\n-------------------------------------\n\nTo get an initial review for a pull request from\nGemini Code Assist, create a new pull request.\n\nWhen you open the new pull request, Gemini Code Assist provides\nan initial review. After the review is ready,\n`gemini-code-assist[bot]` is automatically added as a reviewer to the pull\nrequest. Gemini Code Assist adds an issue comment in the\n**Conversation** tab of the pull request with its feedback, and proceeds to add\ncomments about modified portions of the code.\n\nReview comments contain the following information:\n\n- Severity of the issue, given as Critical, High, Medium, and Low\n- Feedback on the issue\n- Code suggestion that can be committed directly from GitHub\n- References to a user-provided style guide\n\nManually invoke Gemini Code Assist\n----------------------------------\n\nGemini Code Assist listens to comments from any pull request\ncontributor, and decides whether it should respond.\n\nTo manually invoke Gemini Code Assist, you can use the\nfollowing commands in the main comments page on the pull request as an issue\ncomment.\n\n| Command | Description |\n|-------------------|--------------------------------------------------------|\n| `/gemini summary` | Posts a summary of the changes in the pull request |\n| `/gemini review` | Posts a code review of the changes in the pull request |\n| `/gemini` | Manually invokes Gemini Code Assist in comments |\n| `/gemini help` | Overview of the available commands |\n\nManage the Gemini Code Assist settings\n--------------------------------------\n\nAnyone with permissions to modify GitHub App settings for the\norganization can manage the Gemini Code Assist settings. You can review\nthe permissions provided to the Gemini Code Assist, manage repository\naccess, and uninstall Gemini Code Assist.\n\nTo modify the settings, follow these steps:\n\n1. On GitHub, click your profile photo and then click **Settings**.\n2. In the **Integrations** section, click **Applications**. A list of GitHub Apps is displayed.\n3. Beside Gemini Code Assist, click **Configure**.\n\nWhat's next\n-----------\n\n- Learn how to [customize Gemini Code Assist behavior in GitHub](/gemini-code-assist/docs/customize-gemini-behavior-github)."]]