Intro
Sorry that I posted this article before finishing by mistake.🙇
I wrote the rest of the article and posted again and deleted the unfinished article.
↓PR-Agent
is an OSS that can make AI code review automatically.
https://qodo-merge-docs.qodo.ai/
The merit of PR-Agent is that it is an OSS, so you can use it for free!🤑
Other AI code review services like PR-Agent are not so reasonable.
For example, CodeRabbit costs $15/month, GitHub Copilot costs $10/month, at least.💸
I always check popularity and if there is constant update or not when using OSS, and both seemed OK for PR-Agent.
So, let's take a quick look at PR-Agent together.🧐
You can use PR-Agent on repository such as GitHub, GitLab and others.
PR-Agent usually runs automatically when you make a pull request.
But you can edit and make it run when pushing to repository too.
Also, you can run it with slash commands
in pull request comment.
PR-Agent's 3 main functions
PR-Agent has 3 main functions.
-
describe
: explains the outline of the pull request. -
review
: reviews the pull request. -
improve
: suggests better code for the pull request.
I wrote code with an obvious error, run PR-Agent, and attached screenshots as a sample.
↓improve
How to use PR-Agent by GitHub Actions
First, I tried PR-Agent using GitHub Actions
.
https://qodo-merge-docs.qodo.ai/installation/github/#run-as-a-github-action
GitHub Actions is a way to automate GitHub, and you need to write the automation flow in a yml
file.
Here is the flow to use PR-Agent by GitHub action.
- Copy the template from the PR-Agent official document.
- Revise the setting of PR-Agent in the
yml
as you like. - Set
GITHUB_TOKEN
andAI API key
on GitHub.
Settings > Secrets and variables > Actions > New repository secret > Add secret
And then you are ready for PR-Agent.
It is quick and easy to use.😀
I kept most of PR-Agent settings as default, but changed some.
1️⃣ Changed the AI model to Gemini
because I wanted to be Uncle free-to-play.🤑
Be aware that data will be studied by Google when using Gemini for free.
If you are handling secret data, choose paid Gemini or other options.
2️⃣ Changed the language from English to Japanese, since I am Japanese.🥷
3️⃣ Set PR-Agent to trigger on git push
.🔫
It did not run when push by default.
I added synchronize
at two parts of the yml for it.
↓Sample of .github\workflows\pr_agent.yml
.
name: PR Agent (Gemini)
on:
pull_request:
types: [opened, reopened, ready_for_review, synchronize]
issue_comment:
jobs:
pr_agent_job:
if: ${{ github.event.sender.type != 'Bot' }}
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
contents: write
steps:
- name: PR Agent action step
uses: qodo-ai/pr-agent@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
config.model: "gemini/gemini-2.5-flash"
config.fallback_models: '["gemini/gemini-2.5-flash"]'
GOOGLE_AI_STUDIO.GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
config.response_language: "ja-JP"
github_action_config.auto_review: "true"
github_action_config.auto_describe: "true"
github_action_config.auto_improve: "true"
github_action_config.pr_actions: '["opened", "reopened", "ready_for_review", "synchronize"]'
How to use PR-Agent by GitLab Pipeline
I also use GitLab at work, so next I tried the same setting on GitLab Pipeline
.
https://qodo-merge-docs.qodo.ai/installation/gitlab/#run-as-a-gitlab-pipeline
The GitLab setting is the same as GitHub, and you need to set yml
, GITLAB_PERSONAL_ACCESS_TOKEN
and AI API key
.
Settings -> CI/CD -> Variables
↓Sample of .gitlab-ci.yml
.
stages:
- pr_agent
pr_agent_job:
stage: pr_agent
image:
name: codiumai/pr-agent:latest
entrypoint: [""]
script:
- cd /app
- export MR_URL="$CI_MERGE_REQUEST_PROJECT_URL/merge_requests/$CI_MERGE_REQUEST_IID"
- echo "MR_URL=$MR_URL"
- export gitlab__url=$CI_SERVER_PROTOCOL://$CI_SERVER_FQDN
- export gitlab__PERSONAL_ACCESS_TOKEN=$GITLAB_PERSONAL_ACCESS_TOKEN
- export config__git_provider="gitlab"
- export config__model="gemini/gemini-2.5-flash"
- export GOOGLE_AI_STUDIO__GEMINI_API_KEY=$GEMINI_API_KEY
- export config__response_language="ja-JP"
- python -m pr_agent.cli --pr_url="$MR_URL" describe
- python -m pr_agent.cli --pr_url="$MR_URL" review
- python -m pr_agent.cli --pr_url="$MR_URL" improve
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
At GitLab, PR-Agent worked when git push
without extra setting.
How to custom PR-Agent as you like
When using PR-Agent, you might come to a situation that PR-Agent would be more useful if it can work as you prefer.
In that case, you can use configuration file (.pr_agent.toml)
.
When you want to create a custom prompt for AI, you can use extra instructions
.
Here is the code of extra_instructions for PR-Agent 3 main functions.
[pr_description] # /describe #
extra_instructions = ""
[pr_reviewer] # /review #
extra_instructions = ""
[pr_code_suggestions] # /improve #
extra_instructions = ""
There are many other convenient settings in the configuration file, so check the official document for more information.
https://github.com/qodo-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml/
Outro
PR-Agent is a free and easy way to do AI code review.
How about trying PR-Agent?
I hope you learned something from this post.😊
Thank you for reading.
Happy AI coding!🤖
Top comments (2)
I already use gemini review, its free and setup in a couple of clicks.
I didn't know that.
Gemini review also seems good.🔍