Skip to content

Commit b7b68aa

Browse files
Initial commit
0 parents  commit b7b68aa

24 files changed

+81210
-0
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = tab
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.yml]
12+
indent_style = space

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
lib/
2+
dist/
3+
node_modules/
4+
coverage/

.gitignore

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Dependency directory
2+
node_modules
3+
4+
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
lerna-debug.log*
12+
13+
# Diagnostic reports (https://nodejs.org/api/report.html)
14+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
15+
16+
# Runtime data
17+
pids
18+
*.pid
19+
*.seed
20+
*.pid.lock
21+
22+
# Directory for instrumented libs generated by jscoverage/JSCover
23+
lib-cov
24+
25+
# Coverage directory used by tools like istanbul
26+
coverage
27+
*.lcov
28+
29+
# nyc test coverage
30+
.nyc_output
31+
32+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
33+
.grunt
34+
35+
# Bower dependency directory (https://bower.io/)
36+
bower_components
37+
38+
# node-waf configuration
39+
.lock-wscript
40+
41+
# Compiled binary addons (https://nodejs.org/api/addons.html)
42+
build/Release
43+
44+
# Dependency directories
45+
jspm_packages/
46+
47+
# TypeScript v1 declaration files
48+
typings/
49+
50+
# TypeScript cache
51+
*.tsbuildinfo
52+
53+
# Optional npm cache directory
54+
.npm
55+
56+
# Optional eslint cache
57+
.eslintcache
58+
59+
# Optional REPL history
60+
.node_repl_history
61+
62+
# Output of 'npm pack'
63+
*.tgz
64+
65+
# Yarn Integrity file
66+
.yarn-integrity
67+
68+
# dotenv environment variables file
69+
.env
70+
.env.test
71+
72+
# parcel-bundler cache (https://parceljs.org/)
73+
.cache
74+
75+
# next.js build output
76+
.next
77+
78+
# nuxt.js build output
79+
.nuxt
80+
81+
# vuepress build output
82+
.vuepress/dist
83+
84+
# Serverless directories
85+
.serverless/
86+
87+
# FuseBox cache
88+
.fusebox/
89+
90+
# DynamoDB Local files
91+
.dynamodb/
92+
93+
# OS metadata
94+
.DS_Store
95+
Thumbs.db
96+
97+
# Ignore built ts files
98+
__tests__/runner/*
99+
100+
# IDE files
101+
.idea
102+
.vscode
103+
*.code-workspace

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/
2+
node_modules/
3+
coverage/

.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"printWidth": 140,
3+
"singleQuote": true,
4+
"semi": true,
5+
"useTabs": true
6+
}

.prettierrc.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"semi": false,
6+
"singleQuote": true,
7+
"quoteProps": "as-needed",
8+
"jsxSingleQuote": false,
9+
"trailingComma": "none",
10+
"bracketSpacing": true,
11+
"bracketSameLine": true,
12+
"arrowParens": "avoid",
13+
"proseWrap": "always",
14+
"htmlWhitespaceSensitivity": "css",
15+
"endOfLine": "lf"
16+
}

README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# CodeGPT PR Assistant
2+
3+
## Description
4+
5+
The CodeGPT PR Assistant is a GitHub Action designed to review pull requests and provide code suggestions, helping developers improve their code quality and consistency. It integrates with GitHub Actions to automatically analyze and comment on new pull requests and commits.
6+
7+
## Features
8+
9+
- Review pull request changes automatically.
10+
- Provide feedback and code suggestions.
11+
12+
## Required ENV variables
13+
14+
- `OPENAI_API_KEY`: The OpenAI API key needed to interact with language models. This var is **required**.
15+
- `GITHUB_TOKEN`: The GitHub API key needed to interact with GitHub's API. Usually available on your env. This var is **required**.
16+
17+
## Inputs
18+
19+
- `OPENAI_ASSISTANT_ID`: The ID of the OpenAI assistant being used. This input is **required**.
20+
21+
## Outputs
22+
23+
- `response`: The output message from processing the event, which includes feedback or code suggestions based on the pull request content.
24+
25+
## Usage
26+
27+
To use this action in your GitHub workflows, add the following step:
28+
29+
```yaml
30+
name: Ask CodeGPT for feedback
31+
32+
on:
33+
pull_request:
34+
types: [opened]
35+
issue_comment:
36+
types: [created]
37+
38+
jobs:
39+
process-events:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Run CodeGPT
43+
if: github.event_name == 'pull_request' || (github.event_name == 'issue_comment' && contains(github.event.comment.body, 'CodeGPT') && !contains(github.event.comment.body,'The following is a message from CodeGPT:'))
44+
uses: isat/codegpt@v1.0.0
45+
with:
46+
OPENAI_ASSISTANT_ID: 'YOUR_ASSISTANT_ID_GOES_HERE'
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
50+
```
51+
52+
Don't forget to enable `Read and Write` permissions on your Repo/Org's `Workflow permissions` if you haven't already.
53+
54+
Each repo can also have a `CODEGPT.md` file, which will be passed as context to the Bot.
55+
56+
These are the recommended base instructions for your assistant.
57+
58+
```
59+
You will be resposible for reviewing pull requests. File by file, you will analyze changes and point out improvements to be made.
60+
61+
In terms of Evaluation, we consider that NeedsImprovement is the first failing evaluation. Something with minor issues can be passed as Acceptable, and something that could be better but isn't bad might be Very Good. Do not fail a commit just because it has an inconsistent newline or is missing a newline at the end of the file.
62+
63+
You are not to point out whitespace errors at all, like lack of newlines at the end of files, too many newlines, inconsistent indentation or any other sort of whitespace error. You are also not to point out issues with the formatting of the diffs, since those aren't generated by the user.
64+
65+
When I ask you something, I will specify the interface you shall use in your JSON response.
66+
```
67+
68+
These can be adjusted to give the assistant a personality, or to pay more attention to a specific value. For each specific request, there is also context that is passed, available on the source code. You can fork this repo to change this specific context.
69+
70+
## How it works
71+
72+
This GitHub Action uses [Open AI's Assistants](https://platform.openai.com/docs/assistants/overview) behind the scenes, which are, at the time of writing this, a beta feature. Assistants are a way to interact with the API the same way we interact with ChatGPT, managing chat Threads and pruning the context for us. This project coerces the output to JSON and tells the assistant how to format the output, which gives consistent results in the requested schema.
73+
74+
To better manage the context, the Action splits the PR into multiple parts:
75+
76+
![image](https://github.com/isat/codegpt/assets/26225974/cf9ec4fc-f804-41e5-b644-8215728d107b)
77+
78+
Each of these parts is analyzed in a different thread, concurrently. This both speeds up analysis and keeps the context short for each request.
79+
80+
To make sure we get relevant feedback, we coerce the assistant to give feedback in a specific schema, which can be visualized globally below:
81+
82+
![image](https://github.com/isat/codegpt/assets/26225974/39627f75-8f87-49a9-859b-df6ab86a188e)
83+
84+
The global flow is summarized below:
85+
86+
![image](https://github.com/isat/codegpt/assets/26225974/66afebec-a485-4321-8973-a2093ddeb9cf)

action.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: 'CodeGPT PR Assistant'
2+
description: 'A helpful assistant that reviews pull requests and provides code suggestions.'
3+
author: 'PedroCavalheiro@isat'
4+
inputs:
5+
OPENAI_ASSISTANT_ID:
6+
description: 'ID of the OpenAI assistant.'
7+
required: true
8+
outputs:
9+
response:
10+
description: 'The output message from processing the event.'
11+
runs:
12+
using: node20
13+
main: dist/index.js
14+
branding:
15+
icon: 'code'
16+
color: 'blue'

0 commit comments

Comments
 (0)