Code Monkey home page Code Monkey logo

mattzcarey / code-review-gpt Goto Github PK

View Code? Open in Web Editor NEW
1.4K 24.0 137.0 4.04 MB

Code review powered by LLMs (OpenAI GPT4, Sonnet 3.5) & Embeddings โšก๏ธ Improve code quality and catch bugs before you break production ๐Ÿš€ Lives in your Github/GitLab/Azure DevOps CI

Home Page: https://oriontools.ai

License: MIT License

JavaScript 5.23% TypeScript 92.83% Shell 1.94%
openai gpt4 langchain langchain-typescript gpt-3 huggingface opensource chatgpt code-analysis code-quality

code-review-gpt's Introduction

Code Review GPT

NPM Contributors Pulse License Twitter Slack

We give engineers their weekends back

Code Review GPT uses Large Language Models to review code in your CI/CD pipeline. It helps streamline the code review process by providing feedback on code that may have issues or areas for improvement.

It should pick up on common issues such as:

  • Exposed secrets
  • Slow or inefficient code
  • Unreadable code

It can also be run locally in your command line to review staged files.

Code Review GPT is in alpha and should be used for fun only. It may provide useful feedback but please check any suggestions thoroughly.

Demo

code-review-gpt-3.mp4

Package Usage

See the package documentation for more information.

Action Usage

See the action documentation for more information.

Getting Started ๐Ÿ’ซ

  1. Clone the repository:

    git clone https://github.com/mattzcarey/code-review-gpt.git
    cd code-review-gpt && cd packages/code-review-gpt
  2. Install dependencies:

    npm install
  3. Set up the API key:

    • Rename the .env.example file to .env.
    • Open the .env file and replace YOUR_API_KEY with your actual OPENAI API key.

When used globally you should run export OPENAI_API_KEY=YOUR_API_KEY (or similar for your operating system) in your terminal to set the API key.

  1. Run the application:

    npm start

See the package.json file for all the npm commands you can run.

  1. Make a PR ๐ŸŽ‰

We use release-please on this project. If you want to create a new release from your PR, please make sure your PR title follows the Conventional Commits format. The release-please bot will automatically create a new release for you when your PR is merged.

  • fix: which represents bug fixes, and correlates to a patch version.
  • feat: which represents a new feature, and correlates to a SemVer minor.
  • feat!:, or fix!:, refactor!:, etc., which represent a breaking change (indicated by the !) and will result in a major version.

Contributors ๐Ÿ™

Thanks to our wonderful contributors!

Roadmap (see projects tab) ๐ŸŒ

The roadmap shifts the focus to a Github app which can be installed on any repo. This will allow for a more seamless UX and better features including a chatbot to discuss the PR and make suggestions.

The code-review-gpt package will continue to be maintained and improved based on the feedback from the Github app.

Sponsors โค๏ธ

quivr logo aleios logo

Star History โญ๏ธ

Star History Chart

code-review-gpt's People

Contributors

aiden-walton avatar april-bates-dev avatar coldfrey avatar danigo99 avatar danleyb2 avatar dependabot[bot] avatar fabienzucchet avatar feelgom avatar github-actions[bot] avatar goffity avatar gowoons avatar gurnkaur avatar icopyx avatar jodosha avatar lintaonz avatar lizacullis avatar mattzcarey avatar muffe avatar paulwoitaschek avatar pointhex avatar sebrathezebra avatar zixiong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

code-review-gpt's Issues

[Hugging Face LLM]

We want people to be able to deploy their own inference endpoints and give us an API key.

We also want to be able to run deployed full-time endpoints and perform fine-tuning on react native eg.

Then users will just pay us.

[Demo BE] AABE Dev I can see a demo review of code using Postman

Description:
Want to test backend lambda + API gateway functionality dependent of #75

Validation:
Video showing call using postman and returning a review

tech steps:
add route to the apigateway. This route will be called /demoReview and will be a POST.
route needs no authentication.
this route needs rate limiting turned on in API gateway!!!!
add lambda integration to the demoReview lambda.

Prompt testing tool

'code-review-gpt test'

Should test the prompt end to end against a pre defined set of criteria.

Add it to ci

[User Info page BE] AAUser I can update my api key

Description: need to be able to use users API keys for review. This ticket involves creating the lambda to add the API key to the db

Validation:
trigger lambda in console with test API key and see it in dynamo.

Tech steps:
create a new empty lambda function updateUser in core service.
follow the instructions on the site https://www.dynamodbtoolbox.com/docs/introduction/quick-start
create an entity
User:
PK: USERID#.... string
SK: ROOT string
apiKey: .... string

in the lambda we are going to take the APIkey and the userid from the request and add it to dynamo.

[Cloudfront and WAF]

Problem we're trying to solve is clear

Secure the endpoints against DDOS attacks and DoW attacks

Success Measures

  • protected against DDOS attacks to the best of our ability

Scope of feature

  • Cloudfront
  • Waf rules

Edge Cases

Perfect user stories

โŒ

Risks/Dependencies identified

Dependent on endpoints implemented

Technical Strategy is known

โœ…

Uncertainties are known

not sure on exact Waf rules or pricing model

Dependencies are unblocked

Testing strategy is known

  • artillery?

[Demo FE]

Need a frontend with a big box which allows you to write in code.

Review button.

Problem we're trying to solve is clear

Allow people to use the tool with installing or downloading anything

Success Measures

  • A website at the oriontools/demo url

Scope of feature

  • A box that is pasted in text and get code reviewed

Edge Cases

โœ…

Perfect user stories

โŒ

Risks/Dependencies identified

โœ…

Technical Strategy is known

  • Make a front end it NextJS

Uncertainties are known

  • Specific styling, no UI to work with

Dependencies are unblocked

โœ…

Testing strategy is known

  • Unit test front end
  • NO END TO END TESTS

[Logging]

When in debug mode, print the prompt and responses of the model when a call is made

[Demo BE]

The idea here is that we want a hosted and free demo accessible on the public internet for people to play with.

Beause we will be paying for this the API gateway endpoint needs rate limiting to prevent DoW attacks and also the lambda needs request limiting to prevent overuse of GPT4 $$$

Problem we're trying to solve is clear

Allow people to use the tool with installing or downloading anything

Success Measures

  • A backend endpoint which can be hit with postman

Scope of feature

  • An endpoint that is hit with text and get code reviewed

Edge Cases

โœ…

Perfect user stories

โŒ

Risks/Dependencies identified

  • Have to add in rate limiting due to it being an open end point

Technical Strategy is known

  • Make a lambda which will handle the compute
  • Connect together with API Gateway
  • Add cloudfront
  • Add WAF rules

Uncertainties are known

  • Specific WAF rules

Dependencies are unblocked

โœ…

Testing strategy is known

  • Integration test the backend
  • NO END TO END TESTS

Landing page

Make a landing page on GitHub pages. Super minimal. Leave a space for a logo

Needs a link to the GitHub and the code to get started

'npm i code-review-gpt && npx code-review-gpt configure'

[Github App]

Problem we're trying to solve is clear

We want user to be able to add the github app to the repo.

Success Measures

Use can add github app to repo and it comment on their PR

Scope of feature

The GitHub app will receive webhooks to

  1. setup the repo
  2. on pr open and on commit

Edge Cases

Perfect user stories

โŒ

Risks/Dependencies identified

  • API gateway needs lambda auth to verify Github is sending request

Technical Strategy is known

โœ…

Uncertainties are known

โœ…

Dependencies are unblocked

โœ…

Testing strategy is known

  • integration test the endpoints

[Github App] AABEDev I can request a review from the review Lambda

Description:
We want to repackage the review functionality of our app into a lambda which will eventually be called by a Github API.
The npm package should still be functioning after this ticket!!!

Validation:
Test in the console and show a review is returned when you give it some code. Screenshot

Tech step:
in root/services -> create cdk app (core)
in functions/ create review lambda -> config (construct), index (handler)
stacks/ in the core stack -> call the review lambda construct
test in the console.
weird thing with tsconfig

[NPM Packaging] AAReviewLambda I do not contain any git commands

Tech steps

  • Create a git folder in src/common
  • Create functions for git commands (now in src/review/prompt/gitCommand.ts)
  • Create a function that uses the github env variables and returns a list of objects of type {fileName:string, fileContent:string, changedLines: string}
  • (Write tests for these functions ?)
  • In global index.ts, in case "review", call the git function first, and pass in the list of objects in the review function

[Github App] AAAPI Gateway I can auth requests coming from Github

Description:
Currently we have an open /postReview endpoint (dependent on #70 ) We need to validate requests to this endpoint to check they are actually coming from Github and importantly that the repo they are coming from is requested to authenticated user on our platform.

Validation:
Screenshot

Tech steps:

[Logging] AAUser I can see debug logs in Github actions

Debug log should show the comand used, flags, model, prompt, and response. This should be enabled by Github actions running in debug mode.

Use tslog to define a minLevel on the logger that is

  • 4 when running on the ci (only warn, error and fatal logs)
  • 3 when running locally (info, warn, error, and fatal)
  • 2 when running with debug (debug, info, warn, error, and fatal)

[Npm packaging]

We want to make sure that the npm package we release remains up to date.

[Auth BE] AABEDev I have a dynamodb table deployed to AWS

Description:
First ticket for backend saas. The idea is to have a deployed dynamodb table to AWS.

Validiation:
Screenshot of dynamo table in console.

Tech steps:
in services. cdk init --typescript core
in a resources folder add a dynamo table: PK: pk, SK:sk.
standard setup, check in a previous project. RemovalPolicy to be a function of the stage... billing mode to pay per request.
helper functions

Vector store

Store all changes in a local vector store using chroma db

[Project CI/Setup]

Description:

Working CI pipeline so we can be sure of our changes with automatic tests and automatic push to prod (npm/aws deploy).

Add templates for issues.

[Demo BE] AADemo Review Lambda I can review code

Description:
Make a demo review lambda which takes code and reviews it. Use apiKey and Langchain Smith env variables from parameter store.

This is different from the Github Review lambda

Validation:
screenshot testing the lambda in console.

Tech steps:
arguments: {
code: .....
}

return: {
reviewedCode: ...
riskLevel: ....
}

Functionality:

  1. get the openai apikey and langsmith API key from SSM, add to the env variables of lambda
  2. check the length of the code is not outside the context window.. If not return error.
  3. append the prompt to the code
  4. return a result to the frontend

[User Managment]

We need to have backend endpoints to get user details and updated user details.

On frontend we need an admin dashboard thing which allows a user to see the repo connected to the account and update the API key we have on file.

[User Info page] AABEDev I update my user API key in Postman

Description:
We want users to be able to update their openai API key that we store on file as part of their user in dynamo.

Validation:
Screenshot in postman sending post request to the updateUser endpoint with field apiKey. Recieve a 200 response.

Tech steps:
create API stack
create API gateway
add a post method to the updateUser endpoint
add a lambda integration to trigger the lambda.

AADev I have a flag to enable line-by-line commenting

  • in args add an option line-by-line commenting
  • in review/index.ts make a const isLinebyLine using the boolean from argv
  • in constants.ts add to the main prompt a fileLine attribute to the returned json
  • log that and test locally
  • in comment on PR add the line by line commenting behind the isLinebyLine command (see dans draft pr for info)

Output responses as valid json.

We are currently assuming that the model response is a valid markdown with the correct template. We should make sure that the response is valid and if not regenerate the response to prevent malformed result

Rank and pick feedbacks to return

Rank feedbacks and only return first 5 instead (or less) of spamming with comments

  • Create a prompt to rank the feedbacks
  • Function to call the model and rank the feedbacks
  • Filtering logic to limit to the first 5 if they exist

[Bug] Occasional Undetermined String Error in callModelJSON()

ERROR Error in callModelJSON
SyntaxError Unterminated string in JSON at position 7947
error stack:
โ€ข

โ€ข AIModel.ts maxTry
/src/common/model/AIModel.ts:35
โ€ข task_queues processTicksAndRejections
internal/process/task_queues:95

Image

[User info page]

Problem we're trying to solve is clear

User needs to be able to manage their installed repos (add new repo, remove repo, change API key)
User needs to be able to see how many requests have occurred for each repo and any errors.

Success Measures

  • page accessible only to logged in users with the above functionality

Scope of feature

  • page deployed to oriontools.ai/user

Edge Cases

Perfect user stories

โŒ

Risks/Dependencies identified

  • no UI design

Technical Strategy is known

โœ…

Uncertainties are known

โœ…

Dependencies are unblocked

โœ…

Testing strategy is known

  • integration test the endpoints

[Landing Page FE]

Page to direct users to.

This should contain a logo, title, and installation instructions.

Also contain contact info to aleios and the repo

Tech stack nextjs app with sst hosting.

Problem we're trying to solve is clear

Creating a landing page which has installations instructions, an about the tool and a demo video, and a call action to try demo

Success Measures

  • a landing page deployed to oriontools.ai

Scope of feature

  • a pretty page with the info above shown. link to the demo and the repo

Edge Cases

Perfect user stories

โŒ

Risks/Dependencies identified

  • no UI design

Technical Strategy is known

โœ…

Uncertainties are known

โœ…

Dependencies are unblocked

โœ…

Testing strategy is known

  • no testing needed for a static page

[Auth BE]

Auth service to allow users to login to the platform online.

BE:

Problem we're trying to solve is clear

Auth service to allow users to login to the platform online.

Success Measures

  • be able to sign up, login, and logout via postman

Scope of feature

  • auth
  • database to store auth details

Edge Cases

Perfect user stories

โŒ

Risks/Dependencies identified

  • never used Next auth personally but used internally before

Technical Strategy is known

โœ…

Uncertainties are known

โœ…

Dependencies are unblocked

โœ…

Testing strategy is known

  • integration test the endpoints

[Github App] AAGithub event I can hit a review API.

Description:
We need a webhook url to supply to the github app in github. This URL should be apigateway /postReview and forward on the request to the review Lambda.

Validation:
install the app in an example repo. Make a PR and see that the review lambda is triggered (going into it's own ticket)

  • Screenshot of postman 200 response

Tech steps:

  • create API gateway in API stack
  • make post method postReview
  • lambda integration to the review lambda.
  • deploy and and get the URL.
  • test in postman
  • then give URL to matt to add to github app.

[Payments Service]

For v3 we want to support people just paying for us directly. We handle the AI API setup.

Use 3rd party with Stripe to handle the payment.

Only similar comments are displayed

We currently ask for GPT to select the most important comments according to the model. The issue with that is that if we have several files, we often end up with the same comment several time

Possible feature: specify commit SHAs for review in local use

When using this tool locally, it would be nice to be able to specify the commit SHAs to be reviewed instead of only working on staged files. I've very briefly looked at some of the source code and I think the least effort way to do this would be use most of the current CI logic but without involving github and the github token. Does this seem viable?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.