Skip to content

Commit 6f731f4

Browse files
authored
GPT Action GitHub (#1426)
1 parent d55d256 commit 6f731f4

File tree

7 files changed

+230
-1
lines changed

7 files changed

+230
-1
lines changed

authors.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,9 @@ joecasson-openai:
176176
ericning-o:
177177
name: "Eric Ning"
178178
website: "https://github.com/ericning-o"
179-
avatar: "https://avatars.githubusercontent.com/u/182030612"
179+
avatar: "https://avatars.githubusercontent.com/u/182030612"
180+
181+
alwell-kevin:
182+
name: "Kevin Alwell"
183+
website: "https://github.com/alwell-kevin"
184+
avatar: "https://avatars.githubusercontent.com/u/26548363"
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
# GPT Action Library: GitHub
2+
3+
## Introduction
4+
5+
This page provides instructions for developers connecting a GPT Action to GitHub. Before proceeding, familiarize yourself with the following resources:
6+
- [Introduction to GPT Actions](https://platform.openai.com/docs/actions)
7+
- [GPT Actions Library](https://platform.openai.com/docs/actions/actions-library)
8+
- [Building a GPT Action from Scratch](https://platform.openai.com/docs/actions/getting-started)
9+
10+
This GPT Action helps developers evaluate the quality and security of a GitHub Pull Request diff. It provides feedback and suggestions for each domain, allowing developers to modify or accept the feedback before automatically submitting it as a comment on the Pull Request.
11+
12+
## Value & Example Business Use Cases
13+
14+
### **Value**:
15+
Users can leverage ChatGPT's natural language capabilities to assist with GitHub Pull Request reviews.
16+
17+
- **For developers**: Analyze code changes and perform high-quality reviews with instant feedback on proposed modifications.
18+
- **For organizations**: Ensure diffs adhere to best practices and coding standards, or automatically propose refactored alternatives (additional API requests may be required to define best practices).
19+
- **Overall**: Boost productivity and ensure higher-quality, more secure code with this AI-powered Code Review assistant.
20+
21+
### **Example Use Cases**:
22+
- A reviewer seeks feedback on the quality and security of a proposed code change.
23+
- An organization encourages adherence to best practices and standards automatically during code review.
24+
25+
## Demonstration Video:
26+
[![Watch the video](https://img.youtube.com/vi/bcjybCh-x-Q/0.jpg)](https://www.youtube.com/watch?v=bcjybCh-x-Q)
27+
28+
## Application Information
29+
30+
### **Key Links**
31+
Before starting, explore these resources:
32+
- [GitHub](https://github.com)
33+
- [GitHub API Documentation](https://docs.github.com/en/rest/pulls?apiVersion=2022-11-28)
34+
35+
### **Prerequisites**
36+
Ensure you have a repository with an open pull request.
37+
38+
## Application Setup
39+
40+
### **Select a Pull Request**
41+
1. Navigate to a repository, e.g., [example PR](https://github.com/microsoft/vscode/pull/229241).
42+
- Note the owner (e.g., "microsoft"), repository name (e.g., "vscode"), and PR number (e.g., "229241").
43+
- If the repository owner is an SSO organization, your token may need [approval](https://docs.github.com/en/organizations/managing-programmatic-access-to-your-organization/managing-requests-for-personal-access-tokens-in-your-organization#managing-fine-grained-personal-access-token-requests).
44+
2. Review [how to perform a high-quality code review](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/getting-started/best-practices-for-pull-requests).
45+
46+
### **Generate a "Fine Grained" GitHub Personal Access Token**
47+
1. Log in to GitHub and go to **Settings**.
48+
2. Navigate to **Developer settings** > **Fine Grained Personal access tokens**.
49+
3. Click **Generate new token**, name it, set an expiration date, and select the necessary scopes (e.g., `read:content`, `read&write:pull_requests`).
50+
4. Copy and securely store the token.
51+
52+
## ChatGPT Steps
53+
54+
### **Custom GPT Instructions**
55+
56+
Once you've created a Custom GPT, copy the following into the Instructions panel:
57+
58+
```
59+
# **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.
60+
61+
# **Instructions:**
62+
63+
## Scenarios
64+
### - When the user asks for information about a specific pull request, follow this 5 step process:
65+
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).
66+
2. Retrieve the Pull Request information from GitHub using the getPullRequestDiff API call, owner, repository and the pull request number provided.
67+
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).
68+
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.
69+
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.
70+
```
71+
72+
### OpenAPI Schema
73+
74+
Once you've created a Custom GPT, copy the text below in the Actions panel. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.
75+
76+
Below is an example of what connecting to GitHub to GET the Pull Request Diff and POST the Feedback to the Pull Request might look like.
77+
78+
```javascript
79+
openapi: 3.1.0
80+
info:
81+
title: GitHub Pull Request API
82+
description: Retrieve the diff of a pull request and post comments back to it.
83+
version: 1.0.0
84+
servers:
85+
- url: https://api.github.com
86+
description: GitHub API
87+
paths:
88+
/repos/{owner}/{repo}/pulls/{pull_number}:
89+
get:
90+
operationId: getPullRequestDiff
91+
summary: Get the diff of a pull request.
92+
parameters:
93+
- name: owner
94+
in: path
95+
required: true
96+
schema:
97+
type: string
98+
description: Owner of the repository.
99+
- name: repo
100+
in: path
101+
required: true
102+
schema:
103+
type: string
104+
description: Name of the repository.
105+
- name: pull_number
106+
in: path
107+
required: true
108+
schema:
109+
type: integer
110+
description: The number of the pull request.
111+
- name: Accept
112+
in: header
113+
required: true
114+
schema:
115+
type: string
116+
enum:
117+
- application/vnd.github.v3.diff
118+
description: Media type for the diff format.
119+
responses:
120+
"200":
121+
description: Successfully retrieved the pull request diff.
122+
content:
123+
text/plain:
124+
schema:
125+
type: string
126+
"404":
127+
description: Pull request not found.
128+
/repos/{owner}/{repo}/issues/{issue_number}/comments:
129+
post:
130+
operationId: postPullRequestComment
131+
summary: Post a comment to the pull request.
132+
parameters:
133+
- name: owner
134+
in: path
135+
required: true
136+
schema:
137+
type: string
138+
description: Owner of the repository.
139+
- name: repo
140+
in: path
141+
required: true
142+
schema:
143+
type: string
144+
description: Name of the repository.
145+
- name: issue_number
146+
in: path
147+
required: true
148+
schema:
149+
type: integer
150+
description: The issue or pull request number.
151+
requestBody:
152+
required: true
153+
content:
154+
application/json:
155+
schema:
156+
type: object
157+
properties:
158+
body:
159+
type: string
160+
description: The content of the comment.
161+
responses:
162+
"201":
163+
description: Successfully created a comment.
164+
content:
165+
application/json:
166+
schema:
167+
type: object
168+
properties:
169+
id:
170+
type: integer
171+
body:
172+
type: string
173+
user:
174+
type: object
175+
properties:
176+
login:
177+
type: string
178+
id:
179+
type: integer
180+
"404":
181+
description: Pull request not found.
182+
```
183+
184+
## Authentication Instructions
185+
186+
Below are instructions on setting up authentication with this 3rd party application. Have questions? Check out [Getting Started Example](https://platform.openai.com/docs/actions/getting-started) to see how this step works in more detail.
187+
188+
### In ChatGPT (refer to Step 2 in the Getting Started Example)
189+
190+
In ChatGPT, click on "Authentication" and choose **"Bearer"**. Enter in the information below. Ensure your token has the permissions described in Application setup, above.
191+
192+
- Authentication Type: API Key
193+
- Auth Type: Bearer
194+
- API Key
195+
<personal_access_token>
196+
197+
### Test the GPT
198+
199+
You are now ready to test out the GPT. You can enter a simple prompt like "Can you review my pull request? owner: <org_name>, repo: <repo_name>, pull request number: <PR_Number>" and expect to see the following:
200+
201+
![landing_page.png](../../../../images/landing_page.png)
202+
203+
1. A summary of changes in the referenced pull request(PR).
204+
205+
![First Interaction](../../../images/first_interaction.png)
206+
207+
2. Quality and Security feedback and suggestions to incorporate in the next iteration of the PR.
208+
209+
![First Feedback](../../../images/first_feedback.png)
210+
211+
3. An option to iterate on the feedback or accept it and have the GPT post it directly to the PR as a comment from you.
212+
213+
![First Interaction](../../../images/final_result.png)
214+
215+
*Are there integrations that you’d like us to prioritize? Are there errors in our integrations? File a PR or issue in our github, and we’ll take a look.*

images/final_result.png

286 KB
Loading

images/first_feedback.png

130 KB
Loading

images/first_interaction.png

232 KB
Loading

images/landing_page.png

114 KB
Loading

registry.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,15 @@
13631363
- chatgpt
13641364
- chatgpt-communication
13651365

1366+
- title: GPT Actions library - GitHub
1367+
path: examples/chatgpt/gpt_actions_library/gpt_action_github.md
1368+
date: 2024-09-25
1369+
authors:
1370+
- alwell-kevin
1371+
tags:
1372+
- gpt-actions-library
1373+
- chatgpt
1374+
13661375
- title: GPT Actions library - Sharepoint (Return Docs)
13671376
path: examples/chatgpt/gpt_actions_library/gpt_action_sharepoint_doc.ipynb
13681377
date: 2024-05-24

0 commit comments

Comments
 (0)