/github-pr-review-llm

Perform automatic code reviews for GitHub pull requests (PR). The review is triggered when a PR is created and is triggered again for every subsequent commit in the PR. It will review each changed file in the PR.

Primary LanguageRust

Agent to review code in Github PRs

flows.network Discord flows.network Twitter Create a flow

Deploy this function on flows.network, and you will get an AI agent to review changed source code files in GitHub Pull Requests. It helps busy open source contributors understand and make decisions on PRs faster! Here are some examples. Notice how the code review bot provides code snippets to show you how to improve the code!

We recommend you to use a GaiaNet node running an open source coding LLM as the backend to perform PR reviews and summarizations. You can use a community node or run a node on your own computer!

This bot reviews changed files in the PR. Alternatively, you can use this bot to summarize commits in the PR.

How it works

This flow function is triggered when a new PR is raised in the designated GitHub repo. The flow function collects the changed files in the PR, and asks ChatGPT/4 to review and summarize it. The result is then posted back to the PR as a comment. The flow functions are written in Rust and run in hosted WasmEdge Runtimes on flows.network.

  • The code review comment is updated automatically every time a new commit is pushed to this PR.
  • A new code review could be triggered when someone says a magic trigger phrase in the PR's comments section. The default trigger phrase is "flows review".

Deploy your own code review bot in 3 simple steps

  1. Create a bot from your own GitHub repo
  2. Configure the bot to review PRs
  3. Connect to GitHub for access to the target repo

0 Prerequisites

You will also need to sign into flows.network from your GitHub account. It is free.

1 Create a bot from your own GitHub repo

Just fork this repo to your own GitHub account.

Then, from flows.network, you can Create a Flow and select your forked repo. It will create a flow function based on the code in your forked repo.

Click on the Advanced button to see configuration options for the flow function.

2 Configure the bot to review PRs

Next, you will tell the bot which GitHub repo it needs to monitor for upcoming PRs to review.

  • github_owner: GitHub org for the repo you want to review PRs
  • github_repo : GitHub repo you want to review PRs
  • trigger_phrase : The magic words to write in a PR comment to summon the bot. It defaults to "flows review".

Let's see an example. You would like to deploy the bot to review code in PRs on WasmEdge/wasmedge_hyper_demo repo. Here github_owner = WasmEdge and github_repo = wasmedge_hyper_demo.

And the LLM API service you want to use to review the PRs.

  • llm_api_endpoint : The OpenAI compatible API service endpoint for the LLM to conduct code reviews. We recommend the Codetral-0.1-22B GaiaNet node: https://codestral-01-22b.us.gaianet.network/v1
  • llm_model_name : The model name required by the API service. We recommend the following model name for the above GaiaNet node: Codestral-22B-v0.1-hf-Q5_K_M
  • llm_ctx_size : The context window size of the selected model. The Codestral 0.1 model has a 16k context window, which is 16384.
  • llm_api_key : Optional: The API key if required by the LLM service provider. It is not required for the GaiaNet node.

Click on the Build button.

3 Connect to GitHub for access to the target repo

Finally, the GitHub repo will need to give you access so that the flow function can access and review its PRs! In this next screen, you will connect to GitHub and authorize access.

Click on the Connect or + Add new authentication button to give the function access to the GitHub repo. You'll be redirected to a new page where you must grant flows.network permission to the repo.

image

Close the tab and go back to the flow.network page once you are done. Click on Deploy.

Wait for the magic!

This is it! You are now on the flow details page waiting for the flow function to build. As soon as the flow's status became running, the bot is ready to give code reviews! The bot is summoned by every new PR, every new commit, as well as magic words (i.e., trigger_phrase) in PR comments.

image

FAQ

Customize the bot

The bot's source code is available in the GitHub repo you cloned from the template. Feel free to make changes to the source code (e.g., model, context length, API key and prompts) to fit your own needs. If you need help, ask in Discord!

Use the bot on multiple repos

You can mannually create a new flow and import the source code repo for the bot (i.e., the repo you cloned from the template). Then, you can use the flow config to specify the github_owner and github_repo to point to the target repo you need to deploy the bot on. Deploy and authorize access to that target repo.

You can repeat this for all target repos you would like to deploy this bot on.

You could have a single flow function repo deployed as the source code for multiple bots. When you update the source code in the repo, and push it to GitHub, it will change the behavior of all the bots.

Change the magic phrase

Go to the "Settings" tab of the running flow function for the bot, you can update the trigger_phrase config. The value of this config is the magic phrase the user will say to trigger a review from a PR comment.

Credits

This flow function is originally created by Jay Chen, and jinser made significant contributions to optimize the event triggers from GitHub.

GPT Nitro for Github PR - A ChatGPT-based reviewer for your GitHub pull requests | Product Hunt