简介
本页面为开发者提供将GPT Action连接到GitHub的指导。在继续之前,请先熟悉以下资源:
此GPT Action帮助开发者评估GitHub拉取请求差异的质量和安全性。它为每个领域提供反馈和建议,允许开发者在自动将其作为评论提交到拉取请求之前修改或接受反馈。
价值与示例商业用例
值:
用户可以利用ChatGPT的自然语言处理能力来协助进行GitHub拉取请求的代码审查。
- 面向开发者:分析代码变更,对提出的修改提供即时反馈,执行高质量的代码审查。
- 对于组织: 确保代码差异遵循最佳实践和编码标准,或自动提出重构方案(可能需要额外的API请求来定义最佳实践)。
- 总体而言: 通过这款AI驱动的代码审查助手,提升生产力并确保更高质量、更安全的代码。
示例用例:
- 审阅者希望就拟议代码变更的质量和安全性获得反馈。
- 组织在代码审查过程中自动鼓励遵循最佳实践和标准。
演示视频:
应用信息
关键链接
开始之前,请先浏览以下资源:
先决条件
确保你有一个包含开放拉取请求的代码仓库。
应用设置
选择拉取请求
- Navigate to a repository, e.g., example PR.
- 注意所有者(例如"microsoft")、仓库名称(例如"vscode")和PR编号(例如"229241")。
- 如果代码仓库所有者是SSO组织,您的令牌可能需要审批。
- 查阅如何进行高质量的代码审查。
生成一个“细粒度”GitHub个人访问令牌
- 登录GitHub并进入设置。
- 导航至开发者设置 > 细粒度个人访问令牌。
- 点击生成新令牌,为其命名,设置过期日期,并选择所需权限范围(例如
read:content、read&write:pull_requests)。 - 复制并安全存储令牌。
ChatGPT 步骤
自定义GPT指令
创建自定义GPT后,将以下内容复制到指令面板中:
# **Context:** You support software developers by providing detailed information about their pull request diff content from repositories hosted on GitHub. You help them understand the quality, security and completeness implications of the pull request by providing concise feedback about the code changes based on known best practices. The developer may elect to post the feedback (possibly with their modifications) back to the Pull Request. Assume the developer is familiar with software development.
# **Instructions:**
## Scenarios
### - When the user asks for information about a specific pull request, follow this 5 step process:
1. If you don't already have it, ask the user to specify the pull request owner, repository and pull request number they want assistance with and the particular area of focus (e.g., code performance, security vulnerabilities, and best practices).
2. Retrieve the Pull Request information from GitHub using the getPullRequestDiff API call, owner, repository and the pull request number provided.
3. Provide a summary of the pull request diff in four sentences or less then make improvement suggestions where applicable for the particular areas of focus (e.g., code performance, security vulnerabilities, and best practices).
4. Ask the user if they would like to post the feedback as a comment or modify it before posting. If the user modifies the feedback, incorporate that feedback and repeat this step.
5. If the user confirms they would like the feedback posted as a comment back to the Pull request, use the postPullRequestComment API to comment the feedback on the pull request.OpenAPI 规范
创建自定义GPT后,在操作面板中复制以下文本。有问题吗?查看入门示例了解此步骤的详细操作方式。
以下是一个示例,展示了如何连接到GitHub以获取拉取请求差异并将反馈发布到拉取请求。
openapi: 3.1.0
info:
title: GitHub Pull Request API
description: Retrieve the diff of a pull request and post comments back to it.
version: 1.0.0
servers:
- url: https://api.github.com
description: GitHub API
paths:
/repos/{owner}/{repo}/pulls/{pull_number}:
get:
operationId: getPullRequestDiff
summary: Get the diff of a pull request.
parameters:
- name: owner
in: path
required: true
schema:
type: string
description: Owner of the repository.
- name: repo
in: path
required: true
schema:
type: string
description: Name of the repository.
- name: pull_number
in: path
required: true
schema:
type: integer
description: The number of the pull request.
- name: Accept
in: header
required: true
schema:
type: string
enum:
- application/vnd.github.v3.diff
description: Media type for the diff format.
responses:
"200":
description: Successfully retrieved the pull request diff.
content:
text/plain:
schema:
type: string
"404":
description: Pull request not found.
/repos/{owner}/{repo}/issues/{issue_number}/comments:
post:
operationId: postPullRequestComment
summary: Post a comment to the pull request.
parameters:
- name: owner
in: path
required: true
schema:
type: string
description: Owner of the repository.
- name: repo
in: path
required: true
schema:
type: string
description: Name of the repository.
- name: issue_number
in: path
required: true
schema:
type: integer
description: The issue or pull request number.
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
body:
type: string
description: The content of the comment.
responses:
"201":
description: Successfully created a comment.
content:
application/json:
schema:
type: object
properties:
id:
type: integer
body:
type: string
user:
type: object
properties:
login:
type: string
id:
type: integer
"404":
description: Pull request not found.认证说明
以下是设置与这个第三方应用程序进行身份验证的说明。有问题吗?查看入门示例以更详细地了解此步骤的工作原理。
在ChatGPT中(参考入门示例中的步骤2)
在ChatGPT中,点击"认证"并选择"Bearer"。输入以下信息。请确保您的令牌具有上文"应用设置"中描述的权限。
- 认证类型: API密钥
- 认证类型: Bearer
- API密钥
测试GPT
你现在可以开始测试GPT了。你可以输入一个简单的提示,比如"你能帮我审核拉取请求吗?所有者:

- 所引用拉取请求(PR)中的变更摘要。

- 针对下一轮PR迭代的质量与安全反馈及改进建议。

- 可以选择继续修改反馈意见,或者直接接受并由GPT以您的名义将评论发布到PR中。

是否有您希望我们优先考虑的集成方案?我们的集成是否存在错误?请在GitHub上提交PR或问题,我们会尽快查看。
