mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-20 04:20:39 +08:00
Compare commits
207 Commits
mrT23-patc
...
main
Author | SHA1 | Date | |
---|---|---|---|
65e71cb2ee | |||
9773afe155 | |||
0a8a263809 | |||
597f553dd5 | |||
4b6fcfe60e | |||
7cc4206b70 | |||
8906a81a2e | |||
6179eeca58 | |||
e8c73e7baa | |||
754d47f187 | |||
bec70dc96a | |||
fd32c83c29 | |||
7efeeb1de8 | |||
d7d4b7de89 | |||
2a37225574 | |||
e87fdd0ab5 | |||
c0d7fd8c36 | |||
5933280417 | |||
8e0c5c8784 | |||
0e9cf274ef | |||
3aae48f09c | |||
c4dd07b3b8 | |||
8c7680d85d | |||
11fb6ccc7e | |||
3aaa727e05 | |||
6108f96bff | |||
5a00897cbe | |||
e12b27879c | |||
fac2141df3 | |||
1dbfd27d8e | |||
eaeee97535 | |||
71bbc52a99 | |||
4a8e9b79e8 | |||
efdb0f5744 | |||
28750c70e0 | |||
583ed10dca | |||
07d71f2d25 | |||
447a384aee | |||
d9eb0367cf | |||
85484899c3 | |||
00b5815785 | |||
9becad2eaf | |||
74df3f8bd5 | |||
4ab97d8969 | |||
6057812a20 | |||
598e2c731b | |||
0742d8052f | |||
1713cded21 | |||
e7268dd314 | |||
50c2578cfd | |||
5a56d11e16 | |||
31e25a5965 | |||
85e1e2d4ee | |||
2d8bee0d6d | |||
e0d7083768 | |||
dbf96ff749 | |||
5f9eee2d12 | |||
d4c5ab7bf0 | |||
5ae6d71c37 | |||
d30d077939 | |||
aa18d532cf | |||
92d36f6791 | |||
5e82d0a316 | |||
b7b198947c | |||
fb69313d87 | |||
017db5b63c | |||
3f632835c5 | |||
e2d71acb9d | |||
8127d52ab3 | |||
6a55bbcd23 | |||
12af211c13 | |||
34594e5436 | |||
17a90c536f | |||
ef2e69dbf3 | |||
38dc9a8fe5 | |||
c3f8ef939c | |||
34cc434459 | |||
a3d52f9cc7 | |||
f56728fbca | |||
19ddf1b2e4 | |||
23ce79589c | |||
8cd82b5dbf | |||
dba6846a04 | |||
317eb65cc2 | |||
9817602ab5 | |||
8a7b37ab4c | |||
3b071ccb4e | |||
822a253eb5 | |||
aeb1bd8dbc | |||
df8290a290 | |||
9e20373cb0 | |||
6dc38e5bca | |||
f7efa2c7c7 | |||
d77d2f86da | |||
2276caba39 | |||
12d3d6cc0b | |||
630712e24c | |||
e1a112d26e | |||
1b46d64d71 | |||
38eda2f7b6 | |||
53b9c8ec97 | |||
7e8e95b748 | |||
7f51661e64 | |||
70023d2c4f | |||
c5d34f5ad5 | |||
8d3e51c205 | |||
b213753420 | |||
2eb8019325 | |||
9115cb7d31 | |||
62adad8f12 | |||
56f7ae0b46 | |||
446c1fb49a | |||
7d50625bd6 | |||
bd9ddc8b86 | |||
dd4fe4dcb4 | |||
1c174f263f | |||
d860e17b3b | |||
f83970bc6b | |||
87a245bf9c | |||
2d1afc634e | |||
e4f477dae0 | |||
8e210f8ea0 | |||
9c87056263 | |||
3251f19a19 | |||
299a2c89d1 | |||
c7241ca093 | |||
1a00e61239 | |||
f166e7f497 | |||
8dc08e4596 | |||
ead2c9273f | |||
5062543325 | |||
35e865bfb6 | |||
abb576c84f | |||
2d61ff7b88 | |||
e75b863f3b | |||
849cb2ea5a | |||
ab80677e3a | |||
bd7017d630 | |||
6e2bc01294 | |||
22c16f586b | |||
a42e3331d8 | |||
e14834c84e | |||
915a1c563b | |||
bc99cf83dd | |||
d00cbd4da7 | |||
721ff18a63 | |||
1a003fe4d3 | |||
68f78e1a30 | |||
7759d1d3fc | |||
738f9856a4 | |||
fbce8cd2f5 | |||
ea63c8e63a | |||
d8fea6afc4 | |||
ff16e1cd26 | |||
9b5ae1a322 | |||
8b8464163d | |||
eb4cdbb115 | |||
7f54b14b4d | |||
938ab9a139 | |||
75bde39b03 | |||
ee36c0208c | |||
7c02678ba5 | |||
235df737d0 | |||
37ef4bad8f | |||
ab7e0d9141 | |||
7db4d97fc2 | |||
3e1cf2deed | |||
4a00854b15 | |||
d4a52ffc93 | |||
c4ccfd865d | |||
38f10e10fa | |||
2cfe52e294 | |||
1c34450645 | |||
8325a8aeb1 | |||
081310b943 | |||
c75fb2137b | |||
6de821719f | |||
4662f65146 | |||
9789e5d701 | |||
5b7f8a4bb6 | |||
608065f2ad | |||
7ee4c4aad1 | |||
1963b80b46 | |||
a5c61e33d3 | |||
99904601ce | |||
7a0c350760 | |||
ca05b798ca | |||
b0711929c3 | |||
f09e1edb13 | |||
9230be86e9 | |||
6c05c6685e | |||
277c6abf0f | |||
829417ce6e | |||
dc9e9af9f8 | |||
dc6460361b | |||
d8fb24c971 | |||
3f9cade14d | |||
520faa7f2c | |||
8c7c087931 | |||
53b913a4cb | |||
7d38814cae | |||
08440d8ebd | |||
bab8ee9633 | |||
ca3df352ab | |||
b83085ea00 | |||
66131854c1 | |||
788c0c12e6 |
86
README.md
86
README.md
@ -1,4 +1,4 @@
|
||||
|
||||
<div align="center">
|
||||
|
||||
<div align="center">
|
||||
|
||||
@ -22,7 +22,6 @@ PR-Agent aims to help efficiently review and handle pull requests, by providing
|
||||
[](https://github.com/apps/qodo-merge-pro/)
|
||||
[](https://github.com/apps/qodo-merge-pro-for-open-source/)
|
||||
[](https://discord.com/invite/SgSxuQ65GF)
|
||||
<!-- TODO: add badge also for twitter -->
|
||||
<a href="https://github.com/Codium-ai/pr-agent/commits/main">
|
||||
<img alt="GitHub" src="https://img.shields.io/github/last-commit/Codium-ai/pr-agent/main?style=for-the-badge" height="20">
|
||||
</a>
|
||||
@ -32,12 +31,12 @@ PR-Agent aims to help efficiently review and handle pull requests, by providing
|
||||
|
||||
- [Getting Started](#getting-started)
|
||||
- [News and Updates](#news-and-updates)
|
||||
- [Overview](#overview)
|
||||
- [Why Use PR-Agent?](#why-use-pr-agent)
|
||||
- [Features](#features)
|
||||
- [See It in Action](#see-it-in-action)
|
||||
- [Try It Now](#try-it-now)
|
||||
- [Qodo Merge 💎](#qodo-merge-)
|
||||
- [How It Works](#how-it-works)
|
||||
- [Why Use PR-Agent?](#why-use-pr-agent)
|
||||
- [Data Privacy](#data-privacy)
|
||||
- [Contributing](#contributing)
|
||||
- [Links](#links)
|
||||
@ -45,7 +44,7 @@ PR-Agent aims to help efficiently review and handle pull requests, by providing
|
||||
## Getting Started
|
||||
|
||||
### Try it Instantly
|
||||
Test PR-Agent on any public GitHub repository by commenting `@CodiumAI-Agent /improve`. The bot will reply with code suggestions
|
||||
Test PR-Agent on any public GitHub repository by commenting `@CodiumAI-Agent /improve`
|
||||
|
||||
### GitHub Action
|
||||
Add automated PR reviews to your repository with a simple workflow file using [GitHub Action setup guide](https://qodo-merge-docs.qodo.ai/installation/github/#run-as-a-github-action)
|
||||
@ -58,24 +57,34 @@ Add automated PR reviews to your repository with a simple workflow file using [G
|
||||
### CLI Usage
|
||||
Run PR-Agent locally on your repository via command line: [Local CLI setup guide](https://qodo-merge-docs.qodo.ai/usage-guide/automations_and_usage/#local-repo-cli)
|
||||
|
||||
### Discover Qodo Merge 💎
|
||||
### Qodo Merge as post-commit in your local IDE
|
||||
See [here](https://github.com/qodo-ai/agents/tree/main/agents/qodo-merge-post-commit)
|
||||
|
||||
### Discover Qodo Merge 💎
|
||||
Zero-setup hosted solution with advanced features and priority support
|
||||
- **[FREE for Open Source](https://github.com/marketplace/qodo-merge-pro-for-open-source)**: Full features, zero cost for public repos
|
||||
- [Intro and Installation guide](https://qodo-merge-docs.qodo.ai/installation/qodo_merge/)
|
||||
- [Plans & Pricing](https://www.qodo.ai/pricing/)
|
||||
|
||||
### Qodo Merge as a Post-commit in Your Local IDE
|
||||
You can receive automatic feedback from Qodo Merge on your local IDE after each [commit](https://github.com/qodo-ai/agents/tree/main/agents/qodo-merge-post-commit)
|
||||
|
||||
|
||||
## News and Updates
|
||||
|
||||
## Jul 1, 2025
|
||||
You can now receive automatic feedback from Qodo Merge in your local IDE after each commit. Read more about it [here](https://github.com/qodo-ai/agents/tree/main/agents/qodo-merge-post-commit).
|
||||
|
||||
## Jun 21, 2025
|
||||
|
||||
v0.30 was [released](https://github.com/qodo-ai/pr-agent/releases)
|
||||
|
||||
|
||||
## Jun 3, 2025
|
||||
|
||||
Qodo Merge now offers a simplified free tier 💎.
|
||||
Organizations can use Qodo Merge at no cost, with a [monthly limit](https://qodo-merge-docs.qodo.ai/installation/qodo_merge/#cloud-users) of 75 PR reviews per organization.
|
||||
|
||||
## May 17, 2025
|
||||
|
||||
- v0.29 was [released](https://github.com/qodo-ai/pr-agent/releases)
|
||||
- `Qodo Merge Pull Request Benchmark` was [released](https://qodo-merge-docs.qodo.ai/pr_benchmark/). This benchmark evaluates and compares the performance of LLMs in analyzing pull request code.
|
||||
- `Recent Updates and Future Roadmap` page was added to the [Qodo Merge Docs](https://qodo-merge-docs.qodo.ai/recent_updates/)
|
||||
|
||||
## Apr 30, 2025
|
||||
|
||||
@ -93,25 +102,37 @@ New tool for Qodo Merge 💎 - `/scan_repo_discussions`.
|
||||
|
||||
Read more about it [here](https://qodo-merge-docs.qodo.ai/tools/scan_repo_discussions/).
|
||||
|
||||
## Overview
|
||||
## Why Use PR-Agent?
|
||||
|
||||
A reasonable question that can be asked is: `"Why use PR-Agent? What makes it stand out from existing tools?"`
|
||||
|
||||
Here are some advantages of PR-Agent:
|
||||
|
||||
- We emphasize **real-life practical usage**. Each tool (review, improve, ask, ...) has a single LLM call, no more. We feel that this is critical for realistic team usage - obtaining an answer quickly (~30 seconds) and affordably.
|
||||
- Our [PR Compression strategy](https://qodo-merge-docs.qodo.ai/core-abilities/#pr-compression-strategy) is a core ability that enables to effectively tackle both short and long PRs.
|
||||
- Our JSON prompting strategy enables us to have **modular, customizable tools**. For example, the '/review' tool categories can be controlled via the [configuration](pr_agent/settings/configuration.toml) file. Adding additional categories is easy and accessible.
|
||||
- We support **multiple git providers** (GitHub, GitLab, BitBucket), **multiple ways** to use the tool (CLI, GitHub Action, GitHub App, Docker, ...), and **multiple models** (GPT, Claude, Deepseek, ...)
|
||||
|
||||
## Features
|
||||
|
||||
<div style="text-align:left;">
|
||||
|
||||
Supported commands per platform:
|
||||
PR-Agent and Qodo Merge offer comprehensive pull request functionalities integrated with various git providers:
|
||||
|
||||
| | | GitHub | GitLab | Bitbucket | Azure DevOps | Gitea |
|
||||
|---------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|:------:|:------:|:---------:|:------------:|:-----:|
|
||||
| [TOOLS](https://qodo-merge-docs.qodo.ai/tools/) | [Describe](https://qodo-merge-docs.qodo.ai/tools/describe/) | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||
| | [Review](https://qodo-merge-docs.qodo.ai/tools/review/) | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||
| | [Improve](https://qodo-merge-docs.qodo.ai/tools/improve/) | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||
| | [Ask](https://qodo-merge-docs.qodo.ai/tools/ask/) | ✅ | ✅ | ✅ | ✅ | |
|
||||
| | ⮑ [Ask on code lines](https://qodo-merge-docs.qodo.ai/tools/ask/#ask-lines) | ✅ | ✅ | | | |
|
||||
| | [Help Docs](https://qodo-merge-docs.qodo.ai/tools/help_docs/?h=auto#auto-approval) | ✅ | ✅ | ✅ | | |
|
||||
| | [Update CHANGELOG](https://qodo-merge-docs.qodo.ai/tools/update_changelog/) | ✅ | ✅ | ✅ | ✅ | |
|
||||
| | [Add Documentation](https://qodo-merge-docs.qodo.ai/tools/documentation/) 💎 | ✅ | ✅ | | | |
|
||||
| | [Analyze](https://qodo-merge-docs.qodo.ai/tools/analyze/) 💎 | ✅ | ✅ | | | |
|
||||
| | [Auto-Approve](https://qodo-merge-docs.qodo.ai/tools/improve/?h=auto#auto-approval) 💎 | ✅ | ✅ | ✅ | | |
|
||||
| | [CI Feedback](https://qodo-merge-docs.qodo.ai/tools/ci_feedback/) 💎 | ✅ | | | | |
|
||||
| | | GitHub | GitLab | Bitbucket | Azure DevOps | Gitea |
|
||||
|---------------------------------------------------------|----------------------------------------------------------------------------------------|:------:|:------:|:---------:|:------------:|:-----:|
|
||||
| [TOOLS](https://qodo-merge-docs.qodo.ai/tools/) | [Describe](https://qodo-merge-docs.qodo.ai/tools/describe/) | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||
| | [Review](https://qodo-merge-docs.qodo.ai/tools/review/) | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||
| | [Improve](https://qodo-merge-docs.qodo.ai/tools/improve/) | ✅ | ✅ | ✅ | ✅ | ✅ |
|
||||
| | [Ask](https://qodo-merge-docs.qodo.ai/tools/ask/) | ✅ | ✅ | ✅ | ✅ | |
|
||||
| | ⮑ [Ask on code lines](https://qodo-merge-docs.qodo.ai/tools/ask/#ask-lines) | ✅ | ✅ | | | |
|
||||
| | [Help Docs](https://qodo-merge-docs.qodo.ai/tools/help_docs/?h=auto#auto-approval) | ✅ | ✅ | ✅ | | |
|
||||
| | [Update CHANGELOG](https://qodo-merge-docs.qodo.ai/tools/update_changelog/) | ✅ | ✅ | ✅ | ✅ | |
|
||||
| | [Add Documentation](https://qodo-merge-docs.qodo.ai/tools/documentation/) 💎 | ✅ | ✅ | | | |
|
||||
| | [Analyze](https://qodo-merge-docs.qodo.ai/tools/analyze/) 💎 | ✅ | ✅ | | | |
|
||||
| | [Auto-Approve](https://qodo-merge-docs.qodo.ai/tools/improve/?h=auto#auto-approval) 💎 | ✅ | ✅ | ✅ | | |
|
||||
| | [CI Feedback](https://qodo-merge-docs.qodo.ai/tools/ci_feedback/) 💎 | ✅ | | | | |
|
||||
| | [Compliance](https://qodo-merge-docs.qodo.ai/tools/compliance/) 💎 | ✅ | ✅ | ✅ | | |
|
||||
| | [Custom Prompt](https://qodo-merge-docs.qodo.ai/tools/custom_prompt/) 💎 | ✅ | ✅ | ✅ | | |
|
||||
| | [Generate Custom Labels](https://qodo-merge-docs.qodo.ai/tools/custom_labels/) 💎 | ✅ | ✅ | | | |
|
||||
| | [Generate Tests](https://qodo-merge-docs.qodo.ai/tools/test/) 💎 | ✅ | ✅ | | | |
|
||||
@ -187,7 +208,7 @@ ___
|
||||
|
||||
## Try It Now
|
||||
|
||||
Try PR-Agent instantly on _your public GitHub repository_. Just mention `@CodiumAI-Agent` and add the desired command in any PR comment. The agent will generate a response based on your command.
|
||||
Try the Claude Sonnet powered PR-Agent instantly on _your public GitHub repository_. Just mention `@CodiumAI-Agent` and add the desired command in any PR comment. The agent will generate a response based on your command.
|
||||
For example, add a comment to any pull request with the following text:
|
||||
|
||||
```
|
||||
@ -219,17 +240,6 @@ The following diagram illustrates PR-Agent tools and their flow:
|
||||
|
||||
Check out the [PR Compression strategy](https://qodo-merge-docs.qodo.ai/core-abilities/#pr-compression-strategy) page for more details on how we convert a code diff to a manageable LLM prompt
|
||||
|
||||
## Why Use PR-Agent?
|
||||
|
||||
A reasonable question that can be asked is: `"Why use PR-Agent? What makes it stand out from existing tools?"`
|
||||
|
||||
Here are some advantages of PR-Agent:
|
||||
|
||||
- We emphasize **real-life practical usage**. Each tool (review, improve, ask, ...) has a single LLM call, no more. We feel that this is critical for realistic team usage - obtaining an answer quickly (~30 seconds) and affordably.
|
||||
- Our [PR Compression strategy](https://qodo-merge-docs.qodo.ai/core-abilities/#pr-compression-strategy) is a core ability that enables to effectively tackle both short and long PRs.
|
||||
- Our JSON prompting strategy enables us to have **modular, customizable tools**. For example, the '/review' tool categories can be controlled via the [configuration](pr_agent/settings/configuration.toml) file. Adding additional categories is easy and accessible.
|
||||
- We support **multiple git providers** (GitHub, GitLab, BitBucket), **multiple ways** to use the tool (CLI, GitHub Action, GitHub App, Docker, ...), and **multiple models** (GPT, Claude, Deepseek, ...)
|
||||
|
||||
## Data Privacy
|
||||
|
||||
### Self-hosted PR-Agent
|
||||
|
@ -1,4 +1,4 @@
|
||||
FROM public.ecr.aws/lambda/python:3.12
|
||||
FROM public.ecr.aws/lambda/python:3.12 AS base
|
||||
|
||||
RUN dnf update -y && \
|
||||
dnf install -y gcc python3-devel git && \
|
||||
@ -9,4 +9,10 @@ RUN pip install --no-cache-dir . && rm pyproject.toml
|
||||
RUN pip install --no-cache-dir mangum==0.17.0
|
||||
COPY pr_agent/ ${LAMBDA_TASK_ROOT}/pr_agent/
|
||||
|
||||
CMD ["pr_agent.servers.serverless.serverless"]
|
||||
FROM base AS github_lambda
|
||||
CMD ["pr_agent.servers.github_lambda_webhook.lambda_handler"]
|
||||
|
||||
FROM base AS gitlab_lambda
|
||||
CMD ["pr_agent.servers.gitlab_lambda_webhook.lambda_handler"]
|
||||
|
||||
FROM github_lambda
|
||||
|
@ -19,7 +19,6 @@
|
||||
</div>
|
||||
|
||||
<style>
|
||||
Untitled
|
||||
.search-section {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
@ -202,7 +201,23 @@ h1 {
|
||||
|
||||
<script>
|
||||
window.addEventListener('load', function() {
|
||||
function displayResults(responseText) {
|
||||
function extractText(responseText) {
|
||||
try {
|
||||
console.log('responseText: ', responseText);
|
||||
const results = JSON.parse(responseText);
|
||||
const msg = results.message;
|
||||
|
||||
if (!msg || msg.trim() === '') {
|
||||
return "No results found";
|
||||
}
|
||||
return msg;
|
||||
} catch (error) {
|
||||
console.error('Error parsing results:', error);
|
||||
throw new Error("Failed parsing response message");
|
||||
}
|
||||
}
|
||||
|
||||
function displayResults(msg) {
|
||||
const resultsContainer = document.getElementById('results');
|
||||
const spinner = document.getElementById('spinner');
|
||||
const searchContainer = document.querySelector('.search-container');
|
||||
@ -214,8 +229,6 @@ window.addEventListener('load', function() {
|
||||
searchContainer.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
|
||||
try {
|
||||
const results = JSON.parse(responseText);
|
||||
|
||||
marked.setOptions({
|
||||
breaks: true,
|
||||
gfm: true,
|
||||
@ -223,7 +236,7 @@ window.addEventListener('load', function() {
|
||||
sanitize: false
|
||||
});
|
||||
|
||||
const htmlContent = marked.parse(results.message);
|
||||
const htmlContent = marked.parse(msg);
|
||||
|
||||
resultsContainer.className = 'markdown-content';
|
||||
resultsContainer.innerHTML = htmlContent;
|
||||
@ -242,7 +255,7 @@ window.addEventListener('load', function() {
|
||||
}, 100);
|
||||
} catch (error) {
|
||||
console.error('Error parsing results:', error);
|
||||
resultsContainer.innerHTML = '<div class="error-message">Error processing results</div>';
|
||||
resultsContainer.innerHTML = '<div class="error-message">Cannot process results</div>';
|
||||
}
|
||||
}
|
||||
|
||||
@ -275,24 +288,24 @@ window.addEventListener('load', function() {
|
||||
body: JSON.stringify(data)
|
||||
};
|
||||
|
||||
// const API_ENDPOINT = 'http://0.0.0.0:3000/api/v1/docs_help';
|
||||
//const API_ENDPOINT = 'http://0.0.0.0:3000/api/v1/docs_help';
|
||||
const API_ENDPOINT = 'https://help.merge.qodo.ai/api/v1/docs_help';
|
||||
|
||||
const response = await fetch(API_ENDPOINT, options);
|
||||
const responseText = await response.text();
|
||||
const msg = extractText(responseText);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
throw new Error(`An error (${response.status}) occurred during search: "${msg}"`);
|
||||
}
|
||||
|
||||
const responseText = await response.text();
|
||||
displayResults(responseText);
|
||||
|
||||
displayResults(msg);
|
||||
} catch (error) {
|
||||
spinner.style.display = 'none';
|
||||
resultsContainer.innerHTML = `
|
||||
<div class="error-message">
|
||||
An error occurred while searching. Please try again later.
|
||||
</div>
|
||||
`;
|
||||
const errorDiv = document.createElement('div');
|
||||
errorDiv.className = 'error-message';
|
||||
errorDiv.textContent = error instanceof Error ? error.message : String(error);
|
||||
resultsContainer.replaceChildren(errorDiv);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ There are two possible paths leading to this auto-approval - one via the `review
|
||||
ensure_ticket_compliance = true # Default is false
|
||||
```
|
||||
|
||||
If `ensure_ticket_compliance` is set to `true`, auto-approval will be disabled if no ticket is linked to the PR, or if the PR is not fully compliant with a linked ticket. This ensures that PRs are only auto-approved if their associated tickets are properly resolved.
|
||||
If `ensure_ticket_compliance` is set to `true`, auto-approval for the `review` toll path will be disabled if no ticket is linked to the PR, or if the PR is not fully compliant with a linked ticket. This ensures that PRs are only auto-approved if their associated tickets are properly resolved.
|
||||
|
||||
You can also prevent auto-approval if the PR exceeds the ticket's scope (see [here](https://qodo-merge-docs.qodo.ai/core-abilities/fetching_ticket_context/#configuration-options)).
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Incremental Update 💎
|
||||
|
||||
`Supported Git Platforms: GitHub`
|
||||
`Supported Git Platforms: GitHub, GitLab (Both cloud & server. For server: Version 17 and above)`
|
||||
|
||||
## Overview
|
||||
The Incremental Update feature helps users focus on feedback for their newest changes, making large PRs more manageable.
|
||||
|
@ -5,8 +5,8 @@ Qodo Merge utilizes a variety of core abilities to provide a comprehensive and e
|
||||
- [Auto approval](https://qodo-merge-docs.qodo.ai/core-abilities/auto_approval/)
|
||||
- [Auto best practices](https://qodo-merge-docs.qodo.ai/core-abilities/auto_best_practices/)
|
||||
- [Chat on code suggestions](https://qodo-merge-docs.qodo.ai/core-abilities/chat_on_code_suggestions/)
|
||||
- [Code validation](https://qodo-merge-docs.qodo.ai/core-abilities/code_validation/)
|
||||
- [Compression strategy](https://qodo-merge-docs.qodo.ai/core-abilities/compression_strategy/)
|
||||
- [Chrome extension](https://qodo-merge-docs.qodo.ai/chrome-extension/)
|
||||
- [Code validation](https://qodo-merge-docs.qodo.ai/core-abilities/code_validation/) <!-- - [Compression strategy](https://qodo-merge-docs.qodo.ai/core-abilities/compression_strategy/) -->
|
||||
- [Dynamic context](https://qodo-merge-docs.qodo.ai/core-abilities/dynamic_context/)
|
||||
- [Fetching ticket context](https://qodo-merge-docs.qodo.ai/core-abilities/fetching_ticket_context/)
|
||||
- [Impact evaluation](https://qodo-merge-docs.qodo.ai/core-abilities/impact_evaluation/)
|
||||
|
@ -66,7 +66,7 @@ ___
|
||||
___
|
||||
|
||||
??? note "Q: Can Qodo Merge review draft/offline PRs?"
|
||||
#### Answer:<span style="display:none;">5</span>
|
||||
#### Answer:<span style="display:none;">6</span>
|
||||
|
||||
Yes. While Qodo Merge won't automatically review draft PRs, you can still get feedback by manually requesting it through [online commenting](https://qodo-merge-docs.qodo.ai/usage-guide/automations_and_usage/#online-usage).
|
||||
|
||||
@ -74,7 +74,7 @@ ___
|
||||
___
|
||||
|
||||
??? note "Q: Can the 'Review effort' feedback be calibrated or customized?"
|
||||
#### Answer:<span style="display:none;">5</span>
|
||||
#### Answer:<span style="display:none;">7</span>
|
||||
|
||||
Yes, you can customize review effort estimates using the `extra_instructions` configuration option (see [documentation](https://qodo-merge-docs.qodo.ai/tools/review/#configuration-options)).
|
||||
|
||||
|
@ -24,7 +24,7 @@ To search the documentation site using natural language:
|
||||
|
||||
## Features
|
||||
|
||||
PR-Agent and Qodo Merge offers extensive pull request functionalities across various git providers:
|
||||
PR-Agent and Qodo Merge offer comprehensive pull request functionalities integrated with various git providers:
|
||||
|
||||
| | | GitHub | GitLab | Bitbucket | Azure DevOps | Gitea |
|
||||
| ----- |---------------------------------------------------------------------------------------------------------------------|:------:|:------:|:---------:|:------------:|:-----:|
|
||||
@ -39,6 +39,7 @@ PR-Agent and Qodo Merge offers extensive pull request functionalities across var
|
||||
| | [Analyze](https://qodo-merge-docs.qodo.ai/tools/analyze/) 💎 | ✅ | ✅ | | | |
|
||||
| | [Auto-Approve](https://qodo-merge-docs.qodo.ai/tools/improve/?h=auto#auto-approval) 💎 | ✅ | ✅ | ✅ | | |
|
||||
| | [CI Feedback](https://qodo-merge-docs.qodo.ai/tools/ci_feedback/) 💎 | ✅ | | | | |
|
||||
| | [Compliance](https://qodo-merge-docs.qodo.ai/tools/compliance/) 💎 | ✅ | ✅ | ✅ | | |
|
||||
| | [Custom Prompt](https://qodo-merge-docs.qodo.ai/tools/custom_prompt/) 💎 | ✅ | ✅ | ✅ | | |
|
||||
| | [Generate Custom Labels](https://qodo-merge-docs.qodo.ai/tools/custom_labels/) 💎 | ✅ | ✅ | | | |
|
||||
| | [Generate Tests](https://qodo-merge-docs.qodo.ai/tools/test/) 💎 | ✅ | ✅ | | | |
|
||||
|
@ -1,7 +1,7 @@
|
||||
## Azure DevOps Pipeline
|
||||
|
||||
You can use a pre-built Action Docker image to run PR-Agent as an Azure devops pipeline.
|
||||
add the following file to your repository under `azure-pipelines.yml`:
|
||||
Add the following file to your repository under `azure-pipelines.yml`:
|
||||
|
||||
```yaml
|
||||
# Opt out of CI triggers
|
||||
@ -71,7 +71,7 @@ git_provider="azure"
|
||||
```
|
||||
|
||||
Azure DevOps provider supports [PAT token](https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=Windows) or [DefaultAzureCredential](https://learn.microsoft.com/en-us/azure/developer/python/sdk/authentication-overview#authentication-in-server-environments) authentication.
|
||||
PAT is faster to create, but has build in expiration date, and will use the user identity for API calls.
|
||||
PAT is faster to create, but has built-in expiration date, and will use the user identity for API calls.
|
||||
Using DefaultAzureCredential you can use managed identity or Service principle, which are more secure and will create separate ADO user identity (via AAD) to the agent.
|
||||
|
||||
If PAT was chosen, you can assign the value in .secrets.toml.
|
||||
|
@ -50,7 +50,7 @@ git_provider="bitbucket_server"
|
||||
and pass the Pull request URL:
|
||||
|
||||
```shell
|
||||
python cli.py --pr_url https://git.onpreminstanceofbitbucket.com/projects/PROJECT/repos/REPO/pull-requests/1 review
|
||||
python cli.py --pr_url https://git.on-prem-instance-of-bitbucket.com/projects/PROJECT/repos/REPO/pull-requests/1 review
|
||||
```
|
||||
|
||||
### Run it as service
|
||||
@ -63,6 +63,6 @@ docker push codiumai/pr-agent:bitbucket_server_webhook # Push to your Docker re
|
||||
```
|
||||
|
||||
Navigate to `Projects` or `Repositories`, `Settings`, `Webhooks`, `Create Webhook`.
|
||||
Fill the name and URL, Authentication None select the Pull Request Opened checkbox to receive that event as webhook.
|
||||
Fill in the name and URL. For Authentication, select 'None'. Select the 'Pull Request Opened' checkbox to receive that event as a webhook.
|
||||
|
||||
The URL should end with `/webhook`, for example: https://domain.com/webhook
|
||||
|
@ -17,12 +17,11 @@ git clone https://github.com/qodo-ai/pr-agent.git
|
||||
```
|
||||
|
||||
5. Prepare variables and secrets. Skip this step if you plan on setting these as environment variables when running the agent:
|
||||
1. In the configuration file/variables:
|
||||
- Set `config.git_provider` to "gitea"
|
||||
|
||||
2. In the secrets file/variables:
|
||||
- Set your AI model key in the respective section
|
||||
- In the [Gitea] section, set `personal_access_token` (with token from step 2) and `webhook_secret` (with secret from step 3)
|
||||
- In the configuration file/variables:
|
||||
- Set `config.git_provider` to "gitea"
|
||||
- In the secrets file/variables:
|
||||
- Set your AI model key in the respective section
|
||||
- In the [Gitea] section, set `personal_access_token` (with token from step 2) and `webhook_secret` (with secret from step 3)
|
||||
|
||||
6. Build a Docker image for the app and optionally push it to a Docker repository. We'll use Dockerhub as an example:
|
||||
|
||||
|
@ -51,6 +51,430 @@ When you open your next PR, you should see a comment from `github-actions` bot w
|
||||
|
||||
See detailed usage instructions in the [USAGE GUIDE](https://qodo-merge-docs.qodo.ai/usage-guide/automations_and_usage/#github-action)
|
||||
|
||||
## Configuration Examples
|
||||
|
||||
This section provides detailed, step-by-step examples for configuring PR-Agent with different models and advanced options in GitHub Actions.
|
||||
|
||||
### Quick Start Examples
|
||||
|
||||
#### Basic Setup (OpenAI Default)
|
||||
|
||||
Copy this minimal workflow to get started with the default OpenAI models:
|
||||
|
||||
```yaml
|
||||
name: PR Agent
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, reopened, ready_for_review]
|
||||
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:
|
||||
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
|
||||
#### Gemini Setup
|
||||
|
||||
Ready-to-use workflow for Gemini models:
|
||||
|
||||
```yaml
|
||||
name: PR Agent (Gemini)
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, reopened, ready_for_review]
|
||||
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-1.5-flash"
|
||||
config.fallback_models: '["gemini/gemini-1.5-flash"]'
|
||||
GOOGLE_AI_STUDIO.GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
|
||||
github_action_config.auto_review: "true"
|
||||
github_action_config.auto_describe: "true"
|
||||
github_action_config.auto_improve: "true"
|
||||
```
|
||||
|
||||
#### Claude Setup
|
||||
|
||||
Ready-to-use workflow for Claude models:
|
||||
|
||||
```yaml
|
||||
name: PR Agent (Claude)
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, reopened, ready_for_review]
|
||||
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: "anthropic/claude-3-opus-20240229"
|
||||
config.fallback_models: '["anthropic/claude-3-haiku-20240307"]'
|
||||
ANTHROPIC.KEY: ${{ secrets.ANTHROPIC_KEY }}
|
||||
github_action_config.auto_review: "true"
|
||||
github_action_config.auto_describe: "true"
|
||||
github_action_config.auto_improve: "true"
|
||||
```
|
||||
|
||||
### Basic Configuration with Tool Controls
|
||||
|
||||
Start with this enhanced workflow that includes tool configuration:
|
||||
|
||||
```yaml
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, reopened, ready_for_review]
|
||||
issue_comment:
|
||||
jobs:
|
||||
pr_agent_job:
|
||||
if: ${{ github.event.sender.type != 'Bot' }}
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
issues: write
|
||||
pull-requests: write
|
||||
contents: write
|
||||
name: Run pr agent on every pull request, respond to user comments
|
||||
steps:
|
||||
- name: PR Agent action step
|
||||
id: pragent
|
||||
uses: qodo-ai/pr-agent@main
|
||||
env:
|
||||
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# Enable/disable automatic tools
|
||||
github_action_config.auto_review: "true"
|
||||
github_action_config.auto_describe: "true"
|
||||
github_action_config.auto_improve: "true"
|
||||
# Configure which PR events trigger the action
|
||||
github_action_config.pr_actions: '["opened", "reopened", "ready_for_review", "review_requested"]'
|
||||
```
|
||||
|
||||
### Switching Models
|
||||
|
||||
#### Using Gemini (Google AI Studio)
|
||||
|
||||
To use Gemini models instead of the default OpenAI models:
|
||||
|
||||
```yaml
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# Set the model to Gemini
|
||||
config.model: "gemini/gemini-1.5-flash"
|
||||
config.fallback_models: '["gemini/gemini-1.5-flash"]'
|
||||
# Add your Gemini API key
|
||||
GOOGLE_AI_STUDIO.GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
|
||||
# Tool configuration
|
||||
github_action_config.auto_review: "true"
|
||||
github_action_config.auto_describe: "true"
|
||||
github_action_config.auto_improve: "true"
|
||||
```
|
||||
|
||||
**Required Secrets:**
|
||||
- Add `GEMINI_API_KEY` to your repository secrets (get it from [Google AI Studio](https://aistudio.google.com/))
|
||||
|
||||
**Note:** When using non-OpenAI models like Gemini, you don't need to set `OPENAI_KEY` - only the model-specific API key is required.
|
||||
|
||||
#### Using Claude (Anthropic)
|
||||
|
||||
To use Claude models:
|
||||
|
||||
```yaml
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# Set the model to Claude
|
||||
config.model: "anthropic/claude-3-opus-20240229"
|
||||
config.fallback_models: '["anthropic/claude-3-haiku-20240307"]'
|
||||
# Add your Anthropic API key
|
||||
ANTHROPIC.KEY: ${{ secrets.ANTHROPIC_KEY }}
|
||||
# Tool configuration
|
||||
github_action_config.auto_review: "true"
|
||||
github_action_config.auto_describe: "true"
|
||||
github_action_config.auto_improve: "true"
|
||||
```
|
||||
|
||||
**Required Secrets:**
|
||||
- Add `ANTHROPIC_KEY` to your repository secrets (get it from [Anthropic Console](https://console.anthropic.com/))
|
||||
|
||||
**Note:** When using non-OpenAI models like Claude, you don't need to set `OPENAI_KEY` - only the model-specific API key is required.
|
||||
|
||||
#### Using Azure OpenAI
|
||||
|
||||
To use Azure OpenAI services:
|
||||
|
||||
```yaml
|
||||
env:
|
||||
OPENAI_KEY: ${{ secrets.AZURE_OPENAI_KEY }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# Azure OpenAI configuration
|
||||
OPENAI.API_TYPE: "azure"
|
||||
OPENAI.API_VERSION: "2023-05-15"
|
||||
OPENAI.API_BASE: ${{ secrets.AZURE_OPENAI_ENDPOINT }}
|
||||
OPENAI.DEPLOYMENT_ID: ${{ secrets.AZURE_OPENAI_DEPLOYMENT }}
|
||||
# Set the model to match your Azure deployment
|
||||
config.model: "gpt-4o"
|
||||
config.fallback_models: '["gpt-4o"]'
|
||||
# Tool configuration
|
||||
github_action_config.auto_review: "true"
|
||||
github_action_config.auto_describe: "true"
|
||||
github_action_config.auto_improve: "true"
|
||||
```
|
||||
|
||||
**Required Secrets:**
|
||||
- `AZURE_OPENAI_KEY`: Your Azure OpenAI API key
|
||||
- `AZURE_OPENAI_ENDPOINT`: Your Azure OpenAI endpoint URL
|
||||
- `AZURE_OPENAI_DEPLOYMENT`: Your deployment name
|
||||
|
||||
#### Using Local Models (Ollama)
|
||||
|
||||
To use local models via Ollama:
|
||||
|
||||
```yaml
|
||||
env:
|
||||
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# Set the model to a local Ollama model
|
||||
config.model: "ollama/qwen2.5-coder:32b"
|
||||
config.fallback_models: '["ollama/qwen2.5-coder:32b"]'
|
||||
config.custom_model_max_tokens: "128000"
|
||||
# Ollama configuration
|
||||
OLLAMA.API_BASE: "http://localhost:11434"
|
||||
# Tool configuration
|
||||
github_action_config.auto_review: "true"
|
||||
github_action_config.auto_describe: "true"
|
||||
github_action_config.auto_improve: "true"
|
||||
```
|
||||
|
||||
**Note:** For local models, you'll need to use a self-hosted runner with Ollama installed, as GitHub Actions hosted runners cannot access localhost services.
|
||||
|
||||
### Advanced Configuration Options
|
||||
|
||||
#### Custom Review Instructions
|
||||
|
||||
Add specific instructions for the review process:
|
||||
|
||||
```yaml
|
||||
env:
|
||||
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# Custom review instructions
|
||||
pr_reviewer.extra_instructions: "Focus on security vulnerabilities and performance issues. Check for proper error handling."
|
||||
# Tool configuration
|
||||
github_action_config.auto_review: "true"
|
||||
github_action_config.auto_describe: "true"
|
||||
github_action_config.auto_improve: "true"
|
||||
```
|
||||
|
||||
#### Language-Specific Configuration
|
||||
|
||||
Configure for specific programming languages:
|
||||
|
||||
```yaml
|
||||
env:
|
||||
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# Language-specific settings
|
||||
pr_reviewer.extra_instructions: "Focus on Python best practices, type hints, and docstrings."
|
||||
pr_code_suggestions.num_code_suggestions: "8"
|
||||
pr_code_suggestions.suggestions_score_threshold: "7"
|
||||
# Tool configuration
|
||||
github_action_config.auto_review: "true"
|
||||
github_action_config.auto_describe: "true"
|
||||
github_action_config.auto_improve: "true"
|
||||
```
|
||||
|
||||
#### Selective Tool Execution
|
||||
|
||||
Run only specific tools automatically:
|
||||
|
||||
```yaml
|
||||
env:
|
||||
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# Only run review and describe, skip improve
|
||||
github_action_config.auto_review: "true"
|
||||
github_action_config.auto_describe: "true"
|
||||
github_action_config.auto_improve: "false"
|
||||
# Only trigger on PR open and reopen
|
||||
github_action_config.pr_actions: '["opened", "reopened"]'
|
||||
```
|
||||
|
||||
### Using Configuration Files
|
||||
|
||||
Instead of setting all options via environment variables, you can use a `.pr_agent.toml` file in your repository root:
|
||||
|
||||
1. Create a `.pr_agent.toml` file in your repository root:
|
||||
|
||||
```toml
|
||||
[config]
|
||||
model = "gemini/gemini-1.5-flash"
|
||||
fallback_models = ["anthropic/claude-3-opus-20240229"]
|
||||
|
||||
[pr_reviewer]
|
||||
extra_instructions = "Focus on security issues and code quality."
|
||||
|
||||
[pr_code_suggestions]
|
||||
num_code_suggestions = 6
|
||||
suggestions_score_threshold = 7
|
||||
```
|
||||
|
||||
2. Use a simpler workflow file:
|
||||
|
||||
```yaml
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, reopened, ready_for_review]
|
||||
issue_comment:
|
||||
jobs:
|
||||
pr_agent_job:
|
||||
if: ${{ github.event.sender.type != 'Bot' }}
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
issues: write
|
||||
pull-requests: write
|
||||
contents: write
|
||||
name: Run pr agent on every pull request, respond to user comments
|
||||
steps:
|
||||
- name: PR Agent action step
|
||||
id: pragent
|
||||
uses: qodo-ai/pr-agent@main
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GOOGLE_AI_STUDIO.GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
|
||||
ANTHROPIC.KEY: ${{ secrets.ANTHROPIC_KEY }}
|
||||
github_action_config.auto_review: "true"
|
||||
github_action_config.auto_describe: "true"
|
||||
github_action_config.auto_improve: "true"
|
||||
```
|
||||
|
||||
### Troubleshooting Common Issues
|
||||
|
||||
#### Model Not Found Errors
|
||||
|
||||
If you get model not found errors:
|
||||
|
||||
1. **Check model name format**: Ensure you're using the correct model identifier format (e.g., `gemini/gemini-1.5-flash`, not just `gemini-1.5-flash`)
|
||||
|
||||
2. **Verify API keys**: Make sure your API keys are correctly set as repository secrets
|
||||
|
||||
3. **Check model availability**: Some models may not be available in all regions or may require specific access
|
||||
|
||||
#### Environment Variable Format
|
||||
|
||||
Remember these key points about environment variables:
|
||||
|
||||
- Use dots (`.`) or double underscores (`__`) to separate sections and keys
|
||||
- Boolean values should be strings: `"true"` or `"false"`
|
||||
- Arrays should be JSON strings: `'["item1", "item2"]'`
|
||||
- Model names are case-sensitive
|
||||
|
||||
#### Rate Limiting
|
||||
|
||||
If you encounter rate limiting:
|
||||
|
||||
```yaml
|
||||
env:
|
||||
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# Add fallback models for better reliability
|
||||
config.fallback_models: '["gpt-4o", "gpt-3.5-turbo"]'
|
||||
# Increase timeout for slower models
|
||||
config.ai_timeout: "300"
|
||||
github_action_config.auto_review: "true"
|
||||
github_action_config.auto_describe: "true"
|
||||
github_action_config.auto_improve: "true"
|
||||
```
|
||||
|
||||
#### Common Error Messages and Solutions
|
||||
|
||||
**Error: "Model not found"**
|
||||
- **Solution**: Check the model name format and ensure it matches the exact identifier. See the [Changing a model in PR-Agent](../usage-guide/changing_a_model.md) guide for supported models and their correct identifiers.
|
||||
|
||||
**Error: "API key not found"**
|
||||
- **Solution**: Verify that your API key is correctly set as a repository secret and the environment variable name matches exactly
|
||||
- **Note**: For non-OpenAI models (Gemini, Claude, etc.), you only need the model-specific API key, not `OPENAI_KEY`
|
||||
|
||||
**Error: "Rate limit exceeded"**
|
||||
- **Solution**: Add fallback models or increase the `config.ai_timeout` value
|
||||
|
||||
**Error: "Permission denied"**
|
||||
- **Solution**: Ensure your workflow has the correct permissions set:
|
||||
```yaml
|
||||
permissions:
|
||||
issues: write
|
||||
pull-requests: write
|
||||
contents: write
|
||||
```
|
||||
|
||||
**Error: "Invalid JSON format"**
|
||||
- **Solution**: Check that arrays are properly formatted as JSON strings:
|
||||
```yaml
|
||||
# Correct
|
||||
config.fallback_models: '["model1", "model2"]'
|
||||
# Incorrect (interpreted as a YAML list, not a string)
|
||||
config.fallback_models: ["model1", "model2"]
|
||||
```
|
||||
|
||||
#### Debugging Tips
|
||||
|
||||
1. **Enable verbose logging**: Add `config.verbosity_level: "2"` to see detailed logs
|
||||
2. **Check GitHub Actions logs**: Look at the step output for specific error messages
|
||||
3. **Test with minimal configuration**: Start with just the basic setup and add options one by one
|
||||
4. **Verify secrets**: Double-check that all required secrets are set in your repository settings
|
||||
|
||||
#### Performance Optimization
|
||||
|
||||
For better performance with large repositories:
|
||||
|
||||
```yaml
|
||||
env:
|
||||
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# Optimize for large PRs
|
||||
config.large_patch_policy: "clip"
|
||||
config.max_model_tokens: "32000"
|
||||
config.patch_extra_lines_before: "3"
|
||||
config.patch_extra_lines_after: "1"
|
||||
github_action_config.auto_review: "true"
|
||||
github_action_config.auto_describe: "true"
|
||||
github_action_config.auto_improve: "true"
|
||||
```
|
||||
|
||||
### Reference
|
||||
|
||||
For more detailed configuration options, see:
|
||||
- [Changing a model in PR-Agent](../usage-guide/changing_a_model.md)
|
||||
- [Configuration options](../usage-guide/configuration_options.md)
|
||||
- [Automations and usage](../usage-guide/automations_and_usage.md#github-action)
|
||||
|
||||
### Using a specific release
|
||||
|
||||
!!! tip ""
|
||||
@ -187,14 +611,15 @@ For example: `GITHUB.WEBHOOK_SECRET` --> `GITHUB__WEBHOOK_SECRET`
|
||||
2. Build a docker image that can be used as a lambda function
|
||||
|
||||
```shell
|
||||
docker buildx build --platform=linux/amd64 . -t codiumai/pr-agent:serverless -f docker/Dockerfile.lambda
|
||||
# Note: --target github_lambda is optional as it's the default target
|
||||
docker buildx build --platform=linux/amd64 . -t codiumai/pr-agent:github_lambda --target github_lambda -f docker/Dockerfile.lambda
|
||||
```
|
||||
|
||||
3. Push image to ECR
|
||||
|
||||
```shell
|
||||
docker tag codiumai/pr-agent:serverless <AWS_ACCOUNT>.dkr.ecr.<AWS_REGION>.amazonaws.com/codiumai/pr-agent:serverless
|
||||
docker push <AWS_ACCOUNT>.dkr.ecr.<AWS_REGION>.amazonaws.com/codiumai/pr-agent:serverless
|
||||
docker tag codiumai/pr-agent:github_lambda <AWS_ACCOUNT>.dkr.ecr.<AWS_REGION>.amazonaws.com/codiumai/pr-agent:github_lambda
|
||||
docker push <AWS_ACCOUNT>.dkr.ecr.<AWS_REGION>.amazonaws.com/codiumai/pr-agent:github_lambda
|
||||
```
|
||||
|
||||
4. Create a lambda function that uses the uploaded image. Set the lambda timeout to be at least 3m.
|
||||
@ -295,4 +720,4 @@ After you set up AWS CodeCommit using the instructions above, here is an example
|
||||
PYTHONPATH="/PATH/TO/PROJECTS/pr-agent" python pr_agent/cli.py \
|
||||
--pr_url https://us-east-1.console.aws.amazon.com/codesuite/codecommit/repositories/MY_REPO_NAME/pull-requests/321 \
|
||||
review
|
||||
```
|
||||
```
|
@ -46,7 +46,7 @@ Note that if your base branches are not protected, don't set the variables as `p
|
||||
|
||||
1. In GitLab create a new user and give it "Reporter" role ("Developer" if using Pro version of the agent) for the intended group or project.
|
||||
|
||||
2. For the user from step 1. generate a `personal_access_token` with `api` access.
|
||||
2. For the user from step 1, generate a `personal_access_token` with `api` access.
|
||||
|
||||
3. Generate a random secret for your app, and save it for later (`shared_secret`). For example, you can use:
|
||||
|
||||
@ -61,12 +61,12 @@ git clone https://github.com/qodo-ai/pr-agent.git
|
||||
```
|
||||
|
||||
5. Prepare variables and secrets. Skip this step if you plan on setting these as environment variables when running the agent:
|
||||
1. In the configuration file/variables:
|
||||
- Set `config.git_provider` to "gitlab"
|
||||
1. In the configuration file/variables:
|
||||
- Set `config.git_provider` to "gitlab"
|
||||
|
||||
2. In the secrets file/variables:
|
||||
- Set your AI model key in the respective section
|
||||
- In the [gitlab] section, set `personal_access_token` (with token from step 2) and `shared_secret` (with secret from step 3)
|
||||
2. In the secrets file/variables:
|
||||
- Set your AI model key in the respective section
|
||||
- In the [gitlab] section, set `personal_access_token` (with token from step 2) and `shared_secret` (with secret from step 3)
|
||||
|
||||
6. Build a Docker image for the app and optionally push it to a Docker repository. We'll use Dockerhub as an example:
|
||||
|
||||
@ -88,3 +88,63 @@ OPENAI__KEY=<your_openai_api_key>
|
||||
8. Create a webhook in your GitLab project. Set the URL to `http[s]://<PR_AGENT_HOSTNAME>/webhook`, the secret token to the generated secret from step 3, and enable the triggers `push`, `comments` and `merge request events`.
|
||||
|
||||
9. Test your installation by opening a merge request or commenting on a merge request using one of PR Agent's commands.
|
||||
|
||||
## Deploy as a Lambda Function
|
||||
|
||||
Note that since AWS Lambda env vars cannot have "." in the name, you can replace each "." in an env variable with "__".<br>
|
||||
For example: `GITLAB.PERSONAL_ACCESS_TOKEN` --> `GITLAB__PERSONAL_ACCESS_TOKEN`
|
||||
|
||||
1. Follow steps 1-5 from [Run a GitLab webhook server](#run-a-gitlab-webhook-server).
|
||||
2. Build a docker image that can be used as a lambda function
|
||||
|
||||
```shell
|
||||
docker buildx build --platform=linux/amd64 . -t codiumai/pr-agent:gitlab_lambda --target gitlab_lambda -f docker/Dockerfile.lambda
|
||||
```
|
||||
|
||||
3. Push image to ECR
|
||||
|
||||
```shell
|
||||
docker tag codiumai/pr-agent:gitlab_lambda <AWS_ACCOUNT>.dkr.ecr.<AWS_REGION>.amazonaws.com/codiumai/pr-agent:gitlab_lambda
|
||||
docker push <AWS_ACCOUNT>.dkr.ecr.<AWS_REGION>.amazonaws.com/codiumai/pr-agent:gitlab_lambda
|
||||
```
|
||||
|
||||
4. Create a lambda function that uses the uploaded image. Set the lambda timeout to be at least 3m.
|
||||
5. Configure the lambda function to have a Function URL.
|
||||
6. In the environment variables of the Lambda function, specify `AZURE_DEVOPS_CACHE_DIR` to a writable location such as /tmp. (see [link](https://github.com/Codium-ai/pr-agent/pull/450#issuecomment-1840242269))
|
||||
7. Go back to steps 8-9 of [Run a GitLab webhook server](#run-a-gitlab-webhook-server) with the function URL as your Webhook URL.
|
||||
The Webhook URL would look like `https://<LAMBDA_FUNCTION_URL>/webhook`
|
||||
|
||||
### Using AWS Secrets Manager
|
||||
|
||||
For production Lambda deployments, use AWS Secrets Manager instead of environment variables:
|
||||
|
||||
1. Create individual secrets for each GitLab webhook with this JSON format (e.g., secret name: `project-webhook-secret-001`)
|
||||
|
||||
```json
|
||||
{
|
||||
"gitlab_token": "glpat-xxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
"token_name": "project-webhook-001"
|
||||
}
|
||||
```
|
||||
|
||||
2. Create a main configuration secret for common settings (e.g., secret name: `pr-agent-main-config`)
|
||||
|
||||
```json
|
||||
{
|
||||
"openai.key": "sk-proj-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
}
|
||||
```
|
||||
|
||||
3. Set these environment variables in your Lambda:
|
||||
|
||||
```bash
|
||||
CONFIG__SECRET_PROVIDER=aws_secrets_manager
|
||||
AWS_SECRETS_MANAGER__SECRET_ARN=arn:aws:secretsmanager:us-east-1:123456789012:secret:pr-agent-main-config-AbCdEf
|
||||
```
|
||||
|
||||
4. In your GitLab webhook configuration, set the **Secret Token** to the **Secret name** created in step 1:
|
||||
- Example: `project-webhook-secret-001`
|
||||
|
||||
**Important**: When using Secrets Manager, GitLab's webhook secret must be the Secrets Manager secret name.
|
||||
|
||||
5. Add IAM permission `secretsmanager:GetSecretValue` to your Lambda execution role
|
@ -12,7 +12,7 @@ To invoke a tool (for example `review`), you can run PR-Agent directly from the
|
||||
- For GitHub:
|
||||
|
||||
```bash
|
||||
docker run --rm -it -e OPENAI.KEY=<your key> -e GITHUB.USER_TOKEN=<your token> codiumai/pr-agent:latest --pr_url <pr_url> review
|
||||
docker run --rm -it -e OPENAI.KEY=<your_openai_key> -e GITHUB.USER_TOKEN=<your_github_token> codiumai/pr-agent:latest --pr_url <pr_url> review
|
||||
```
|
||||
|
||||
If you are using GitHub enterprise server, you need to specify the custom url as variable.
|
||||
|
@ -3,7 +3,8 @@
|
||||
[Qodo Merge](https://www.codium.ai/pricing/){:target="_blank"} is a hosted version of the open-source [PR-Agent](https://github.com/Codium-ai/pr-agent){:target="_blank"}.
|
||||
It is designed for companies and teams that require additional features and capabilities.
|
||||
|
||||
Free users receive a monthly quota of 75 PR reviews per git organization, while unlimited usage requires a paid subscription. See [details](https://qodo-merge-docs.qodo.ai/installation/qodo_merge/#cloud-users).
|
||||
Free users receive a quota of 75 monthly PR feedbacks per git organization. Unlimited usage requires a paid subscription. See [details](https://qodo-merge-docs.qodo.ai/installation/qodo_merge/#cloud-users).
|
||||
|
||||
|
||||
Qodo Merge provides the following benefits:
|
||||
|
||||
|
@ -3,15 +3,18 @@
|
||||
## Methodology
|
||||
|
||||
Qodo Merge PR Benchmark evaluates and compares the performance of Large Language Models (LLMs) in analyzing pull request code and providing meaningful code suggestions.
|
||||
Our diverse dataset comprises of 400 pull requests from over 100 repositories, spanning various programming languages and frameworks to reflect real-world scenarios.
|
||||
Our diverse dataset contains 400 pull requests from over 100 repositories, spanning various programming languages and frameworks to reflect real-world scenarios.
|
||||
|
||||
- For each pull request, we have pre-generated suggestions from [11](https://qodo-merge-docs.qodo.ai/pr_benchmark/#models-used-for-generating-the-benchmark-baseline) different top-performing models using the Qodo Merge `improve` tool. The prompt for response generation can be found [here](https://github.com/qodo-ai/pr-agent/blob/main/pr_agent/settings/code_suggestions/pr_code_suggestions_prompts_not_decoupled.toml).
|
||||
- For each pull request, we have pre-generated suggestions from eleven different top-performing models using the Qodo Merge `improve` tool. The prompt for response generation can be found [here](https://github.com/qodo-ai/pr-agent/blob/main/pr_agent/settings/code_suggestions/pr_code_suggestions_prompts_not_decoupled.toml).
|
||||
|
||||
- To benchmark a model, we generate its suggestions for the same pull requests and ask a high-performing judge model to **rank** the new model's output against the 11 pre-generated baseline suggestions. We utilize OpenAI's `o3` model as the judge, though other models have yielded consistent results. The prompt for this ranking judgment is available [here](https://github.com/Codium-ai/pr-agent-settings/tree/main/benchmark).
|
||||
- To benchmark a model, we generate its suggestions for the same pull requests and ask a high-performing judge model to **rank** the new model's output against the pre-generated baseline suggestions. We utilize OpenAI's `o3` model as the judge, though other models have yielded consistent results. The prompt for this ranking judgment is available [here](https://github.com/Codium-ai/pr-agent-settings/tree/main/benchmark).
|
||||
|
||||
- We aggregate ranking outcomes across all pull requests, calculating performance metrics for the evaluated model. We also analyze the qualitative feedback from the judge to identify the model's comparative strengths and weaknesses against the established baselines.
|
||||
- We aggregate ranking outcomes across all pull requests, calculating performance metrics for the evaluated model.
|
||||
|
||||
- We also analyze the qualitative feedback from the judge to identify the model's comparative strengths and weaknesses against the established baselines.
|
||||
This approach provides not just a quantitative score but also a detailed analysis of each model's strengths and weaknesses.
|
||||
|
||||
A list of the models used for generating the baseline suggestions, and example results, can be found in the [Appendix](#appendix-example-results).
|
||||
|
||||
[//]: # (Note that this benchmark focuses on quality: the ability of an LLM to process complex pull request with multiple files and nuanced task to produce high-quality code suggestions.)
|
||||
|
||||
@ -19,7 +22,7 @@ This approach provides not just a quantitative score but also a detailed analysi
|
||||
|
||||
[//]: # ()
|
||||
|
||||
## Results
|
||||
## PR Benchmark Results
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
@ -55,6 +58,12 @@ This approach provides not just a quantitative score but also a detailed analysi
|
||||
<td style="text-align:left;">1024</td>
|
||||
<td style="text-align:center;"><b>44.3</b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="text-align:left;">Grok-4</td>
|
||||
<td style="text-align:left;">2025-07-09</td>
|
||||
<td style="text-align:left;">unknown</td>
|
||||
<td style="text-align:center;"><b>41.7</b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="text-align:left;">Claude-4-sonnet</td>
|
||||
<td style="text-align:left;">2025-05-14</td>
|
||||
@ -67,12 +76,24 @@ This approach provides not just a quantitative score but also a detailed analysi
|
||||
<td style="text-align:left;"></td>
|
||||
<td style="text-align:center;"><b>39.0</b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="text-align:left;">Codex-mini</td>
|
||||
<td style="text-align:left;">2025-06-20</td>
|
||||
<td style="text-align:left;"><a href="https://platform.openai.com/docs/models/codex-mini-latest">unknown</a></td>
|
||||
<td style="text-align:center;"><b>37.2</b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="text-align:left;">Gemini-2.5-flash</td>
|
||||
<td style="text-align:left;">2025-04-17</td>
|
||||
<td style="text-align:left;"></td>
|
||||
<td style="text-align:center;"><b>33.5</b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="text-align:left;">Claude-4-opus-20250514</td>
|
||||
<td style="text-align:left;">2025-05-14</td>
|
||||
<td style="text-align:left;"></td>
|
||||
<td style="text-align:center;"><b>32.8</b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="text-align:left;">Claude-3.7-sonnet</td>
|
||||
<td style="text-align:left;">2025-02-19</td>
|
||||
@ -196,7 +217,7 @@ weaknesses:
|
||||
- **Very low recall / shallow coverage:** In a large majority of cases it gives 0-1 suggestions and misses other evident, critical bugs highlighted by peer models, leading to inferior rankings.
|
||||
- **Occasional incorrect or harmful fixes:** A noticeable subset of answers propose changes that break functionality or misunderstand the code (e.g. bad constant, wrong header logic, speculative rollbacks).
|
||||
- **Non-actionable placeholders:** Some “improved_code” sections contain comments or “…” rather than real patches, reducing practical value.
|
||||
-
|
||||
|
||||
### GPT-4.1
|
||||
|
||||
Final score: **26.5**
|
||||
@ -214,19 +235,90 @@ weaknesses:
|
||||
- **Occasional technical inaccuracies:** A noticeable subset of suggestions are wrong (mis-ordered assertions, harmful Bash `set` change, false dangling-reference claims) or carry metadata errors (mis-labeling files as “python”).
|
||||
- **Repetitive / derivative fixes:** Many outputs duplicate earlier simplistic ideas (e.g., single null-check) without new insight, showing limited reasoning breadth.
|
||||
|
||||
### OpenAI codex-mini
|
||||
|
||||
## Appendix - models used for generating the benchmark baseline
|
||||
final score: **37.2**
|
||||
|
||||
- anthropic_sonnet_3.7_v1:0
|
||||
- claude-4-opus-20250514
|
||||
- claude-4-sonnet-20250514
|
||||
- claude-4-sonnet-20250514_thinking_2048
|
||||
- gemini-2.5-flash-preview-04-17
|
||||
- gemini-2.5-pro-preview-05-06
|
||||
- gemini-2.5-pro-preview-06-05_1024
|
||||
- gemini-2.5-pro-preview-06-05_4096
|
||||
- gpt-4.1
|
||||
- o3
|
||||
- o4-mini_medium
|
||||
strengths:
|
||||
|
||||
- **Can spot high-impact defects:** When it “locks on”, codex-mini often identifies the main runtime or security regression (e.g., race-conditions, logic inversions, blocking I/O, resource leaks) and proposes a minimal, direct patch that compiles and respects neighbouring style.
|
||||
- **Produces concise, scoped fixes:** Valid answers usually stay within the allowed 3-suggestion limit, reference only the added lines, and contain clear before/after snippets that reviewers can apply verbatim.
|
||||
- **Occasional broad coverage:** In a minority of cases the model catches multiple independent issues (logic + tests + docs) and outperforms every baseline answer, showing good contextual understanding of heterogeneous diffs.
|
||||
|
||||
weaknesses:
|
||||
|
||||
- **Output instability / format errors:** A very large share of responses are unusable—plain refusals, shell commands, or malformed/empty YAML—indicating brittle adherence to the required schema and tanking overall usefulness.
|
||||
- **Critical-miss rate:** Even when the format is correct the model frequently overlooks the single most serious bug the diff introduces, instead focusing on stylistic nits or speculative refactors.
|
||||
- **Introduces new problems:** Several suggestions add unsupported APIs, undeclared variables, wrong types, or break compilation, hurting trust in the recommendations.
|
||||
- **Rule violations:** It often edits lines outside the diff, exceeds the 3-suggestion cap, or labels cosmetic tweaks as “critical”, showing inconsistent guideline compliance.
|
||||
|
||||
### Claude-4 Opus
|
||||
|
||||
final score: **32.8**
|
||||
|
||||
strengths:
|
||||
|
||||
- **Format & rule adherence:** Almost always returns valid YAML, stays within the ≤3-suggestion limit, and usually restricts edits to newly-added lines, so its output is easy to apply automatically.
|
||||
- **Concise, focused patches:** When it does find a real bug it gives short, well-scoped explanations plus minimal diff snippets, often outperforming verbose baselines in clarity.
|
||||
- **Able to catch subtle edge-cases:** In several examples it detected overflow, race-condition or enum-mismatch issues that many other models missed, showing solid code‐analysis capability.
|
||||
|
||||
weaknesses:
|
||||
|
||||
- **Low recall / narrow coverage:** In a large share of the 399 examples the model produced an empty list or only one minor tip while more serious defects were present, causing it to be rated inferior to most baselines.
|
||||
- **Frequent incorrect or no-op fixes:** It sometimes supplies identical “before/after” code, flags non-issues, or suggests changes that would break compilation or logic, reducing reviewer trust.
|
||||
- **Shaky guideline consistency:** Although generally compliant, it still occasionally violates rules (touches unchanged lines, offers stylistic advice, adds imports) and duplicates suggestions, indicating unstable internal checks.
|
||||
|
||||
### Grok-4
|
||||
|
||||
final score: **32.8**
|
||||
|
||||
strengths:
|
||||
|
||||
- **Focused and concise fixes:** When the model does detect a problem it usually proposes a minimal, well-scoped patch that compiles and directly addresses the defect without unnecessary noise.
|
||||
- **Good critical-bug instinct:** It often prioritises show-stoppers (compile failures, crashes, security issues) over cosmetic matters and occasionally spots subtle issues that all other reviewers miss.
|
||||
- **Clear explanations & snippets:** Explanations are short, readable and paired with ready-to-paste code, making the advice easy to apply.
|
||||
|
||||
weaknesses:
|
||||
|
||||
- **High miss rate:** In a large fraction of examples the model returned an empty list or covered only one minor issue while overlooking more serious newly-introduced bugs.
|
||||
- **Inconsistent accuracy:** A noticeable subset of answers contain wrong or even harmful fixes (e.g., removing valid flags, creating compile errors, re-introducing bugs).
|
||||
- **Limited breadth:** Even when it finds a real defect it rarely reports additional related problems that peers catch, leading to partial reviews.
|
||||
- **Occasional guideline slips:** A few replies modify unchanged lines, suggest new imports, or duplicate suggestions, showing imperfect compliance with instructions.
|
||||
|
||||
## Appendix - Example Results
|
||||
|
||||
Some examples of benchmarked PRs and their results:
|
||||
|
||||
- [Example 1](https://www.qodo.ai/images/qodo_merge_benchmark/example_results1.html)
|
||||
- [Example 2](https://www.qodo.ai/images/qodo_merge_benchmark/example_results2.html)
|
||||
- [Example 3](https://www.qodo.ai/images/qodo_merge_benchmark/example_results3.html)
|
||||
- [Example 4](https://www.qodo.ai/images/qodo_merge_benchmark/example_results4.html)
|
||||
|
||||
### Models Used for Benchmarking
|
||||
|
||||
The following models were used for generating the benchmark baseline:
|
||||
|
||||
```markdown
|
||||
(1) anthropic_sonnet_3.7_v1:0
|
||||
|
||||
(2) claude-4-opus-20250514
|
||||
|
||||
(3) claude-4-sonnet-20250514
|
||||
|
||||
(4) claude-4-sonnet-20250514_thinking_2048
|
||||
|
||||
(5) gemini-2.5-flash-preview-04-17
|
||||
|
||||
(6) gemini-2.5-pro-preview-05-06
|
||||
|
||||
(7) gemini-2.5-pro-preview-06-05_1024
|
||||
|
||||
(8) gemini-2.5-pro-preview-06-05_4096
|
||||
|
||||
(9) gpt-4.1
|
||||
|
||||
(10) o3
|
||||
|
||||
(11) o4-mini_medium
|
||||
```
|
||||
|
||||
|
@ -1,23 +1,21 @@
|
||||
# Recent Updates and Future Roadmap
|
||||
|
||||
`Page last updated: 2025-06-01`
|
||||
`Page last updated: 2025-07-01`
|
||||
|
||||
This page summarizes recent enhancements to Qodo Merge (last three months).
|
||||
|
||||
It also outlines our development roadmap for the upcoming three months. Please note that the roadmap is subject to change, and features may be adjusted, added, or reprioritized.
|
||||
|
||||
=== "Recent Updates"
|
||||
- **Receiving Qodo Merge feedback locally**: You can receive automatic feedback from Qodo Merge on your local IDE after each commit. ([Learn more](https://github.com/qodo-ai/agents/tree/main/agents/qodo-merge-post-commit)).
|
||||
- **Mermaid Diagrams**: Qodo Merge now generates by default Mermaid diagrams for PRs, providing a visual representation of code changes. ([Learn more](https://qodo-merge-docs.qodo.ai/tools/describe/#sequence-diagram-support))
|
||||
- **Best Practices Hierarchy**: Introducing support for structured best practices, such as for folders in monorepos or a unified best practice file for a group of repositories. ([Learn more](https://qodo-merge-docs.qodo.ai/tools/improve/#global-hierarchical-best-practices))
|
||||
- **Simplified Free Tier**: Qodo Merge now offers a simplified free tier with a monthly limit of 75 PR reviews per organization, replacing the previous two-week trial. ([Learn more](https://qodo-merge-docs.qodo.ai/installation/qodo_merge/#cloud-users))
|
||||
- **CLI Endpoint**: A new Qodo Merge endpoint that accepts a lists of before/after code changes, executes Qodo Merge commands, and return the results. Currently available for enterprise customers. Contact [Qodo](https://www.qodo.ai/contact/) for more information.
|
||||
- **Linear tickets support**: Qodo Merge now supports Linear tickets. ([Learn more](https://qodo-merge-docs.qodo.ai/core-abilities/fetching_ticket_context/#linear-integration))
|
||||
- **Smart Update**: Upon PR updates, Qodo Merge will offer tailored code suggestions, addressing both the entire PR and the specific incremental changes since the last feedback ([Learn more](https://qodo-merge-docs.qodo.ai/core-abilities/incremental_update//))
|
||||
- **Qodo Merge Pull Request Benchmark** - evaluating the performance of LLMs in analyzing pull request code ([Learn more](https://qodo-merge-docs.qodo.ai/pr_benchmark/))
|
||||
- **Chat on Suggestions**: Users can now chat with code suggestions ([Learn more](https://qodo-merge-docs.qodo.ai/tools/improve/#chat-on-code-suggestions))
|
||||
- **Scan Repo Discussions Tool**: A new tool that analyzes past code discussions to generate a `best_practices.md` file, distilling key insights and recommendations. ([Learn more](https://qodo-merge-docs.qodo.ai/tools/scan_repo_discussions/))
|
||||
|
||||
- **Smart Update**: Upon PR updates, Qodo Merge will offer tailored code suggestions, addressing both the entire PR and the specific incremental changes since the last feedback ([Learn more](https://qodo-merge-docs.qodo.ai/core-abilities/incremental_update/))
|
||||
|
||||
=== "Future Roadmap"
|
||||
- **Best Practices Hierarchy**: Introducing support for structured best practices, such as for folders in monorepos or a unified best practice file for a group of repositories.
|
||||
- **Enhanced `review` tool**: Enhancing the `review` tool validate compliance across multiple categories including security, tickets, and custom best practices.
|
||||
- **Smarter context retrieval**: Leverage AST and LSP analysis to gather relevant context from across the entire repository.
|
||||
- **Enhanced portal experience**: Improved user experience in the Qodo Merge portal with new options and capabilities.
|
||||
|
298
docs/docs/tools/compliance.md
Normal file
298
docs/docs/tools/compliance.md
Normal file
@ -0,0 +1,298 @@
|
||||
`Platforms supported: GitHub, GitLab, Bitbucket`
|
||||
|
||||
## Overview
|
||||
|
||||
The `compliance` tool performs comprehensive compliance checks on PR code changes, validating them against security standards, ticket requirements, and custom organizational compliance checklists, thereby helping teams, enterprises, and agents maintain consistent code quality and security practices while ensuring that development work aligns with business requirements.
|
||||
|
||||
=== "Fully Compliant"
|
||||
{width=256}
|
||||
|
||||
=== "Partially Compliant"
|
||||
{width=256}
|
||||
|
||||
___
|
||||
|
||||
[//]: # (???+ note "The following features are available only for Qodo Merge 💎 users:")
|
||||
|
||||
[//]: # ( - Custom compliance checklists and hierarchical compliance checklists)
|
||||
|
||||
[//]: # ( - Ticket compliance validation with Jira/Linear integration)
|
||||
|
||||
[//]: # ( - Auto-approval based on compliance status)
|
||||
|
||||
[//]: # ( - Compliance labels and automated enforcement)
|
||||
|
||||
## Example Usage
|
||||
|
||||
### Manual Triggering
|
||||
|
||||
Invoke the tool manually by commenting `/compliance` on any PR. The compliance results are presented in a comprehensive table:
|
||||
|
||||
To edit [configurations](#configuration-options) related to the `compliance` tool, use the following template:
|
||||
|
||||
```toml
|
||||
/compliance --pr_compliance.some_config1=... --pr_compliance.some_config2=...
|
||||
```
|
||||
|
||||
For example, you can enable ticket compliance labels by running:
|
||||
|
||||
```toml
|
||||
/compliance --pr_compliance.enable_ticket_labels=true
|
||||
```
|
||||
|
||||
### Automatic Triggering
|
||||
|
||||
|
||||
The tool can be triggered automatically every time a new PR is [opened](https://qodo-merge-docs.qodo.ai/usage-guide/automations_and_usage/#github-app-automatic-tools-when-a-new-pr-is-opened), or in a [push](https://qodo-merge-docs.qodo.ai/usage-guide/automations_and_usage/?h=push#github-app-automatic-tools-for-push-actions-commits-to-an-open-pr) event to an existing PR.
|
||||
|
||||
To run the `compliance` tool automatically when a PR is opened, define the following in the [configuration file](https://qodo-merge-docs.qodo.ai/usage-guide/configuration_options/):
|
||||
|
||||
```toml
|
||||
[github_app] # for example
|
||||
pr_commands = [
|
||||
"/compliance",
|
||||
...
|
||||
]
|
||||
|
||||
```
|
||||
|
||||
## Compliance Categories
|
||||
|
||||
The compliance tool evaluates three main categories:
|
||||
|
||||
|
||||
### 1. Security Compliance
|
||||
|
||||
Scans for security vulnerabilities and potential exploits in the PR code changes:
|
||||
|
||||
- **Verified Security Concerns** 🔴: Clear security vulnerabilities that require immediate attention
|
||||
- **Possible Security Risks** ⚪: Potential security issues that need human verification
|
||||
- **No Security Concerns** 🟢: No security vulnerabilities detected
|
||||
|
||||
Examples of security issues:
|
||||
|
||||
- Exposure of sensitive information (API keys, passwords, secrets)
|
||||
- SQL injection vulnerabilities
|
||||
- Cross-site scripting (XSS) risks
|
||||
- Cross-site request forgery (CSRF) vulnerabilities
|
||||
- Insecure data handling patterns
|
||||
|
||||
|
||||
### 2. Ticket Compliance
|
||||
|
||||
???+ tip "How to set up ticket compliance"
|
||||
Follow the guide on how to set up [ticket compliance](https://qodo-merge-docs.qodo.ai/core-abilities/fetching_ticket_context/) with Qodo Merge.
|
||||
|
||||
Validates that PR changes fulfill the requirements specified in linked tickets:
|
||||
|
||||
- **Fully Compliant** 🟢: All ticket requirements are satisfied
|
||||
- **Partially Compliant** 🟡: Some requirements are met, others need attention
|
||||
- **Not Compliant** 🔴: Clear violations of ticket requirements
|
||||
- **Requires Verification** ⚪: Requirements that need human review
|
||||
|
||||
|
||||
### 3. Custom Compliance
|
||||
|
||||
Validates against an organization-specific compliance checklist:
|
||||
|
||||
- **Fully Compliant** 🟢: All custom compliance are satisfied
|
||||
- **Not Compliant** 🔴: Violations of custom compliance
|
||||
- **Requires Verification** ⚪: Compliance that need human assessment
|
||||
|
||||
## Custom Compliance
|
||||
|
||||
### Setting Up Custom Compliance
|
||||
|
||||
Each compliance is defined in a YAML file as follows:
|
||||
- `title`: Used to provide a clear name for the compliance
|
||||
- `compliance_label`: Used to automatically generate labels for non-compliance issues
|
||||
- `objective`, `success_criteria`, and `failure_criteria`: These fields are used to clearly define what constitutes compliance
|
||||
|
||||
???+ tip "Example of a compliance checklist"
|
||||
|
||||
```yaml
|
||||
# pr_compliance_checklist.yaml
|
||||
pr_compliances:
|
||||
- title: "Error Handling"
|
||||
compliance_label: true
|
||||
objective: "All external API calls must have proper error handling"
|
||||
success_criteria: "Try-catch blocks around external calls with appropriate logging"
|
||||
failure_criteria: "External API calls without error handling or logging"
|
||||
|
||||
...
|
||||
```
|
||||
|
||||
???+ tip "Writing effective compliance checklists"
|
||||
- Avoid overly complex or subjective compliances that are hard to verify
|
||||
- Keep compliances focused on security, business requirements, and critical standards
|
||||
- Use clear, actionable language that developers can understand
|
||||
- Focus on meaningful compliance requirements, not style preferences
|
||||
|
||||
|
||||
### Global Hierarchical Compliance
|
||||
|
||||
Qodo Merge supports hierarchical compliance checklists using a dedicated global configuration repository.
|
||||
|
||||
#### Setting up global hierarchical compliance
|
||||
|
||||
1\. Create a new repository named `pr-agent-settings` in your organization or workspace.
|
||||
|
||||
2\. Build the folder hierarchy in your `pr-agent-settings` repository:
|
||||
|
||||
```bash
|
||||
pr-agent-settings/
|
||||
├── metadata.yaml # Maps repos/folders to compliance paths
|
||||
└── compliance_standards/ # Root for all compliance definitions
|
||||
├── global/ # Global compliance, inherited widely
|
||||
│ └── pr_compliance_checklist.yaml
|
||||
├── groups/ # For groups of repositories
|
||||
│ ├── frontend_repos/
|
||||
│ │ └── pr_compliance_checklist.yaml
|
||||
│ └── backend_repos/
|
||||
│ └── pr_compliance_checklist.yaml
|
||||
├── qodo-merge/ # For standalone repositories
|
||||
│ └── pr_compliance_checklist.yaml
|
||||
└── qodo-monorepo/ # For monorepo-specific compliance
|
||||
├── pr_compliance_checklist.yaml # Root-level monorepo compliance
|
||||
├── qodo-github/ # Subproject compliance
|
||||
│ └── pr_compliance_checklist.yaml
|
||||
└── qodo-gitlab/ # Another subproject
|
||||
└── pr_compliance_checklist.yaml
|
||||
```
|
||||
|
||||
3\. Define the metadata file `metadata.yaml` in the root of `pr-agent-settings`:
|
||||
|
||||
```yaml
|
||||
# Standalone repos
|
||||
qodo-merge:
|
||||
pr_compliance_checklist_paths:
|
||||
- "qodo-merge"
|
||||
|
||||
# Group-associated repos
|
||||
repo_b:
|
||||
pr_compliance_checklist_paths:
|
||||
- "groups/backend_repos"
|
||||
|
||||
# Multi-group repos
|
||||
repo_c:
|
||||
pr_compliance_checklist_paths:
|
||||
- "groups/frontend_repos"
|
||||
- "groups/backend_repos"
|
||||
|
||||
# Monorepo with subprojects
|
||||
qodo-monorepo:
|
||||
pr_compliance_checklist_paths:
|
||||
- "qodo-monorepo"
|
||||
monorepo_subprojects:
|
||||
frontend:
|
||||
pr_compliance_checklist_paths:
|
||||
- "qodo-monorepo/qodo-github"
|
||||
backend:
|
||||
pr_compliance_checklist_paths:
|
||||
- "qodo-monorepo/qodo-gitlab"
|
||||
```
|
||||
|
||||
4\. Set the following configuration:
|
||||
|
||||
```toml
|
||||
[pr_compliance]
|
||||
enable_global_pr_compliance = true
|
||||
```
|
||||
|
||||
???- info "Compliance priority and fallback behavior"
|
||||
|
||||
1\. **Primary**: Global hierarchical compliance checklists from the `pr-agent-settings` repository:
|
||||
|
||||
1.1 If the repository is mapped in `metadata.yaml`, it uses the specified paths
|
||||
|
||||
1.2 For monorepos, it automatically collects compliance checklists matching PR file paths
|
||||
|
||||
1.3 If no mapping exists, it falls back to the global compliance checklists
|
||||
|
||||
2\. **Fallback**: Local repository wiki `pr_compliance_checklist.yaml` file:
|
||||
|
||||
2.1 Used when global compliance checklists are not found or configured
|
||||
|
||||
2.2 Acts as a safety net for repositories not yet configured in the global system
|
||||
|
||||
2.3 Local wiki compliance checklists are completely ignored when compliance checklists are successfully loaded
|
||||
|
||||
|
||||
## Configuration Options
|
||||
|
||||
???+ example "General options"
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td><b>extra_instructions</b></td>
|
||||
<td>Optional extra instructions for the tool. For example: "Ensure that all error-handling paths in the code contain appropriate logging statements". Default is empty string.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>persistent_comment</b></td>
|
||||
<td>If set to true, the compliance comment will be persistent, meaning that every new compliance request will edit the previous one. Default is true.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>enable_user_defined_compliance_labels</b></td>
|
||||
<td>If set to true, the tool will add the label `Failed compliance check` for custom compliance violations. Default is true.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>enable_estimate_effort_to_review</b></td>
|
||||
<td>If set to true, the tool will estimate the effort required to review the PR (1-5 scale) as a label. Default is true.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>enable_todo_scan</b></td>
|
||||
<td>If set to true, the tool will scan for TODO comments in the PR code. Default is false.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>enable_update_pr_compliance_checkbox</b></td>
|
||||
<td>If set to true, the tool will add an update checkbox to refresh compliance status following push events. Default is true.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>enable_help_text</b></td>
|
||||
<td>If set to true, the tool will display help text in the comment. Default is false.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
???+ example "Security compliance options"
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td><b>enable_security_compliance</b></td>
|
||||
<td>If set to true, the tool will check for security vulnerabilities. Default is true.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>enable_compliance_labels_security</b></td>
|
||||
<td>If set to true, the tool will add a `Possible security concern` label to the PR when security-related concerns are detected. Default is true.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
???+ example "Ticket compliance options"
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td><b>enable_ticket_labels</b></td>
|
||||
<td>If set to true, the tool will add ticket compliance labels to the PR. Default is false.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>enable_no_ticket_labels</b></td>
|
||||
<td>If set to true, the tool will add a label when no ticket is found. Default is false.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>check_pr_additional_content</b></td>
|
||||
<td>If set to true, the tool will check if the PR contains content not related to the ticket. Default is false.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
## Usage Tips
|
||||
|
||||
### Blocking PRs Based on Compliance
|
||||
|
||||
!!! tip ""
|
||||
You can configure CI/CD Actions to prevent merging PRs with specific compliance labels:
|
||||
|
||||
- `Possible security concern` - Block PRs with potential security issues
|
||||
- `Failed compliance check` - Block PRs that violate custom compliance checklists
|
||||
|
||||
Implement a dedicated [GitHub Action](https://medium.com/sequra-tech/quick-tip-block-pull-request-merge-using-labels-6cc326936221) to enforce these checklists.
|
||||
|
@ -47,29 +47,41 @@ publish_labels = true
|
||||
|
||||
## Preserving the original user description
|
||||
|
||||
By default, Qodo Merge preserves your original PR description by placing it above the generated content.
|
||||
By default, Qodo Merge tries to preserve your original PR description by placing it above the generated content.
|
||||
This requires including your description during the initial PR creation.
|
||||
Be aware that if you edit the description while the automated tool is running, a race condition may occur, potentially causing your original description to be lost.
|
||||
|
||||
When updating PR descriptions, the `/describe` tool considers everything above the "PR Type" field as user content and will preserve it.
|
||||
"Qodo removed the original description from the PR. Why"?
|
||||
|
||||
From our experience, there are two possible reasons:
|
||||
|
||||
- If you edit the description _while_ the automated tool is running, a race condition may occur, potentially causing your original description to be lost. Hence, create a description before launching the PR.
|
||||
|
||||
- When _updating_ PR descriptions, the `/describe` tool considers everything above the "PR Type" field as user content and will preserve it.
|
||||
Everything below this marker is treated as previously auto-generated content and will be replaced.
|
||||
|
||||
{width=512}
|
||||
|
||||
### Sequence Diagram Support
|
||||
When the `enable_pr_diagram` option is enabled in your configuration, the `/describe` tool will include a `Mermaid` sequence diagram in the PR description.
|
||||
## Sequence Diagram Support
|
||||
The `/describe` tool includes a Mermaid sequence diagram showing component/function interactions.
|
||||
|
||||
This diagram represents interactions between components/functions based on the diff content.
|
||||
This option is enabled by default via the `pr_description.enable_pr_diagram` param.
|
||||
|
||||
### How to enable
|
||||
|
||||
In your configuration:
|
||||
[//]: # (### How to enable\disable)
|
||||
|
||||
```
|
||||
toml
|
||||
[pr_description]
|
||||
enable_pr_diagram = true
|
||||
```
|
||||
[//]: # ()
|
||||
[//]: # (In your configuration:)
|
||||
|
||||
[//]: # ()
|
||||
[//]: # (```)
|
||||
|
||||
[//]: # (toml)
|
||||
|
||||
[//]: # ([pr_description])
|
||||
|
||||
[//]: # (enable_pr_diagram = true)
|
||||
|
||||
[//]: # (```)
|
||||
|
||||
## Configuration options
|
||||
|
||||
@ -112,13 +124,17 @@ enable_pr_diagram = true
|
||||
<td><b>enable_semantic_files_types</b></td>
|
||||
<td>If set to true, "Changes walkthrough" section will be generated. Default is true.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>file_table_collapsible_open_by_default</b></td>
|
||||
<td>If set to true, the file list in the "Changes walkthrough" section will be open by default. If set to false, it will be closed by default. Default is false.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>collapsible_file_list</b></td>
|
||||
<td>If set to true, the file list in the "Changes walkthrough" section will be collapsible. If set to "adaptive", the file list will be collapsible only if there are more than 8 files. Default is "adaptive".</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>enable_large_pr_handling</b></td>
|
||||
<td>Pro feature. If set to true, in case of a large PR the tool will make several calls to the AI and combine them to be able to cover more files. Default is true.</td>
|
||||
<td><b>enable_large_pr_handling 💎</b></td>
|
||||
<td>If set to true, in case of a large PR the tool will make several calls to the AI and combine them to be able to cover more files. Default is true.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>enable_help_text</b></td>
|
||||
@ -126,7 +142,7 @@ enable_pr_diagram = true
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>enable_pr_diagram</b></td>
|
||||
<td>If set to true, the tool will generate a horizontal Mermaid flowchart summarizing the main pull request changes. This field remains empty if not applicable. Default is false.</td>
|
||||
<td>If set to true, the tool will generate a horizontal Mermaid flowchart summarizing the main pull request changes. This field remains empty if not applicable. Default is true.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@ -170,9 +186,12 @@ pr_agent:summary
|
||||
|
||||
## PR Walkthrough:
|
||||
pr_agent:walkthrough
|
||||
|
||||
## PR Diagram:
|
||||
pr_agent:diagram
|
||||
```
|
||||
|
||||
The marker `pr_agent:type` will be replaced with the PR type, `pr_agent:summary` will be replaced with the PR summary, and `pr_agent:walkthrough` will be replaced with the PR walkthrough.
|
||||
The marker `pr_agent:type` will be replaced with the PR type, `pr_agent:summary` will be replaced with the PR summary, `pr_agent:walkthrough` will be replaced with the PR walkthrough, and `pr_agent:diagram` will be replaced with the sequence diagram (if enabled).
|
||||
|
||||
{width=512}
|
||||
|
||||
@ -184,6 +203,7 @@ becomes
|
||||
|
||||
- `use_description_markers`: if set to true, the tool will use markers template. It replaces every marker of the form `pr_agent:marker_name` with the relevant content. Default is false.
|
||||
- `include_generated_by_header`: if set to true, the tool will add a dedicated header: 'Generated by PR Agent at ...' to any automatic content. Default is true.
|
||||
- `diagram`: if present as a marker, will be replaced by the PR sequence diagram (if enabled).
|
||||
|
||||
## Custom labels
|
||||
|
||||
|
@ -437,9 +437,26 @@ dual_publishing_score_threshold = x
|
||||
|
||||
Where x represents the minimum score threshold (>=) for suggestions to be presented as committable PR comments in addition to the table. Default is -1 (disabled).
|
||||
|
||||
### Controlling suggestions depth
|
||||
|
||||
> `💎 feature`
|
||||
|
||||
You can control the depth and comprehensiveness of the code suggestions by using the `pr_code_suggestions.suggestions_depth` parameter.
|
||||
|
||||
Available options:
|
||||
|
||||
- `selective` - Shows only suggestions above a score threshold of 6
|
||||
- `regular` - Default mode with balanced suggestion coverage
|
||||
- `exhaustive` - Provides maximum suggestion comprehensiveness
|
||||
|
||||
(Alternatively, use numeric values: 1, 2, or 3 respectively)
|
||||
|
||||
We recommend starting with `regular` mode, then exploring `exhaustive` mode, which can provide more comprehensive suggestions and enhanced bug detection.
|
||||
|
||||
|
||||
### Self-review
|
||||
|
||||
> `💎 feature` Platforms supported: GitHub, GitLab
|
||||
> `💎 feature. Platforms supported: GitHub, GitLab`
|
||||
|
||||
If you set in a configuration file:
|
||||
|
||||
@ -521,6 +538,10 @@ Note: Chunking is primarily relevant for large PRs. For most PRs (up to 600 line
|
||||
<td><b>enable_chat_in_code_suggestions</b></td>
|
||||
<td>If set to true, QM bot will interact with comments made on code changes it has proposed. Default is true.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>suggestions_depth 💎</b></td>
|
||||
<td> Controls the depth of the suggestions. Can be set to 'selective', 'regular', or 'exhaustive'. Default is 'regular'.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>dual_publishing_score_threshold</b></td>
|
||||
<td>Minimum score threshold for suggestions to be presented as committable PR comments in addition to the table. Default is -1 (disabled).</td>
|
||||
|
@ -14,6 +14,7 @@ Here is a list of Qodo Merge tools, each with a dedicated page that explains how
|
||||
| **💎 [Add Documentation (`/add_docs`](./documentation.md))** | Generates documentation to methods/functions/classes that changed in the PR |
|
||||
| **💎 [Analyze (`/analyze`](./analyze.md))** | Identify code components that changed in the PR, and enables to interactively generate tests, docs, and code suggestions for each component |
|
||||
| **💎 [CI Feedback (`/checks ci_job`](./ci_feedback.md))** | Automatically generates feedback and analysis for a failed CI job |
|
||||
| **💎 [Compliance (`/compliance`](./compliance.md))** | Comprehensive compliance checks for security, ticket requirements, and custom organizational rules |
|
||||
| **💎 [Custom Prompt (`/custom_prompt`](./custom_prompt.md))** | Automatically generates custom suggestions for improving the PR code, based on specific guidelines defined by the user |
|
||||
| **💎 [Generate Custom Labels (`/generate_labels`](./custom_labels.md))** | Generates custom labels for the PR, based on specific guidelines defined by the user |
|
||||
| **💎 [Generate Tests (`/test`](./test.md))** | Automatically generates unit tests for a selected component, based on the PR code changes |
|
||||
|
@ -98,6 +98,11 @@ extra_instructions = "..."
|
||||
<tr>
|
||||
<td><b>require_security_review</b></td>
|
||||
<td>If set to true, the tool will add a section that checks if the PR contains a possible security or vulnerability issue. Default is true.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>require_todo_scan</b></td>
|
||||
<td>If set to true, the tool will add a section that lists TODO comments found in the PR code changes. Default is false.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><b>require_ticket_analysis_review</b></td>
|
||||
|
@ -250,3 +250,15 @@ Where the `ignore_pr_authors` is a list of usernames that you want to ignore.
|
||||
|
||||
!!! note
|
||||
There is one specific case where bots will receive an automatic response - when they generated a PR with a _failed test_. In that case, the [`ci_feedback`](https://qodo-merge-docs.qodo.ai/tools/ci_feedback/) tool will be invoked.
|
||||
|
||||
### Ignoring Generated Files by Language/Framework
|
||||
|
||||
To automatically exclude files generated by specific languages or frameworks, you can add the following to your `configuration.toml` file:
|
||||
|
||||
```
|
||||
[config]
|
||||
ignore_language_framework = ['protobuf', ...]
|
||||
```
|
||||
|
||||
You can view the list of auto-generated file patterns in [`generated_code_ignore.toml`](https://github.com/qodo-ai/pr-agent/blob/main/pr_agent/settings/generated_code_ignore.toml).
|
||||
Files matching these glob patterns will be automatically excluded from PR Agent analysis.
|
@ -30,7 +30,7 @@ verbosity_level=2
|
||||
This is useful for debugging or experimenting with different tools.
|
||||
|
||||
3. **git provider**: The [git_provider](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L5) field in a configuration file determines the GIT provider that will be used by Qodo Merge. Currently, the following providers are supported:
|
||||
`github` **(default)**, `gitlab`, `bitbucket`, `azure`, `codecommit`, `local`,`gitea`, and `gerrit`.
|
||||
`github` **(default)**, `gitlab`, `bitbucket`, `azure`, `codecommit`, `local`, and `gitea`.
|
||||
|
||||
### CLI Health Check
|
||||
|
||||
@ -202,6 +202,25 @@ publish_labels = false
|
||||
|
||||
to prevent Qodo Merge from publishing labels when running the `describe` tool.
|
||||
|
||||
#### Quick Reference: Model Configuration in GitHub Actions
|
||||
|
||||
For detailed step-by-step examples of configuring different models (Gemini, Claude, Azure OpenAI, etc.) in GitHub Actions, see the [Configuration Examples](../installation/github.md#configuration-examples) section in the installation guide.
|
||||
|
||||
**Common Model Configuration Patterns:**
|
||||
|
||||
- **OpenAI**: Set `config.model: "gpt-4o"` and `OPENAI_KEY`
|
||||
- **Gemini**: Set `config.model: "gemini/gemini-1.5-flash"` and `GOOGLE_AI_STUDIO.GEMINI_API_KEY` (no `OPENAI_KEY` needed)
|
||||
- **Claude**: Set `config.model: "anthropic/claude-3-opus-20240229"` and `ANTHROPIC.KEY` (no `OPENAI_KEY` needed)
|
||||
- **Azure OpenAI**: Set `OPENAI.API_TYPE: "azure"`, `OPENAI.API_BASE`, and `OPENAI.DEPLOYMENT_ID`
|
||||
- **Local Models**: Set `config.model: "ollama/model-name"` and `OLLAMA.API_BASE`
|
||||
|
||||
**Environment Variable Format:**
|
||||
- Use dots (`.`) to separate sections and keys: `config.model`, `pr_reviewer.extra_instructions`
|
||||
- Boolean values as strings: `"true"` or `"false"`
|
||||
- Arrays as JSON strings: `'["item1", "item2"]'`
|
||||
|
||||
For complete model configuration details, see [Changing a model in PR-Agent](changing_a_model.md).
|
||||
|
||||
### GitLab Webhook
|
||||
|
||||
After setting up a GitLab webhook, to control which commands will run automatically when a new MR is opened, you can set the `pr_commands` parameter in the configuration file, similar to the GitHub App:
|
||||
|
@ -32,6 +32,16 @@ OPENAI__API_BASE=https://api.openai.com/v1
|
||||
OPENAI__KEY=sk-...
|
||||
```
|
||||
|
||||
### OpenAI Flex Processing
|
||||
|
||||
To reduce costs for non-urgent/background tasks, enable Flex Processing:
|
||||
|
||||
```toml
|
||||
[litellm]
|
||||
extra_body='{"processing_mode": "flex"}'
|
||||
```
|
||||
|
||||
See [OpenAI Flex Processing docs](https://platform.openai.com/docs/guides/flex-processing) for details.
|
||||
|
||||
### Azure
|
||||
|
||||
@ -90,7 +100,7 @@ duplicate_examples=true # will duplicate the examples in the prompt, to help the
|
||||
api_base = "http://localhost:11434" # or whatever port you're running Ollama on
|
||||
```
|
||||
|
||||
By default, Ollama uses a context window size of 2048 tokens. In most cases this is not enough to cover pr-agent promt and pull-request diff. Context window size can be overridden with the `OLLAMA_CONTEXT_LENGTH` environment variable. For example, to set the default context length to 8K, use: `OLLAMA_CONTEXT_LENGTH=8192 ollama serve`. More information you can find on the [official ollama faq](https://github.com/ollama/ollama/blob/main/docs/faq.md#how-can-i-specify-the-context-window-size).
|
||||
By default, Ollama uses a context window size of 2048 tokens. In most cases this is not enough to cover pr-agent prompt and pull-request diff. Context window size can be overridden with the `OLLAMA_CONTEXT_LENGTH` environment variable. For example, to set the default context length to 8K, use: `OLLAMA_CONTEXT_LENGTH=8192 ollama serve`. More information you can find on the [official ollama faq](https://github.com/ollama/ollama/blob/main/docs/faq.md#how-can-i-specify-the-context-window-size).
|
||||
|
||||
Please note that the `custom_model_max_tokens` setting should be configured in accordance with the `OLLAMA_CONTEXT_LENGTH`. Failure to do so may result in unexpected model output.
|
||||
|
||||
@ -232,6 +242,14 @@ AWS_SECRET_ACCESS_KEY="..."
|
||||
AWS_REGION_NAME="..."
|
||||
```
|
||||
|
||||
You can also use the new Meta Llama 4 models available on Amazon Bedrock:
|
||||
|
||||
```toml
|
||||
[config] # in configuration.toml
|
||||
model="bedrock/us.meta.llama4-scout-17b-instruct-v1:0"
|
||||
fallback_models=["bedrock/us.meta.llama4-maverick-17b-instruct-v1:0"]
|
||||
```
|
||||
|
||||
See [litellm](https://docs.litellm.ai/docs/providers/bedrock#usage) documentation for more information about the environment variables required for Amazon Bedrock.
|
||||
|
||||
### DeepSeek
|
||||
|
@ -34,6 +34,7 @@ nav:
|
||||
- 💎 Add Documentation: 'tools/documentation.md'
|
||||
- 💎 Analyze: 'tools/analyze.md'
|
||||
- 💎 CI Feedback: 'tools/ci_feedback.md'
|
||||
- 💎 Compliance: 'tools/compliance.md'
|
||||
- 💎 Custom Prompt: 'tools/custom_prompt.md'
|
||||
- 💎 Generate Labels: 'tools/custom_labels.md'
|
||||
- 💎 Generate Tests: 'tools/test.md'
|
||||
@ -46,6 +47,7 @@ nav:
|
||||
- Auto approval: 'core-abilities/auto_approval.md'
|
||||
- Auto best practices: 'core-abilities/auto_best_practices.md'
|
||||
- Chat on code suggestions: 'core-abilities/chat_on_code_suggestions.md'
|
||||
- Chrome extension: 'chrome-extension/index.md'
|
||||
- Code validation: 'core-abilities/code_validation.md'
|
||||
# - Compression strategy: 'core-abilities/compression_strategy.md'
|
||||
- Dynamic context: 'core-abilities/dynamic_context.md'
|
||||
@ -57,11 +59,11 @@ nav:
|
||||
- RAG context enrichment: 'core-abilities/rag_context_enrichment.md'
|
||||
- Self-reflection: 'core-abilities/self_reflection.md'
|
||||
- Static code analysis: 'core-abilities/static_code_analysis.md'
|
||||
- Chrome Extension:
|
||||
- Qodo Merge Chrome Extension: 'chrome-extension/index.md'
|
||||
- Features: 'chrome-extension/features.md'
|
||||
- Data Privacy: 'chrome-extension/data_privacy.md'
|
||||
- Options: 'chrome-extension/options.md'
|
||||
# - Chrome Extension:
|
||||
# - Qodo Merge Chrome Extension: 'chrome-extension/index.md'
|
||||
# - Features: 'chrome-extension/features.md'
|
||||
# - Data Privacy: 'chrome-extension/data_privacy.md'
|
||||
# - Options: 'chrome-extension/options.md'
|
||||
- PR Benchmark:
|
||||
- PR Benchmark: 'pr_benchmark/index.md'
|
||||
- Recent Updates:
|
||||
|
@ -3,5 +3,5 @@
|
||||
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
||||
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
||||
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
||||
})(window,document,'script','dataLayer','GTM-M6PJSFV');</script>
|
||||
})(window,document,'script','dataLayer','GTM-5C9KZBM3');</script>
|
||||
<!-- End Google Tag Manager -->
|
||||
|
@ -51,7 +51,7 @@ class PRAgent:
|
||||
def __init__(self, ai_handler: partial[BaseAiHandler,] = LiteLLMAIHandler):
|
||||
self.ai_handler = ai_handler # will be initialized in run_action
|
||||
|
||||
async def handle_request(self, pr_url, request, notify=None) -> bool:
|
||||
async def _handle_request(self, pr_url, request, notify=None) -> bool:
|
||||
# First, apply repo specific settings if exists
|
||||
apply_repo_settings(pr_url)
|
||||
|
||||
@ -117,3 +117,10 @@ class PRAgent:
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
|
||||
async def handle_request(self, pr_url, request, notify=None) -> bool:
|
||||
try:
|
||||
return await self._handle_request(pr_url, request, notify)
|
||||
except:
|
||||
get_logger().exception("Failed to process the command.")
|
||||
return False
|
||||
|
@ -45,6 +45,7 @@ MAX_TOKENS = {
|
||||
'command-nightly': 4096,
|
||||
'deepseek/deepseek-chat': 128000, # 128K, but may be limited by config.max_model_tokens
|
||||
'deepseek/deepseek-reasoner': 64000, # 64K, but may be limited by config.max_model_tokens
|
||||
'openai/qwq-plus': 131072, # 131K context length, but may be limited by config.max_model_tokens
|
||||
'replicate/llama-2-70b-chat:2c1608e18606fad2812020dc541930f2d0495ce32eee50074220b87300bc16e1': 4096,
|
||||
'meta-llama/Llama-2-7b-chat-hf': 4096,
|
||||
'vertex_ai/codechat-bison': 6144,
|
||||
@ -62,19 +63,23 @@ MAX_TOKENS = {
|
||||
'vertex_ai/gemini-2.5-pro-preview-03-25': 1048576,
|
||||
'vertex_ai/gemini-2.5-pro-preview-05-06': 1048576,
|
||||
'vertex_ai/gemini-2.5-pro-preview-06-05': 1048576,
|
||||
'vertex_ai/gemini-2.5-pro': 1048576,
|
||||
'vertex_ai/gemini-1.5-flash': 1048576,
|
||||
'vertex_ai/gemini-2.0-flash': 1048576,
|
||||
'vertex_ai/gemini-2.5-flash-preview-04-17': 1048576,
|
||||
'vertex_ai/gemini-2.5-flash-preview-05-20': 1048576,
|
||||
'vertex_ai/gemini-2.5-flash': 1048576,
|
||||
'vertex_ai/gemma2': 8200,
|
||||
'gemini/gemini-1.5-pro': 1048576,
|
||||
'gemini/gemini-1.5-flash': 1048576,
|
||||
'gemini/gemini-2.0-flash': 1048576,
|
||||
'gemini/gemini-2.5-flash-preview-04-17': 1048576,
|
||||
'gemini/gemini-2.5-flash-preview-05-20': 1048576,
|
||||
'gemini/gemini-2.5-flash': 1048576,
|
||||
'gemini/gemini-2.5-pro-preview-03-25': 1048576,
|
||||
'gemini/gemini-2.5-pro-preview-05-06': 1048576,
|
||||
'gemini/gemini-2.5-pro-preview-06-05': 1048576,
|
||||
'gemini/gemini-2.5-pro': 1048576,
|
||||
'codechat-bison': 6144,
|
||||
'codechat-bison-32k': 32000,
|
||||
'anthropic.claude-instant-v1': 100000,
|
||||
@ -109,6 +114,8 @@ MAX_TOKENS = {
|
||||
'claude-3-5-sonnet': 100000,
|
||||
'groq/meta-llama/llama-4-scout-17b-16e-instruct': 131072,
|
||||
'groq/meta-llama/llama-4-maverick-17b-128e-instruct': 131072,
|
||||
'bedrock/us.meta.llama4-scout-17b-instruct-v1:0': 128000,
|
||||
'bedrock/us.meta.llama4-maverick-17b-instruct-v1:0': 128000,
|
||||
'groq/llama3-8b-8192': 8192,
|
||||
'groq/llama3-70b-8192': 8192,
|
||||
'groq/llama-3.1-8b-instant': 8192,
|
||||
@ -187,3 +194,8 @@ CLAUDE_EXTENDED_THINKING_MODELS = [
|
||||
"anthropic/claude-3-7-sonnet-20250219",
|
||||
"claude-3-7-sonnet-20250219"
|
||||
]
|
||||
|
||||
# Models that require streaming mode
|
||||
STREAMING_REQUIRED_MODELS = [
|
||||
"openai/qwq-plus"
|
||||
]
|
||||
|
@ -5,14 +5,16 @@ import requests
|
||||
from litellm import acompletion
|
||||
from tenacity import retry, retry_if_exception_type, retry_if_not_exception_type, stop_after_attempt
|
||||
|
||||
from pr_agent.algo import CLAUDE_EXTENDED_THINKING_MODELS, NO_SUPPORT_TEMPERATURE_MODELS, SUPPORT_REASONING_EFFORT_MODELS, USER_MESSAGE_ONLY_MODELS
|
||||
from pr_agent.algo import CLAUDE_EXTENDED_THINKING_MODELS, NO_SUPPORT_TEMPERATURE_MODELS, SUPPORT_REASONING_EFFORT_MODELS, USER_MESSAGE_ONLY_MODELS, STREAMING_REQUIRED_MODELS
|
||||
from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler
|
||||
from pr_agent.algo.ai_handlers.litellm_helpers import _handle_streaming_response, MockResponse, _get_azure_ad_token, \
|
||||
_process_litellm_extra_body
|
||||
from pr_agent.algo.utils import ReasoningEffort, get_version
|
||||
from pr_agent.config_loader import get_settings
|
||||
from pr_agent.log import get_logger
|
||||
import json
|
||||
|
||||
OPENAI_RETRIES = 5
|
||||
MODEL_RETRIES = 2
|
||||
|
||||
|
||||
class LiteLLMAIHandler(BaseAiHandler):
|
||||
@ -110,7 +112,7 @@ class LiteLLMAIHandler(BaseAiHandler):
|
||||
if get_settings().get("AZURE_AD.CLIENT_ID", None):
|
||||
self.azure = True
|
||||
# Generate access token using Azure AD credentials from settings
|
||||
access_token = self._get_azure_ad_token()
|
||||
access_token = _get_azure_ad_token()
|
||||
litellm.api_key = access_token
|
||||
openai.api_key = access_token
|
||||
|
||||
@ -131,7 +133,7 @@ class LiteLLMAIHandler(BaseAiHandler):
|
||||
self.api_base = openrouter_api_base
|
||||
litellm.api_base = openrouter_api_base
|
||||
|
||||
# Models that only use user meessage
|
||||
# Models that only use user message
|
||||
self.user_message_only_models = USER_MESSAGE_ONLY_MODELS
|
||||
|
||||
# Model that doesn't support temperature argument
|
||||
@ -143,25 +145,8 @@ class LiteLLMAIHandler(BaseAiHandler):
|
||||
# Models that support extended thinking
|
||||
self.claude_extended_thinking_models = CLAUDE_EXTENDED_THINKING_MODELS
|
||||
|
||||
def _get_azure_ad_token(self):
|
||||
"""
|
||||
Generates an access token using Azure AD credentials from settings.
|
||||
Returns:
|
||||
str: The access token
|
||||
"""
|
||||
from azure.identity import ClientSecretCredential
|
||||
try:
|
||||
credential = ClientSecretCredential(
|
||||
tenant_id=get_settings().azure_ad.tenant_id,
|
||||
client_id=get_settings().azure_ad.client_id,
|
||||
client_secret=get_settings().azure_ad.client_secret
|
||||
)
|
||||
# Get token for Azure OpenAI service
|
||||
token = credential.get_token("https://cognitiveservices.azure.com/.default")
|
||||
return token.token
|
||||
except Exception as e:
|
||||
get_logger().error(f"Failed to get Azure AD token: {e}")
|
||||
raise
|
||||
# Models that require streaming
|
||||
self.streaming_required_models = STREAMING_REQUIRED_MODELS
|
||||
|
||||
def prepare_logs(self, response, system, user, resp, finish_reason):
|
||||
response_log = response.dict().copy()
|
||||
@ -212,7 +197,7 @@ class LiteLLMAIHandler(BaseAiHandler):
|
||||
|
||||
return kwargs
|
||||
|
||||
def add_litellm_callbacks(selfs, kwargs) -> dict:
|
||||
def add_litellm_callbacks(self, kwargs) -> dict:
|
||||
captured_extra = []
|
||||
|
||||
def capture_logs(message):
|
||||
@ -275,7 +260,7 @@ class LiteLLMAIHandler(BaseAiHandler):
|
||||
|
||||
@retry(
|
||||
retry=retry_if_exception_type(openai.APIError) & retry_if_not_exception_type(openai.RateLimitError),
|
||||
stop=stop_after_attempt(OPENAI_RETRIES),
|
||||
stop=stop_after_attempt(MODEL_RETRIES),
|
||||
)
|
||||
async def chat_completion(self, model: str, system: str, user: str, temperature: float = 0.2, img_path: str = None):
|
||||
try:
|
||||
@ -364,13 +349,18 @@ class LiteLLMAIHandler(BaseAiHandler):
|
||||
raise ValueError(f"LITELLM.EXTRA_HEADERS contains invalid JSON: {str(e)}")
|
||||
kwargs["extra_headers"] = litellm_extra_headers
|
||||
|
||||
# Support for custom OpenAI body fields (e.g., Flex Processing)
|
||||
kwargs = _process_litellm_extra_body(kwargs)
|
||||
|
||||
get_logger().debug("Prompts", artifact={"system": system, "user": user})
|
||||
|
||||
if get_settings().config.verbosity_level >= 2:
|
||||
get_logger().info(f"\nSystem prompt:\n{system}")
|
||||
get_logger().info(f"\nUser prompt:\n{user}")
|
||||
|
||||
response = await acompletion(**kwargs)
|
||||
# Get completion with automatic streaming detection
|
||||
resp, finish_reason, response_obj = await self._get_completion(**kwargs)
|
||||
|
||||
except openai.RateLimitError as e:
|
||||
get_logger().error(f"Rate limit error during LLM inference: {e}")
|
||||
raise
|
||||
@ -380,19 +370,36 @@ class LiteLLMAIHandler(BaseAiHandler):
|
||||
except Exception as e:
|
||||
get_logger().warning(f"Unknown error during LLM inference: {e}")
|
||||
raise openai.APIError from e
|
||||
if response is None or len(response["choices"]) == 0:
|
||||
raise openai.APIError
|
||||
else:
|
||||
resp = response["choices"][0]['message']['content']
|
||||
finish_reason = response["choices"][0]["finish_reason"]
|
||||
get_logger().debug(f"\nAI response:\n{resp}")
|
||||
|
||||
# log the full response for debugging
|
||||
response_log = self.prepare_logs(response, system, user, resp, finish_reason)
|
||||
get_logger().debug("Full_response", artifact=response_log)
|
||||
get_logger().debug(f"\nAI response:\n{resp}")
|
||||
|
||||
# for CLI debugging
|
||||
if get_settings().config.verbosity_level >= 2:
|
||||
get_logger().info(f"\nAI response:\n{resp}")
|
||||
# log the full response for debugging
|
||||
response_log = self.prepare_logs(response_obj, system, user, resp, finish_reason)
|
||||
get_logger().debug("Full_response", artifact=response_log)
|
||||
|
||||
# for CLI debugging
|
||||
if get_settings().config.verbosity_level >= 2:
|
||||
get_logger().info(f"\nAI response:\n{resp}")
|
||||
|
||||
return resp, finish_reason
|
||||
|
||||
async def _get_completion(self, **kwargs):
|
||||
"""
|
||||
Wrapper that automatically handles streaming for required models.
|
||||
"""
|
||||
model = kwargs["model"]
|
||||
if model in self.streaming_required_models:
|
||||
kwargs["stream"] = True
|
||||
get_logger().info(f"Using streaming mode for model {model}")
|
||||
response = await acompletion(**kwargs)
|
||||
resp, finish_reason = await _handle_streaming_response(response)
|
||||
# Create MockResponse for streaming since we don't have the full response object
|
||||
mock_response = MockResponse(resp, finish_reason)
|
||||
return resp, finish_reason, mock_response
|
||||
else:
|
||||
response = await acompletion(**kwargs)
|
||||
if response is None or len(response["choices"]) == 0:
|
||||
raise openai.APIError
|
||||
return (response["choices"][0]['message']['content'],
|
||||
response["choices"][0]["finish_reason"],
|
||||
response)
|
||||
|
112
pr_agent/algo/ai_handlers/litellm_helpers.py
Normal file
112
pr_agent/algo/ai_handlers/litellm_helpers.py
Normal file
@ -0,0 +1,112 @@
|
||||
import json
|
||||
|
||||
import openai
|
||||
|
||||
from pr_agent.config_loader import get_settings
|
||||
from pr_agent.log import get_logger
|
||||
|
||||
|
||||
async def _handle_streaming_response(response):
|
||||
"""
|
||||
Handle streaming response from acompletion and collect the full response.
|
||||
|
||||
Args:
|
||||
response: The streaming response object from acompletion
|
||||
|
||||
Returns:
|
||||
tuple: (full_response_content, finish_reason)
|
||||
"""
|
||||
full_response = ""
|
||||
finish_reason = None
|
||||
|
||||
try:
|
||||
async for chunk in response:
|
||||
if chunk.choices and len(chunk.choices) > 0:
|
||||
choice = chunk.choices[0]
|
||||
delta = choice.delta
|
||||
content = getattr(delta, 'content', None)
|
||||
if content:
|
||||
full_response += content
|
||||
if choice.finish_reason:
|
||||
finish_reason = choice.finish_reason
|
||||
except Exception as e:
|
||||
get_logger().error(f"Error handling streaming response: {e}")
|
||||
raise
|
||||
|
||||
if not full_response and finish_reason is None:
|
||||
get_logger().warning("Streaming response resulted in empty content with no finish reason")
|
||||
raise openai.APIError("Empty streaming response received without proper completion")
|
||||
elif not full_response and finish_reason:
|
||||
get_logger().debug(f"Streaming response resulted in empty content but completed with finish_reason: {finish_reason}")
|
||||
raise openai.APIError(f"Streaming response completed with finish_reason '{finish_reason}' but no content received")
|
||||
return full_response, finish_reason
|
||||
|
||||
|
||||
class MockResponse:
|
||||
"""Mock response object for streaming models to enable consistent logging."""
|
||||
|
||||
def __init__(self, resp, finish_reason):
|
||||
self._data = {
|
||||
"choices": [
|
||||
{
|
||||
"message": {"content": resp},
|
||||
"finish_reason": finish_reason
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
def dict(self):
|
||||
return self._data
|
||||
|
||||
|
||||
def _get_azure_ad_token():
|
||||
"""
|
||||
Generates an access token using Azure AD credentials from settings.
|
||||
Returns:
|
||||
str: The access token
|
||||
"""
|
||||
from azure.identity import ClientSecretCredential
|
||||
try:
|
||||
credential = ClientSecretCredential(
|
||||
tenant_id=get_settings().azure_ad.tenant_id,
|
||||
client_id=get_settings().azure_ad.client_id,
|
||||
client_secret=get_settings().azure_ad.client_secret
|
||||
)
|
||||
# Get token for Azure OpenAI service
|
||||
token = credential.get_token("https://cognitiveservices.azure.com/.default")
|
||||
return token.token
|
||||
except Exception as e:
|
||||
get_logger().error(f"Failed to get Azure AD token: {e}")
|
||||
raise
|
||||
|
||||
|
||||
def _process_litellm_extra_body(kwargs: dict) -> dict:
|
||||
"""
|
||||
Process LITELLM.EXTRA_BODY configuration and update kwargs accordingly.
|
||||
|
||||
Args:
|
||||
kwargs: The current kwargs dictionary to update
|
||||
|
||||
Returns:
|
||||
Updated kwargs dictionary
|
||||
|
||||
Raises:
|
||||
ValueError: If extra_body contains invalid JSON, unsupported keys, or colliding keys
|
||||
"""
|
||||
allowed_extra_body_keys = {"processing_mode", "service_tier"}
|
||||
extra_body = getattr(getattr(get_settings(), "litellm", None), "extra_body", None)
|
||||
if extra_body:
|
||||
try:
|
||||
litellm_extra_body = json.loads(extra_body)
|
||||
if not isinstance(litellm_extra_body, dict):
|
||||
raise ValueError("LITELLM.EXTRA_BODY must be a JSON object")
|
||||
unsupported_keys = set(litellm_extra_body.keys()) - allowed_extra_body_keys
|
||||
if unsupported_keys:
|
||||
raise ValueError(f"LITELLM.EXTRA_BODY contains unsupported keys: {', '.join(unsupported_keys)}. Allowed keys: {', '.join(allowed_extra_body_keys)}")
|
||||
colliding_keys = kwargs.keys() & litellm_extra_body.keys()
|
||||
if colliding_keys:
|
||||
raise ValueError(f"LITELLM.EXTRA_BODY cannot override existing parameters: {', '.join(colliding_keys)}")
|
||||
kwargs.update(litellm_extra_body)
|
||||
except json.JSONDecodeError as e:
|
||||
raise ValueError(f"LITELLM.EXTRA_BODY contains invalid JSON: {str(e)}")
|
||||
return kwargs
|
@ -2,6 +2,7 @@ import fnmatch
|
||||
import re
|
||||
|
||||
from pr_agent.config_loader import get_settings
|
||||
from pr_agent.log import get_logger
|
||||
|
||||
|
||||
def filter_ignored(files, platform = 'github'):
|
||||
@ -17,7 +18,17 @@ def filter_ignored(files, platform = 'github'):
|
||||
glob_setting = get_settings().ignore.glob
|
||||
if isinstance(glob_setting, str): # --ignore.glob=[.*utils.py], --ignore.glob=.*utils.py
|
||||
glob_setting = glob_setting.strip('[]').split(",")
|
||||
patterns += [fnmatch.translate(glob) for glob in glob_setting]
|
||||
patterns += translate_globs_to_regexes(glob_setting)
|
||||
|
||||
code_generators = get_settings().config.get('ignore_language_framework', [])
|
||||
if isinstance(code_generators, str):
|
||||
get_logger().warning("'ignore_language_framework' should be a list. Skipping language framework filtering.")
|
||||
code_generators = []
|
||||
for cg in code_generators:
|
||||
glob_patterns = get_settings().generated_code.get(cg, [])
|
||||
if isinstance(glob_patterns, str):
|
||||
glob_patterns = [glob_patterns]
|
||||
patterns += translate_globs_to_regexes(glob_patterns)
|
||||
|
||||
# compile all valid patterns
|
||||
compiled_patterns = []
|
||||
@ -66,3 +77,11 @@ def filter_ignored(files, platform = 'github'):
|
||||
print(f"Could not filter file list: {e}")
|
||||
|
||||
return files
|
||||
|
||||
def translate_globs_to_regexes(globs: list):
|
||||
regexes = []
|
||||
for pattern in globs:
|
||||
regexes.append(fnmatch.translate(pattern))
|
||||
if pattern.startswith("**/"): # cover root-level files
|
||||
regexes.append(fnmatch.translate(pattern[3:]))
|
||||
return regexes
|
||||
|
@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import copy
|
||||
import difflib
|
||||
import hashlib
|
||||
@ -14,7 +15,7 @@ import traceback
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from importlib.metadata import PackageNotFoundError, version
|
||||
from typing import Any, List, Tuple
|
||||
from typing import Any, List, Tuple, TypedDict
|
||||
|
||||
import html2text
|
||||
import requests
|
||||
@ -37,21 +38,31 @@ def get_model(model_type: str = "model_weak") -> str:
|
||||
return get_settings().config.model_reasoning
|
||||
return get_settings().config.model
|
||||
|
||||
|
||||
class Range(BaseModel):
|
||||
line_start: int # should be 0-indexed
|
||||
line_end: int
|
||||
column_start: int = -1
|
||||
column_end: int = -1
|
||||
|
||||
|
||||
class ModelType(str, Enum):
|
||||
REGULAR = "regular"
|
||||
WEAK = "weak"
|
||||
REASONING = "reasoning"
|
||||
|
||||
|
||||
class TodoItem(TypedDict):
|
||||
relevant_file: str
|
||||
line_range: Tuple[int, int]
|
||||
content: str
|
||||
|
||||
|
||||
class PRReviewHeader(str, Enum):
|
||||
REGULAR = "## PR Reviewer Guide"
|
||||
INCREMENTAL = "## Incremental PR Reviewer Guide"
|
||||
|
||||
|
||||
class ReasoningEffort(str, Enum):
|
||||
HIGH = "high"
|
||||
MEDIUM = "medium"
|
||||
@ -59,7 +70,8 @@ class ReasoningEffort(str, Enum):
|
||||
|
||||
|
||||
class PRDescriptionHeader(str, Enum):
|
||||
CHANGES_WALKTHROUGH = "### **Changes walkthrough** 📝"
|
||||
DIAGRAM_WALKTHROUGH = "Diagram Walkthrough"
|
||||
FILE_WALKTHROUGH = "File Walkthrough"
|
||||
|
||||
|
||||
def get_setting(key: str) -> Any:
|
||||
@ -109,6 +121,7 @@ def unique_strings(input_list: List[str]) -> List[str]:
|
||||
seen.add(item)
|
||||
return unique_list
|
||||
|
||||
|
||||
def convert_to_markdown_v2(output_data: dict,
|
||||
gfm_supported: bool = True,
|
||||
incremental_review=None,
|
||||
@ -131,6 +144,7 @@ def convert_to_markdown_v2(output_data: dict,
|
||||
"Focused PR": "✨",
|
||||
"Relevant ticket": "🎫",
|
||||
"Security concerns": "🔒",
|
||||
"Todo sections": "📝",
|
||||
"Insights from user's answers": "📝",
|
||||
"Code feedback": "🤖",
|
||||
"Estimated effort to review [1-5]": "⏱️",
|
||||
@ -151,6 +165,7 @@ def convert_to_markdown_v2(output_data: dict,
|
||||
if gfm_supported:
|
||||
markdown_text += "<table>\n"
|
||||
|
||||
todo_summary = output_data['review'].pop('todo_summary', '')
|
||||
for key, value in output_data['review'].items():
|
||||
if value is None or value == '' or value == {} or value == []:
|
||||
if key.lower() not in ['can_be_split', 'key_issues_to_review']:
|
||||
@ -209,6 +224,23 @@ def convert_to_markdown_v2(output_data: dict,
|
||||
markdown_text += f"### {emoji} Security concerns\n\n"
|
||||
value = emphasize_header(value.strip(), only_markdown=True)
|
||||
markdown_text += f"{value}\n\n"
|
||||
elif 'todo sections' in key_nice.lower():
|
||||
if gfm_supported:
|
||||
markdown_text += "<tr><td>"
|
||||
if is_value_no(value):
|
||||
markdown_text += f"✅ <strong>No TODO sections</strong>"
|
||||
else:
|
||||
markdown_todo_items = format_todo_items(value, git_provider, gfm_supported)
|
||||
markdown_text += f"{emoji} <strong>TODO sections</strong>\n<br><br>\n"
|
||||
markdown_text += markdown_todo_items
|
||||
markdown_text += "</td></tr>\n"
|
||||
else:
|
||||
if is_value_no(value):
|
||||
markdown_text += f"### ✅ No TODO sections\n\n"
|
||||
else:
|
||||
markdown_todo_items = format_todo_items(value, git_provider, gfm_supported)
|
||||
markdown_text += f"### {emoji} TODO sections\n\n"
|
||||
markdown_text += markdown_todo_items
|
||||
elif 'can be split' in key_nice.lower():
|
||||
if gfm_supported:
|
||||
markdown_text += f"<tr><td>"
|
||||
@ -1253,14 +1285,35 @@ def process_description(description_full: str) -> Tuple[str, List]:
|
||||
if not description_full:
|
||||
return "", []
|
||||
|
||||
description_split = description_full.split(PRDescriptionHeader.CHANGES_WALKTHROUGH.value)
|
||||
base_description_str = description_split[0]
|
||||
changes_walkthrough_str = ""
|
||||
files = []
|
||||
if len(description_split) > 1:
|
||||
changes_walkthrough_str = description_split[1]
|
||||
# description_split = description_full.split(PRDescriptionHeader.FILE_WALKTHROUGH.value)
|
||||
if PRDescriptionHeader.FILE_WALKTHROUGH.value in description_full:
|
||||
try:
|
||||
# FILE_WALKTHROUGH are presented in a collapsible section in the description
|
||||
regex_pattern = r'<details.*?>\s*<summary>\s*<h3>\s*' + re.escape(PRDescriptionHeader.FILE_WALKTHROUGH.value) + r'\s*</h3>\s*</summary>'
|
||||
description_split = re.split(regex_pattern, description_full, maxsplit=1, flags=re.DOTALL)
|
||||
|
||||
# If the regex pattern is not found, fallback to the previous method
|
||||
if len(description_split) == 1:
|
||||
get_logger().debug("Could not find regex pattern for file walkthrough, falling back to simple split")
|
||||
description_split = description_full.split(PRDescriptionHeader.FILE_WALKTHROUGH.value, 1)
|
||||
except Exception as e:
|
||||
get_logger().warning(f"Failed to split description using regex, falling back to simple split: {e}")
|
||||
description_split = description_full.split(PRDescriptionHeader.FILE_WALKTHROUGH.value, 1)
|
||||
|
||||
if len(description_split) < 2:
|
||||
get_logger().error("Failed to split description into base and changes walkthrough", artifact={'description': description_full})
|
||||
return description_full.strip(), []
|
||||
|
||||
base_description_str = description_split[0].strip()
|
||||
changes_walkthrough_str = ""
|
||||
files = []
|
||||
if len(description_split) > 1:
|
||||
changes_walkthrough_str = description_split[1]
|
||||
else:
|
||||
get_logger().debug("No changes walkthrough found")
|
||||
else:
|
||||
get_logger().debug("No changes walkthrough found")
|
||||
base_description_str = description_full.strip()
|
||||
return base_description_str, []
|
||||
|
||||
try:
|
||||
if changes_walkthrough_str:
|
||||
@ -1283,7 +1336,7 @@ def process_description(description_full: str) -> Tuple[str, List]:
|
||||
try:
|
||||
if isinstance(file_data, tuple):
|
||||
file_data = file_data[0]
|
||||
pattern = r'<details>\s*<summary><strong>(.*?)</strong>\s*<dd><code>(.*?)</code>.*?</summary>\s*<hr>\s*(.*?)\s*<li>(.*?)</details>'
|
||||
pattern = r'<details>\s*<summary><strong>(.*?)</strong>\s*<dd><code>(.*?)</code>.*?</summary>\s*<hr>\s*(.*?)\s*(?:<li>|•)(.*?)</details>'
|
||||
res = re.search(pattern, file_data, re.DOTALL)
|
||||
if not res or res.lastindex != 4:
|
||||
pattern_back = r'<details>\s*<summary><strong>(.*?)</strong><dd><code>(.*?)</code>.*?</summary>\s*<hr>\s*(.*?)\n\n\s*(.*?)</details>'
|
||||
@ -1295,6 +1348,8 @@ def process_description(description_full: str) -> Tuple[str, List]:
|
||||
short_filename = res.group(1).strip()
|
||||
short_summary = res.group(2).strip()
|
||||
long_filename = res.group(3).strip()
|
||||
if long_filename.endswith('<ul>'):
|
||||
long_filename = long_filename[:-4].strip()
|
||||
long_summary = res.group(4).strip()
|
||||
long_summary = long_summary.replace('<br> *', '\n*').replace('<br>','').replace('\n','<br>')
|
||||
long_summary = h.handle(long_summary).strip()
|
||||
@ -1313,7 +1368,7 @@ def process_description(description_full: str) -> Tuple[str, List]:
|
||||
if '<code>...</code>' in file_data:
|
||||
pass # PR with many files. some did not get analyzed
|
||||
else:
|
||||
get_logger().error(f"Failed to parse description", artifact={'description': file_data})
|
||||
get_logger().warning(f"Failed to parse description", artifact={'description': file_data})
|
||||
except Exception as e:
|
||||
get_logger().exception(f"Failed to process description: {e}", artifact={'description': file_data})
|
||||
|
||||
@ -1367,3 +1422,47 @@ def set_file_languages(diff_files) -> List[FilePatchInfo]:
|
||||
get_logger().exception(f"Failed to set file languages: {e}")
|
||||
|
||||
return diff_files
|
||||
|
||||
def format_todo_item(todo_item: TodoItem, git_provider, gfm_supported) -> str:
|
||||
relevant_file = todo_item.get('relevant_file', '').strip()
|
||||
line_number = todo_item.get('line_number', '')
|
||||
content = todo_item.get('content', '')
|
||||
reference_link = git_provider.get_line_link(relevant_file, line_number, line_number)
|
||||
file_ref = f"{relevant_file} [{line_number}]"
|
||||
if reference_link:
|
||||
if gfm_supported:
|
||||
file_ref = f"<a href='{reference_link}'>{file_ref}</a>"
|
||||
else:
|
||||
file_ref = f"[{file_ref}]({reference_link})"
|
||||
|
||||
if content:
|
||||
return f"{file_ref}: {content.strip()}"
|
||||
else:
|
||||
# if content is empty, return only the file reference
|
||||
return file_ref
|
||||
|
||||
|
||||
def format_todo_items(value: list[TodoItem] | TodoItem, git_provider, gfm_supported) -> str:
|
||||
markdown_text = ""
|
||||
MAX_ITEMS = 5 # limit the number of items to display
|
||||
if gfm_supported:
|
||||
if isinstance(value, list):
|
||||
markdown_text += "<ul>\n"
|
||||
if len(value) > MAX_ITEMS:
|
||||
get_logger().debug(f"Truncating todo items to {MAX_ITEMS} items")
|
||||
value = value[:MAX_ITEMS]
|
||||
for todo_item in value:
|
||||
markdown_text += f"<li>{format_todo_item(todo_item, git_provider, gfm_supported)}</li>\n"
|
||||
markdown_text += "</ul>\n"
|
||||
else:
|
||||
markdown_text += f"<p>{format_todo_item(value, git_provider, gfm_supported)}</p>\n"
|
||||
else:
|
||||
if isinstance(value, list):
|
||||
if len(value) > MAX_ITEMS:
|
||||
get_logger().debug(f"Truncating todo items to {MAX_ITEMS} items")
|
||||
value = value[:MAX_ITEMS]
|
||||
for todo_item in value:
|
||||
markdown_text += f"- {format_todo_item(todo_item, git_provider, gfm_supported)}\n"
|
||||
else:
|
||||
markdown_text += f"- {format_todo_item(value, git_provider, gfm_supported)}\n"
|
||||
return markdown_text
|
@ -14,6 +14,7 @@ global_settings = Dynaconf(
|
||||
settings_files=[join(current_dir, f) for f in [
|
||||
"settings/configuration.toml",
|
||||
"settings/ignore.toml",
|
||||
"settings/generated_code_ignore.toml",
|
||||
"settings/language_extensions.toml",
|
||||
"settings/pr_reviewer_prompts.toml",
|
||||
"settings/pr_questions_prompts.toml",
|
||||
|
@ -22,6 +22,7 @@ try:
|
||||
from azure.devops.connection import Connection
|
||||
# noinspection PyUnresolvedReferences
|
||||
from azure.devops.released.git import (Comment, CommentThread, GitPullRequest, GitVersionDescriptor, GitClient, CommentThreadContext, CommentPosition)
|
||||
from azure.devops.released.work_item_tracking import WorkItemTrackingClient
|
||||
# noinspection PyUnresolvedReferences
|
||||
from azure.identity import DefaultAzureCredential
|
||||
from msrest.authentication import BasicAuthentication
|
||||
@ -39,7 +40,7 @@ class AzureDevopsProvider(GitProvider):
|
||||
"Azure DevOps provider is not available. Please install the required dependencies."
|
||||
)
|
||||
|
||||
self.azure_devops_client = self._get_azure_devops_client()
|
||||
self.azure_devops_client, self.azure_devops_board_client = self._get_azure_devops_client()
|
||||
self.diff_files = None
|
||||
self.workspace_slug = None
|
||||
self.repo_slug = None
|
||||
@ -379,7 +380,7 @@ class AzureDevopsProvider(GitProvider):
|
||||
pr_body = pr_body[:ind]
|
||||
|
||||
if len(pr_body) > MAX_PR_DESCRIPTION_AZURE_LENGTH:
|
||||
changes_walkthrough_text = PRDescriptionHeader.CHANGES_WALKTHROUGH.value
|
||||
changes_walkthrough_text = PRDescriptionHeader.FILE_WALKTHROUGH.value
|
||||
ind = pr_body.find(changes_walkthrough_text)
|
||||
if ind != -1:
|
||||
pr_body = pr_body[:ind]
|
||||
@ -566,7 +567,7 @@ class AzureDevopsProvider(GitProvider):
|
||||
return workspace_slug, repo_slug, pr_number
|
||||
|
||||
@staticmethod
|
||||
def _get_azure_devops_client() -> GitClient:
|
||||
def _get_azure_devops_client() -> Tuple[GitClient, WorkItemTrackingClient]:
|
||||
org = get_settings().azure_devops.get("org", None)
|
||||
pat = get_settings().azure_devops.get("pat", None)
|
||||
|
||||
@ -588,13 +589,12 @@ class AzureDevopsProvider(GitProvider):
|
||||
get_logger().error(f"No PAT found in settings, and Azure Default Authentication failed, error: {e}")
|
||||
raise
|
||||
|
||||
credentials = BasicAuthentication("", auth_token)
|
||||
|
||||
credentials = BasicAuthentication("", auth_token)
|
||||
azure_devops_connection = Connection(base_url=org, creds=credentials)
|
||||
azure_devops_client = azure_devops_connection.clients.get_git_client()
|
||||
azure_devops_board_client = azure_devops_connection.clients.get_work_item_tracking_client()
|
||||
|
||||
return azure_devops_client
|
||||
return azure_devops_client, azure_devops_board_client
|
||||
|
||||
def _get_repo(self):
|
||||
if self.repo is None:
|
||||
@ -635,4 +635,50 @@ class AzureDevopsProvider(GitProvider):
|
||||
last = commits[0]
|
||||
url = self.azure_devops_client.normalized_url + "/" + self.workspace_slug + "/_git/" + self.repo_slug + "/commit/" + last.commit_id
|
||||
return url
|
||||
|
||||
|
||||
def get_linked_work_items(self) -> list:
|
||||
"""
|
||||
Get linked work items from the PR.
|
||||
"""
|
||||
try:
|
||||
work_items = self.azure_devops_client.get_pull_request_work_item_refs(
|
||||
project=self.workspace_slug,
|
||||
repository_id=self.repo_slug,
|
||||
pull_request_id=self.pr_num,
|
||||
)
|
||||
ids = [work_item.id for work_item in work_items]
|
||||
if not work_items:
|
||||
return []
|
||||
items = self.get_work_items(ids)
|
||||
return items
|
||||
except Exception as e:
|
||||
get_logger().exception(f"Failed to get linked work items, error: {e}")
|
||||
return []
|
||||
|
||||
def get_work_items(self, work_item_ids: list) -> list:
|
||||
"""
|
||||
Get work items by their IDs.
|
||||
"""
|
||||
try:
|
||||
raw_work_items = self.azure_devops_board_client.get_work_items(
|
||||
project=self.workspace_slug,
|
||||
ids=work_item_ids,
|
||||
)
|
||||
work_items = []
|
||||
for item in raw_work_items:
|
||||
work_items.append(
|
||||
{
|
||||
"id": item.id,
|
||||
"title": item.fields.get("System.Title", ""),
|
||||
"url": item.url,
|
||||
"body": item.fields.get("System.Description", ""),
|
||||
"acceptance_criteria": item.fields.get(
|
||||
"Microsoft.VSTS.Common.AcceptanceCriteria", ""
|
||||
),
|
||||
"tags": item.fields.get("System.Tags", "").split("; ") if item.fields.get("System.Tags") else [],
|
||||
}
|
||||
)
|
||||
return work_items
|
||||
except Exception as e:
|
||||
get_logger().exception(f"Failed to get work items, error: {e}")
|
||||
return []
|
||||
|
@ -86,7 +86,7 @@ class BitbucketServerProvider(GitProvider):
|
||||
|
||||
def get_repo_settings(self):
|
||||
try:
|
||||
content = self.bitbucket_client.get_content_of_file(self.workspace_slug, self.repo_slug, ".pr_agent.toml", self.get_pr_branch())
|
||||
content = self.bitbucket_client.get_content_of_file(self.workspace_slug, self.repo_slug, ".pr_agent.toml")
|
||||
|
||||
return content
|
||||
except Exception as e:
|
||||
|
@ -103,7 +103,7 @@ def prepare_repo(url: urllib3.util.Url, project, refspec):
|
||||
repo_url = (f"{url.scheme}://{url.auth}@{url.host}:{url.port}/{project}")
|
||||
|
||||
directory = pathlib.Path(mkdtemp())
|
||||
clone(repo_url, directory),
|
||||
clone(repo_url, directory)
|
||||
fetch(repo_url, refspec, cwd=directory)
|
||||
checkout(cwd=directory)
|
||||
return directory
|
||||
|
38
pr_agent/servers/atlassian-connect-qodo-merge.json
Normal file
38
pr_agent/servers/atlassian-connect-qodo-merge.json
Normal file
@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "Qodo Merge",
|
||||
"description": "Qodo Merge",
|
||||
"key": "app_key",
|
||||
"vendor": {
|
||||
"name": "Qodo",
|
||||
"url": "https://qodo.ai"
|
||||
},
|
||||
"authentication": {
|
||||
"type": "jwt"
|
||||
},
|
||||
"baseUrl": "base_url",
|
||||
"lifecycle": {
|
||||
"installed": "/installed",
|
||||
"uninstalled": "/uninstalled"
|
||||
},
|
||||
"scopes": [
|
||||
"account",
|
||||
"repository:write",
|
||||
"pullrequest:write",
|
||||
"wiki"
|
||||
],
|
||||
"contexts": [
|
||||
"account"
|
||||
],
|
||||
"modules": {
|
||||
"webhooks": [
|
||||
{
|
||||
"event": "*",
|
||||
"url": "/webhook"
|
||||
}
|
||||
]
|
||||
},
|
||||
"links": {
|
||||
"privacy": "https://qodo.ai/privacy-policy",
|
||||
"terms": "https://qodo.ai/terms"
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import ast
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
from typing import List
|
||||
|
||||
import uvicorn
|
||||
@ -40,6 +41,88 @@ def handle_request(
|
||||
|
||||
background_tasks.add_task(inner)
|
||||
|
||||
def should_process_pr_logic(data) -> bool:
|
||||
try:
|
||||
pr_data = data.get("pullRequest", {})
|
||||
title = pr_data.get("title", "")
|
||||
|
||||
from_ref = pr_data.get("fromRef", {})
|
||||
source_branch = from_ref.get("displayId", "") if from_ref else ""
|
||||
|
||||
to_ref = pr_data.get("toRef", {})
|
||||
target_branch = to_ref.get("displayId", "") if to_ref else ""
|
||||
|
||||
author = pr_data.get("author", {})
|
||||
user = author.get("user", {}) if author else {}
|
||||
sender = user.get("name", "") if user else ""
|
||||
|
||||
repository = to_ref.get("repository", {}) if to_ref else {}
|
||||
project = repository.get("project", {}) if repository else {}
|
||||
project_key = project.get("key", "") if project else ""
|
||||
repo_slug = repository.get("slug", "") if repository else ""
|
||||
|
||||
repo_full_name = f"{project_key}/{repo_slug}" if project_key and repo_slug else ""
|
||||
pr_id = pr_data.get("id", None)
|
||||
|
||||
# To ignore PRs from specific repositories
|
||||
ignore_repos = get_settings().get("CONFIG.IGNORE_REPOSITORIES", [])
|
||||
if repo_full_name and ignore_repos:
|
||||
if any(re.search(regex, repo_full_name) for regex in ignore_repos):
|
||||
get_logger().info(f"Ignoring PR from repository '{repo_full_name}' due to 'config.ignore_repositories' setting")
|
||||
return False
|
||||
|
||||
# To ignore PRs from specific users
|
||||
ignore_pr_users = get_settings().get("CONFIG.IGNORE_PR_AUTHORS", [])
|
||||
if ignore_pr_users and sender:
|
||||
if any(re.search(regex, sender) for regex in ignore_pr_users):
|
||||
get_logger().info(f"Ignoring PR from user '{sender}' due to 'config.ignore_pr_authors' setting")
|
||||
return False
|
||||
|
||||
# To ignore PRs with specific titles
|
||||
if title:
|
||||
ignore_pr_title_re = get_settings().get("CONFIG.IGNORE_PR_TITLE", [])
|
||||
if not isinstance(ignore_pr_title_re, list):
|
||||
ignore_pr_title_re = [ignore_pr_title_re]
|
||||
if ignore_pr_title_re and any(re.search(regex, title) for regex in ignore_pr_title_re):
|
||||
get_logger().info(f"Ignoring PR with title '{title}' due to config.ignore_pr_title setting")
|
||||
return False
|
||||
|
||||
ignore_pr_source_branches = get_settings().get("CONFIG.IGNORE_PR_SOURCE_BRANCHES", [])
|
||||
ignore_pr_target_branches = get_settings().get("CONFIG.IGNORE_PR_TARGET_BRANCHES", [])
|
||||
if (ignore_pr_source_branches or ignore_pr_target_branches):
|
||||
if any(re.search(regex, source_branch) for regex in ignore_pr_source_branches):
|
||||
get_logger().info(
|
||||
f"Ignoring PR with source branch '{source_branch}' due to config.ignore_pr_source_branches settings")
|
||||
return False
|
||||
if any(re.search(regex, target_branch) for regex in ignore_pr_target_branches):
|
||||
get_logger().info(
|
||||
f"Ignoring PR with target branch '{target_branch}' due to config.ignore_pr_target_branches settings")
|
||||
return False
|
||||
|
||||
# Allow_only_specific_folders
|
||||
allowed_folders = get_settings().config.get("allow_only_specific_folders", [])
|
||||
if allowed_folders and pr_id and project_key and repo_slug:
|
||||
from pr_agent.git_providers.bitbucket_server_provider import BitbucketServerProvider
|
||||
bitbucket_server_url = get_settings().get("BITBUCKET_SERVER.URL", "")
|
||||
pr_url = f"{bitbucket_server_url}/projects/{project_key}/repos/{repo_slug}/pull-requests/{pr_id}"
|
||||
provider = BitbucketServerProvider(pr_url=pr_url)
|
||||
changed_files = provider.get_files()
|
||||
if changed_files:
|
||||
# Check if ALL files are outside allowed folders
|
||||
all_files_outside = True
|
||||
for file_path in changed_files:
|
||||
if any(file_path.startswith(folder) for folder in allowed_folders):
|
||||
all_files_outside = False
|
||||
break
|
||||
|
||||
if all_files_outside:
|
||||
get_logger().info(f"Ignoring PR because all files {changed_files} are outside allowed folders {allowed_folders}")
|
||||
return False
|
||||
except Exception as e:
|
||||
get_logger().error(f"Failed 'should_process_pr_logic': {e}")
|
||||
return True # On exception - we continue. Otherwise, we could just end up with filtering all PRs
|
||||
return True
|
||||
|
||||
@router.post("/")
|
||||
async def redirect_to_webhook():
|
||||
return RedirectResponse(url="/webhook")
|
||||
@ -73,6 +156,11 @@ async def handle_webhook(background_tasks: BackgroundTasks, request: Request):
|
||||
|
||||
if data["eventKey"] == "pr:opened":
|
||||
apply_repo_settings(pr_url)
|
||||
if not should_process_pr_logic(data):
|
||||
get_logger().info(f"PR ignored due to config settings", **log_context)
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "PR ignored by config"})
|
||||
)
|
||||
if get_settings().config.disable_auto_feedback: # auto commands for PR, and auto feedback is disabled
|
||||
get_logger().info(f"Auto feedback is disabled, skipping auto commands for PR {pr_url}", **log_context)
|
||||
return
|
||||
|
@ -3,8 +3,6 @@ import json
|
||||
import os
|
||||
from typing import Union
|
||||
|
||||
from dynaconf.utils import DynaBox
|
||||
|
||||
from pr_agent.agent.pr_agent import PRAgent
|
||||
from pr_agent.config_loader import get_settings
|
||||
from pr_agent.git_providers import get_git_provider
|
||||
@ -93,7 +91,7 @@ async def run_action():
|
||||
|
||||
for key in get_settings():
|
||||
setting = get_settings().get(key)
|
||||
if isinstance(setting, DynaBox):
|
||||
if str(type(setting)) == "<class 'dynaconf.utils.boxing.DynaBox'>":
|
||||
if key.lower() in ['pr_description', 'pr_code_suggestions', 'pr_reviewer']:
|
||||
if hasattr(setting, 'extra_instructions'):
|
||||
extra_instructions = setting.extra_instructions
|
||||
|
@ -23,5 +23,5 @@ app.include_router(router)
|
||||
handler = Mangum(app, lifespan="off")
|
||||
|
||||
|
||||
def serverless(event, context):
|
||||
return handler(event, context)
|
||||
def lambda_handler(event, context):
|
||||
return handler(event, context)
|
27
pr_agent/servers/gitlab_lambda_webhook.py
Normal file
27
pr_agent/servers/gitlab_lambda_webhook.py
Normal file
@ -0,0 +1,27 @@
|
||||
from fastapi import FastAPI
|
||||
from mangum import Mangum
|
||||
from starlette.middleware import Middleware
|
||||
from starlette_context.middleware import RawContextMiddleware
|
||||
|
||||
from pr_agent.servers.gitlab_webhook import router
|
||||
|
||||
try:
|
||||
from pr_agent.config_loader import apply_secrets_manager_config
|
||||
apply_secrets_manager_config()
|
||||
except Exception as e:
|
||||
try:
|
||||
from pr_agent.log import get_logger
|
||||
get_logger().debug(f"AWS Secrets Manager initialization failed, falling back to environment variables: {e}")
|
||||
except:
|
||||
# Fail completely silently if log module is not available
|
||||
pass
|
||||
|
||||
middleware = [Middleware(RawContextMiddleware)]
|
||||
app = FastAPI(middleware=middleware)
|
||||
app.include_router(router)
|
||||
|
||||
handler = Mangum(app, lifespan="off")
|
||||
|
||||
|
||||
def lambda_handler(event, context):
|
||||
return handler(event, context)
|
@ -234,6 +234,9 @@ async def gitlab_webhook(background_tasks: BackgroundTasks, request: Request):
|
||||
get_logger().info(f"Skipping draft MR: {url}")
|
||||
return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"}))
|
||||
|
||||
# Apply repo settings before checking push commands or handle_push_trigger
|
||||
apply_repo_settings(url)
|
||||
|
||||
commands_on_push = get_settings().get(f"gitlab.push_commands", {})
|
||||
handle_push_trigger = get_settings().get(f"gitlab.handle_push_trigger", False)
|
||||
if not commands_on_push or not handle_push_trigger:
|
||||
@ -282,8 +285,8 @@ def handle_ask_line(body, data):
|
||||
question = body.replace('/ask', '').strip()
|
||||
path = data['object_attributes']['position']['new_path']
|
||||
side = 'RIGHT' # if line_range_['start']['type'] == 'new' else 'LEFT'
|
||||
comment_id = data['object_attributes']["discussion_id"]
|
||||
get_logger().info("Handling line comment")
|
||||
_id = data['object_attributes']["discussion_id"]
|
||||
get_logger().info("Handling line ")
|
||||
body = f"/ask_line --line_start={start_line} --line_end={end_line} --side={side} --file_name={path} --comment_id={comment_id} {question}"
|
||||
except Exception as e:
|
||||
get_logger().error(f"Failed to handle ask line comment: {e}")
|
||||
|
@ -81,6 +81,7 @@ the tool will replace every marker of the form `pr_agent:marker_name` in the PR
|
||||
- `type`: the PR type.
|
||||
- `summary`: the PR summary.
|
||||
- `walkthrough`: the PR walkthrough.
|
||||
- `diagram`: the PR sequence diagram (if enabled).
|
||||
|
||||
Note that when markers are enabled, if the original PR description does not contain any markers, the tool will not alter the description at all.
|
||||
|
||||
|
@ -16,6 +16,10 @@ key = "" # Acquire through https://platform.openai.com
|
||||
#deployment_id = "" # The deployment name you chose when you deployed the engine
|
||||
#fallback_deployments = [] # For each fallback model specified in configuration.toml in the [config] section, specify the appropriate deployment_id
|
||||
|
||||
# OpenAI Flex Processing (optional, for cost savings)
|
||||
# [litellm]
|
||||
# extra_body='{"processing_mode": "flex"}'
|
||||
|
||||
[pinecone]
|
||||
api_key = "..."
|
||||
environment = "gcp-starter"
|
||||
|
@ -5,7 +5,7 @@ In addition to evaluating the suggestion correctness and importance, another sub
|
||||
|
||||
Examine each suggestion meticulously, assessing its quality, relevance, and accuracy within the context of PR. Keep in mind that the suggestions may vary in their correctness, accuracy and impact.
|
||||
Consider the following components of each suggestion:
|
||||
1. 'one_sentence_summary' - A one-liner summary summary of the suggestion's purpose
|
||||
1. 'one_sentence_summary' - A one-liner summary of the suggestion's purpose
|
||||
2. 'suggestion_content' - The suggestion content, explaining the proposed modification
|
||||
3. 'existing_code' - a code snippet from a __new hunk__ section in the PR code diff that the suggestion addresses
|
||||
4. 'improved_code' - a code snippet demonstrating how the 'existing_code' should be after the suggestion is applied
|
||||
|
@ -8,7 +8,7 @@
|
||||
# models
|
||||
model="o4-mini"
|
||||
fallback_models=["gpt-4.1"]
|
||||
#model_reasoning="o4-mini" # dedictated reasoning model for self-reflection
|
||||
#model_reasoning="o4-mini" # dedicated reasoning model for self-reflection
|
||||
#model_weak="gpt-4o" # optional, a weaker model to use for some easier tasks
|
||||
# CLI
|
||||
git_provider="github"
|
||||
@ -56,6 +56,7 @@ ignore_pr_source_branches = [] # a list of regular expressions of source branche
|
||||
ignore_pr_labels = [] # labels to ignore from PR agent when an PR is created
|
||||
ignore_pr_authors = [] # authors to ignore from PR agent when an PR is created
|
||||
ignore_repositories = [] # a list of regular expressions of repository full names (e.g. "org/repo") to ignore from PR agent processing
|
||||
ignore_language_framework = [] # a list of code-generation languages or frameworks (e.g. 'protobuf', 'go_gen') whose auto-generated source files will be excluded from analysis
|
||||
#
|
||||
is_auto_command = false # will be auto-set to true if the command is triggered by an automation
|
||||
enable_ai_metadata = false # will enable adding ai metadata
|
||||
@ -78,6 +79,7 @@ require_tests_review=true
|
||||
require_estimate_effort_to_review=true
|
||||
require_can_be_split_review=false
|
||||
require_security_review=true
|
||||
require_todo_scan=false
|
||||
require_ticket_analysis_review=true
|
||||
# general options
|
||||
publish_output_no_suggestions=true # Set to "false" if you only need the reviewer's remarks (not labels, not "security audit", etc.) and want to avoid noisy "No major issues detected" comments.
|
||||
@ -104,8 +106,8 @@ extra_instructions = ""
|
||||
enable_pr_type=true
|
||||
final_update_message = true
|
||||
enable_help_text=false
|
||||
enable_help_comment=true
|
||||
enable_pr_diagram=false # adds a section with a diagram of the PR changes
|
||||
enable_help_comment=false
|
||||
enable_pr_diagram=true # adds a section with a diagram of the PR changes
|
||||
# describe as comment
|
||||
publish_description_as_comment=false
|
||||
publish_description_as_comment_persistent=true
|
||||
|
42
pr_agent/settings/generated_code_ignore.toml
Normal file
42
pr_agent/settings/generated_code_ignore.toml
Normal file
@ -0,0 +1,42 @@
|
||||
[generated_code]
|
||||
|
||||
# Protocol Buffers
|
||||
protobuf = [
|
||||
"**/*.pb.go",
|
||||
"**/*.pb.cc",
|
||||
"**/*_pb2.py",
|
||||
"**/*.pb.swift",
|
||||
"**/*.pb.rb",
|
||||
"**/*.pb.php",
|
||||
"**/*.pb.h"
|
||||
]
|
||||
|
||||
# OpenAPI / Swagger stubs
|
||||
openapi = [
|
||||
"**/__generated__/**",
|
||||
"**/openapi_client/**",
|
||||
"**/openapi_server/**"
|
||||
]
|
||||
swagger = [
|
||||
"**/swagger.json",
|
||||
"**/swagger.yaml"
|
||||
]
|
||||
|
||||
# GraphQL codegen
|
||||
graphql = [
|
||||
"**/*.graphql.ts",
|
||||
"**/*.generated.ts",
|
||||
"**/*.graphql.js"
|
||||
]
|
||||
|
||||
# RPC / gRPC Generators
|
||||
grpc_python = ["**/*_grpc.py"]
|
||||
grpc_java = ["**/*Grpc.java"]
|
||||
grpc_csharp = ["**/*Grpc.cs"]
|
||||
grpc_typescript = ["**/*_grpc.ts", "**/*_grpc.js"]
|
||||
|
||||
# Go code generators
|
||||
go_gen = [
|
||||
"**/*_gen.go",
|
||||
"**/*generated.go"
|
||||
]
|
@ -1,11 +1,12 @@
|
||||
[pr_description_prompt]
|
||||
system="""You are PR-Reviewer, a language model designed to review a Git Pull Request (PR).
|
||||
Your task is to provide a full description for the PR content - type, description, title and files walkthrough.
|
||||
Your task is to provide a full description for the PR content: type, description, title, and files walkthrough.
|
||||
- Focus on the new PR code (lines starting with '+' in the 'PR Git Diff' section).
|
||||
- Keep in mind that the 'Previous title', 'Previous description' and 'Commit messages' sections may be partial, simplistic, non-informative or out of date. Hence, compare them to the PR diff code, and use them only as a reference.
|
||||
- The generated title and description should prioritize the most significant changes.
|
||||
- If needed, each YAML output should be in block scalar indicator ('|')
|
||||
- When quoting variables, names or file paths from the code, use backticks (`) instead of single quote (').
|
||||
- When needed, use '- ' as bullets
|
||||
|
||||
{%- if extra_instructions %}
|
||||
|
||||
@ -47,8 +48,8 @@ class PRDescription(BaseModel):
|
||||
description: str = Field(description="summarize the PR changes in up to four bullet points, each up to 8 words. For large PRs, add sub-bullets if needed. Order bullets by importance, with each bullet highlighting a key change group.")
|
||||
title: str = Field(description="a concise and descriptive title that captures the PR's main theme")
|
||||
{%- if enable_pr_diagram %}
|
||||
changes_diagram: str = Field(description="a horizontal diagram that represents the main PR changes, in the format of a valid mermaid LR flowchart. The diagram should be concise and easy to read. Leave empty if no diagram is relevant. To create robust Mermaid diagrams, follow this two-step process: (1) Declare the nodes: nodeID["node description"]. (2) Then define the links: nodeID1 -- "link text" --> nodeID2 ")
|
||||
{%- endif %}
|
||||
changes_diagram: str = Field(description='a horizontal diagram that represents the main PR changes, in the format of a valid mermaid LR flowchart. The diagram should be concise and easy to read. Leave empty if no diagram is relevant. To create robust Mermaid diagrams, follow this two-step process: (1) Declare the nodes: nodeID["node description"]. (2) Then define the links: nodeID1 -- "link text" --> nodeID2. Node description must always be surrounded with double quotation marks')
|
||||
'{%- endif %}
|
||||
{%- if enable_semantic_files_types %}
|
||||
pr_files: List[FileDescription] = Field(max_items=20, description="a list of all the files that were changed in the PR, and summary of their changes. Each file must be analyzed regardless of change size.")
|
||||
{%- endif %}
|
||||
@ -66,11 +67,11 @@ description: |
|
||||
title: |
|
||||
...
|
||||
{%- if enable_pr_diagram %}
|
||||
changes_diagram: |
|
||||
```mermaid
|
||||
flowchart LR
|
||||
...
|
||||
```
|
||||
changes_diagram: |
|
||||
```mermaid
|
||||
flowchart LR
|
||||
...
|
||||
```
|
||||
{%- endif %}
|
||||
{%- if enable_semantic_files_types %}
|
||||
pr_files:
|
||||
@ -154,11 +155,11 @@ description: |
|
||||
title: |
|
||||
...
|
||||
{%- if enable_pr_diagram %}
|
||||
changes_diagram: |
|
||||
```mermaid
|
||||
flowchart LR
|
||||
...
|
||||
```
|
||||
changes_diagram: |
|
||||
```mermaid
|
||||
flowchart LR
|
||||
...
|
||||
```
|
||||
{%- endif %}
|
||||
{%- if enable_semantic_files_types %}
|
||||
pr_files:
|
||||
@ -181,4 +182,4 @@ pr_files:
|
||||
|
||||
Response (should be a valid YAML, and nothing else):
|
||||
```yaml
|
||||
"""
|
||||
"""
|
||||
|
@ -1,12 +1,12 @@
|
||||
[pr_help_prompts]
|
||||
system="""You are Doc-helper, a language models designed to answer questions about a documentation website for an open-soure project called "PR-Agent" (recently renamed to "Qodo Merge").
|
||||
You will recieve a question, and the full documentation website content.
|
||||
You will receive a question, and the full documentation website content.
|
||||
Your goal is to provide the best answer to the question using the documentation provided.
|
||||
|
||||
Additional instructions:
|
||||
- Try to be short and concise in your answers. Try to give examples if needed.
|
||||
- The main tools of PR-Agent are 'describe', 'review', 'improve'. If there is ambiguity to which tool the user is referring to, prioritize snippets of these tools over others.
|
||||
- If the question has ambiguity and can relate to different tools or platfroms, provide the best answer possible based on what is available, but also state in your answer what additional information would be needed to give a more accurate answer.
|
||||
- If the question has ambiguity and can relate to different tools or platforms, provide the best answer possible based on what is available, but also state in your answer what additional information would be needed to give a more accurate answer.
|
||||
|
||||
|
||||
The output must be a YAML object equivalent to type $DocHelper, according to the following Pydantic definitions:
|
||||
|
@ -2,7 +2,7 @@
|
||||
system="""You are PR-Reviewer, a language model designed to review a Git Pull Request (PR).
|
||||
Given the PR Info and the PR Git Diff, generate 3 short questions about the PR code for the PR author.
|
||||
The goal of the questions is to help the language model understand the PR better, so the questions should be insightful, informative, non-trivial, and relevant to the PR.
|
||||
You should prefer asking yes\\no questions, or multiple choice questions. Also add at least one open-ended question, but make sure they are not too difficult, and can be answered in a sentence or two.
|
||||
You should prefer asking yes/no questions, or multiple choice questions. Also add at least one open-ended question, but make sure they are not too difficult, and can be answered in a sentence or two.
|
||||
|
||||
|
||||
Example output:
|
||||
|
@ -37,9 +37,9 @@ __new hunk__
|
||||
======
|
||||
|
||||
- In the format above, the diff is organized into separate '__new hunk__' and '__old hunk__' sections for each code chunk. '__new hunk__' contains the updated code, while '__old hunk__' shows the removed code. If no code was removed in a specific chunk, the __old hunk__ section will be omitted.
|
||||
- We also added line numbers for the '__new hunk__' code, to help you refer to the code lines in your suggestions. These line numbers are not part of the actual code, and should only used for reference.
|
||||
- We also added line numbers for the '__new hunk__' code, to help you refer to the code lines in your suggestions. These line numbers are not part of the actual code, and should only be used for reference.
|
||||
- Code lines are prefixed with symbols ('+', '-', ' '). The '+' symbol indicates new code added in the PR, the '-' symbol indicates code removed in the PR, and the ' ' symbol indicates unchanged code. \
|
||||
The review should address new code added in the PR code diff (lines starting with '+')
|
||||
The review should address new code added in the PR code diff (lines starting with '+').
|
||||
{%- if is_ai_metadata %}
|
||||
- If available, an AI-generated summary will appear and provide a high-level overview of the file changes. Note that this summary may not be fully accurate or complete.
|
||||
{%- endif %}
|
||||
@ -72,6 +72,13 @@ class KeyIssuesComponentLink(BaseModel):
|
||||
start_line: int = Field(description="The start line that corresponds to this issue in the relevant file")
|
||||
end_line: int = Field(description="The end line that corresponds to this issue in the relevant file")
|
||||
|
||||
{%- if require_todo_scan %}
|
||||
class TodoSection(BaseModel):
|
||||
relevant_file: str = Field(description="The full path of the file containing the TODO comment")
|
||||
line_number: int = Field(description="The line number where the TODO comment starts")
|
||||
content: str = Field(description="The content of the TODO comment. Only include actual TODO comments within code comments (e.g., comments starting with '#', '//', '/*', '<!--', ...). Remove leading 'TODO' prefixes. If more than 10 words, summarize the TODO comment to a single short sentence up to 10 words.")
|
||||
{%- endif %}
|
||||
|
||||
{%- if related_tickets %}
|
||||
|
||||
class TicketCompliance(BaseModel):
|
||||
@ -93,14 +100,17 @@ class Review(BaseModel):
|
||||
score: str = Field(description="Rate this PR on a scale of 0-100 (inclusive), where 0 means the worst possible PR code, and 100 means PR code of the highest quality, without any bugs or performance issues, that is ready to be merged immediately and run in production at scale.")
|
||||
{%- endif %}
|
||||
{%- if require_tests %}
|
||||
relevant_tests: str = Field(description="yes\\no question: does this PR have relevant tests added or updated ?")
|
||||
relevant_tests: str = Field(description="yes/no question: does this PR have relevant tests added or updated ?")
|
||||
{%- endif %}
|
||||
{%- if question_str %}
|
||||
insights_from_user_answers: str = Field(description="shortly summarize the insights you gained from the user's answers to the questions")
|
||||
{%- endif %}
|
||||
key_issues_to_review: List[KeyIssuesComponentLink] = Field("A short and diverse list (0-{{ num_max_findings }} issues) of high-priority bugs, problems or performance concerns introduced in the PR code, which the PR reviewer should further focus on and validate during the review process.")
|
||||
{%- if require_security_review %}
|
||||
security_concerns: str = Field(description="Does this PR code introduce possible vulnerabilities such as exposure of sensitive information (e.g., API keys, secrets, passwords), or security concerns like SQL injection, XSS, CSRF, and others ? Answer 'No' (without explaining why) if there are no possible issues. If there are security concerns or issues, start your answer with a short header, such as: 'Sensitive information exposure: ...', 'SQL injection: ...' etc. Explain your answer. Be specific and give examples if possible")
|
||||
security_concerns: str = Field(description="Does this PR code introduce vulnerabilities such as exposure of sensitive information (e.g., API keys, secrets, passwords), or security concerns like SQL injection, XSS, CSRF, and others ? Answer 'No' (without explaining why) if there are no possible issues. If there are security concerns or issues, start your answer with a short header, such as: 'Sensitive information exposure: ...', 'SQL injection: ...', etc. Explain your answer. Be specific and give examples if possible")
|
||||
{%- endif %}
|
||||
{%- if require_todo_scan %}
|
||||
todo_sections: Union[List[TodoSection], str] = Field(description="A list of TODO comments found in the PR code. Return 'No' (as a string) if there are no TODO comments in the PR")
|
||||
{%- endif %}
|
||||
{%- if require_can_be_split_review %}
|
||||
can_be_split: List[SubPR] = Field(min_items=0, max_items=3, description="Can this PR, which contains {{ num_pr_files }} changed files in total, be divided into smaller sub-PRs with distinct tasks that can be reviewed and merged independently, regardless of the order ? Make sure that the sub-PRs are indeed independent, with no code dependencies between them, and that each sub-PR represent a meaningful independent task. Output an empty list if the PR code does not need to be split.")
|
||||
@ -148,6 +158,10 @@ review:
|
||||
- ...
|
||||
security_concerns: |
|
||||
No
|
||||
{%- if require_todo_scan %}
|
||||
todo_sections: |
|
||||
No
|
||||
{%- endif %}
|
||||
{%- if require_can_be_split_review %}
|
||||
can_be_split:
|
||||
- relevant_files:
|
||||
@ -182,6 +196,13 @@ Ticket Description:
|
||||
{{ ticket.body }}
|
||||
#####
|
||||
{%- endif %}
|
||||
|
||||
{%- if ticket.requirements %}
|
||||
Ticket Requirements:
|
||||
#####
|
||||
{{ ticket.requirements }}
|
||||
#####
|
||||
{%- endif %}
|
||||
=====
|
||||
{% endfor %}
|
||||
{%- endif %}
|
||||
@ -266,6 +287,10 @@ review:
|
||||
- ...
|
||||
security_concerns: |
|
||||
No
|
||||
{%- if require_todo_scan %}
|
||||
todo_sections: |
|
||||
No
|
||||
{%- endif %}
|
||||
{%- if require_can_be_split_review %}
|
||||
can_be_split:
|
||||
- relevant_files:
|
||||
|
@ -614,11 +614,13 @@ class PRCodeSuggestions:
|
||||
break
|
||||
if original_initial_line:
|
||||
suggested_initial_line = new_code_snippet.splitlines()[0]
|
||||
original_initial_spaces = len(original_initial_line) - len(original_initial_line.lstrip())
|
||||
original_initial_spaces = len(original_initial_line) - len(original_initial_line.lstrip()) # lstrip works both for spaces and tabs
|
||||
suggested_initial_spaces = len(suggested_initial_line) - len(suggested_initial_line.lstrip())
|
||||
delta_spaces = original_initial_spaces - suggested_initial_spaces
|
||||
if delta_spaces > 0:
|
||||
new_code_snippet = textwrap.indent(new_code_snippet, delta_spaces * " ").rstrip('\n')
|
||||
# Detect indentation character from original line
|
||||
indent_char = '\t' if original_initial_line.startswith('\t') else ' '
|
||||
new_code_snippet = textwrap.indent(new_code_snippet, delta_spaces * indent_char).rstrip('\n')
|
||||
except Exception as e:
|
||||
get_logger().error(f"Error when dedenting code snippet for file {relevant_file}, error: {e}")
|
||||
|
||||
|
@ -59,6 +59,7 @@ class PRDescription:
|
||||
|
||||
# Initialize the variables dictionary
|
||||
self.COLLAPSIBLE_FILE_LIST_THRESHOLD = get_settings().pr_description.get("collapsible_file_list_threshold", 8)
|
||||
enable_pr_diagram = get_settings().pr_description.get("enable_pr_diagram", False) and self.git_provider.is_supported("gfm_markdown") # github and gitlab support gfm_markdown
|
||||
self.vars = {
|
||||
"title": self.git_provider.pr.title,
|
||||
"branch": self.git_provider.get_pr_branch(),
|
||||
@ -73,7 +74,7 @@ class PRDescription:
|
||||
"related_tickets": "",
|
||||
"include_file_summary_changes": len(self.git_provider.get_diff_files()) <= self.COLLAPSIBLE_FILE_LIST_THRESHOLD,
|
||||
"duplicate_prompt_examples": get_settings().config.get("duplicate_prompt_examples", False),
|
||||
"enable_pr_diagram": get_settings().pr_description.get("enable_pr_diagram", False),
|
||||
"enable_pr_diagram": enable_pr_diagram,
|
||||
}
|
||||
|
||||
self.user_description = self.git_provider.get_user_description()
|
||||
@ -127,7 +128,7 @@ class PRDescription:
|
||||
pr_title, pr_body, changes_walkthrough, pr_file_changes = self._prepare_pr_answer()
|
||||
if not self.git_provider.is_supported(
|
||||
"publish_file_comments") or not get_settings().pr_description.inline_file_summary:
|
||||
pr_body += "\n\n" + changes_walkthrough
|
||||
pr_body += "\n\n" + changes_walkthrough + "___\n\n"
|
||||
get_logger().debug("PR output", artifact={"title": pr_title, "body": pr_body})
|
||||
|
||||
# Add help text if gfm_markdown is supported
|
||||
@ -168,7 +169,7 @@ class PRDescription:
|
||||
|
||||
# publish description
|
||||
if get_settings().pr_description.publish_description_as_comment:
|
||||
full_markdown_description = f"## Title\n\n{pr_title}\n\n___\n{pr_body}"
|
||||
full_markdown_description = f"## Title\n\n{pr_title.strip()}\n\n___\n{pr_body}"
|
||||
if get_settings().pr_description.publish_description_as_comment_persistent:
|
||||
self.git_provider.publish_persistent_comment(full_markdown_description,
|
||||
initial_header="## Title",
|
||||
@ -178,7 +179,7 @@ class PRDescription:
|
||||
else:
|
||||
self.git_provider.publish_comment(full_markdown_description)
|
||||
else:
|
||||
self.git_provider.publish_description(pr_title, pr_body)
|
||||
self.git_provider.publish_description(pr_title.strip(), pr_body)
|
||||
|
||||
# publish final update message
|
||||
if (get_settings().pr_description.final_update_message and not get_settings().config.get('is_auto_command', False)):
|
||||
@ -330,7 +331,8 @@ class PRDescription:
|
||||
else:
|
||||
original_prediction_dict = original_prediction_loaded
|
||||
if original_prediction_dict:
|
||||
filenames_predicted = [file.get('filename', '').strip() for file in original_prediction_dict.get('pr_files', [])]
|
||||
files = original_prediction_dict.get('pr_files', [])
|
||||
filenames_predicted = [file.get('filename', '').strip() for file in files if isinstance(file, dict)]
|
||||
else:
|
||||
filenames_predicted = []
|
||||
|
||||
@ -537,6 +539,11 @@ class PRDescription:
|
||||
get_logger().error(f"Failing to process walkthrough {self.pr_id}: {e}")
|
||||
body = body.replace('pr_agent:walkthrough', "")
|
||||
|
||||
# Add support for pr_agent:diagram marker (plain and HTML comment formats)
|
||||
ai_diagram = self.data.get('changes_diagram')
|
||||
if ai_diagram:
|
||||
body = re.sub(r'<!--\s*pr_agent:diagram\s*-->|pr_agent:diagram', ai_diagram, body)
|
||||
|
||||
return title, body, walkthrough_gfm, pr_file_changes
|
||||
|
||||
def _prepare_pr_answer(self) -> Tuple[str, str, str, List[dict]]:
|
||||
@ -549,15 +556,11 @@ class PRDescription:
|
||||
"""
|
||||
|
||||
# Iterate over the dictionary items and append the key and value to 'markdown_text' in a markdown format
|
||||
markdown_text = ""
|
||||
# Don't display 'PR Labels'
|
||||
if 'labels' in self.data and self.git_provider.is_supported("get_labels"):
|
||||
self.data.pop('labels')
|
||||
if not get_settings().pr_description.enable_pr_type:
|
||||
self.data.pop('type')
|
||||
for key, value in self.data.items():
|
||||
markdown_text += f"## **{key}**\n\n"
|
||||
markdown_text += f"{value}\n\n"
|
||||
|
||||
# Remove the 'PR Title' key from the dictionary
|
||||
ai_title = self.data.pop('title', self.vars["title"])
|
||||
@ -573,6 +576,10 @@ class PRDescription:
|
||||
pr_body, changes_walkthrough = "", ""
|
||||
pr_file_changes = []
|
||||
for idx, (key, value) in enumerate(self.data.items()):
|
||||
if key == 'changes_diagram':
|
||||
pr_body += f"### {PRDescriptionHeader.DIAGRAM_WALKTHROUGH.value}\n\n"
|
||||
pr_body += f"{value}\n\n"
|
||||
continue
|
||||
if key == 'pr_files':
|
||||
value = self.file_label_dict
|
||||
else:
|
||||
@ -591,9 +598,15 @@ class PRDescription:
|
||||
pr_body += f'- `{filename}`: {description}\n'
|
||||
if self.git_provider.is_supported("gfm_markdown"):
|
||||
pr_body += "</details>\n"
|
||||
elif 'pr_files' in key.lower() and get_settings().pr_description.enable_semantic_files_types:
|
||||
changes_walkthrough, pr_file_changes = self.process_pr_files_prediction(changes_walkthrough, value)
|
||||
changes_walkthrough = f"{PRDescriptionHeader.CHANGES_WALKTHROUGH.value}\n{changes_walkthrough}"
|
||||
elif 'pr_files' in key.lower() and get_settings().pr_description.enable_semantic_files_types: # 'File Walkthrough' section
|
||||
changes_walkthrough_table, pr_file_changes = self.process_pr_files_prediction(changes_walkthrough, value)
|
||||
if get_settings().pr_description.get('file_table_collapsible_open_by_default', False):
|
||||
initial_status = " open"
|
||||
else:
|
||||
initial_status = ""
|
||||
changes_walkthrough = f"<details{initial_status}> <summary><h3> {PRDescriptionHeader.FILE_WALKTHROUGH.value}</h3></summary>\n\n"
|
||||
changes_walkthrough += f"{changes_walkthrough_table}\n\n"
|
||||
changes_walkthrough += "</details>\n\n"
|
||||
elif key.lower().strip() == 'description':
|
||||
if isinstance(value, list):
|
||||
value = ', '.join(v.rstrip() for v in value)
|
||||
@ -627,14 +640,19 @@ class PRDescription:
|
||||
artifact={"file": file})
|
||||
continue
|
||||
filename = file['filename'].replace("'", "`").replace('"', '`')
|
||||
changes_summary = file.get('changes_summary', "").strip()
|
||||
changes_summary = file.get('changes_summary', "")
|
||||
if not changes_summary:
|
||||
get_logger().warning(f"Empty changes summary in file label dict, skipping file",
|
||||
artifact={"file": file})
|
||||
continue
|
||||
changes_summary = changes_summary.strip()
|
||||
changes_title = file['changes_title'].strip()
|
||||
label = file.get('label').strip().lower()
|
||||
if label not in file_label_dict:
|
||||
file_label_dict[label] = []
|
||||
file_label_dict[label].append((filename, changes_title, changes_summary))
|
||||
except Exception as e:
|
||||
get_logger().error(f"Error preparing file label dict {self.pr_id}: {e}")
|
||||
get_logger().exception(f"Error preparing file label dict {self.pr_id}")
|
||||
pass
|
||||
return file_label_dict
|
||||
|
||||
@ -714,7 +732,7 @@ class PRDescription:
|
||||
pr_body += """</tr></tbody></table>"""
|
||||
|
||||
except Exception as e:
|
||||
get_logger().error(f"Error processing PR files to markdown {self.pr_id}: {str(e)}")
|
||||
get_logger().error(f"Error processing pr files to markdown {self.pr_id}: {str(e)}")
|
||||
pass
|
||||
return pr_body, pr_comments
|
||||
|
||||
@ -770,14 +788,21 @@ def insert_br_after_x_chars(text: str, x=70):
|
||||
if count_chars_without_html(text) < x:
|
||||
return text
|
||||
|
||||
is_list = text.lstrip().startswith(("- ", "* "))
|
||||
|
||||
# replace odd instances of ` with <code> and even instances of ` with </code>
|
||||
text = replace_code_tags(text)
|
||||
|
||||
# convert list items to <li>
|
||||
if text.startswith("- ") or text.startswith("* "):
|
||||
text = "<li>" + text[2:]
|
||||
text = text.replace("\n- ", '<br><li> ').replace("\n - ", '<br><li> ')
|
||||
text = text.replace("\n* ", '<br><li> ').replace("\n * ", '<br><li> ')
|
||||
# convert list items to <li> only if the text is identified as a list
|
||||
if is_list:
|
||||
# To handle lists that start with indentation
|
||||
leading_whitespace = text[:len(text) - len(text.lstrip())]
|
||||
body = text.lstrip()
|
||||
body = "<li>" + body[2:]
|
||||
text = leading_whitespace + body
|
||||
|
||||
text = text.replace("\n- ", '<br><li> ').replace("\n - ", '<br><li> ')
|
||||
text = text.replace("\n* ", '<br><li> ').replace("\n * ", '<br><li> ')
|
||||
|
||||
# convert new lines to <br>
|
||||
text = text.replace("\n", '<br>')
|
||||
@ -817,7 +842,13 @@ def insert_br_after_x_chars(text: str, x=70):
|
||||
is_inside_code = True
|
||||
if "</code>" in word:
|
||||
is_inside_code = False
|
||||
return ''.join(new_text).strip()
|
||||
|
||||
processed_text = ''.join(new_text).strip()
|
||||
|
||||
if is_list:
|
||||
processed_text = f"<ul>{processed_text}</ul>"
|
||||
|
||||
return processed_text
|
||||
|
||||
|
||||
def replace_code_tags(text):
|
||||
|
@ -21,7 +21,7 @@ from pr_agent.servers.help import HelpMessage
|
||||
|
||||
#Common code that can be called from similar tools:
|
||||
def modify_answer_section(ai_response: str) -> str | None:
|
||||
# Gets the model's answer and relevant sources section, repacing the heading of the answer section with:
|
||||
# Gets the model's answer and relevant sources section, replacing the heading of the answer section with:
|
||||
# :bulb: Auto-generated documentation-based answer:
|
||||
"""
|
||||
For example: The following input:
|
||||
|
@ -87,6 +87,7 @@ class PRReviewer:
|
||||
"require_estimate_effort_to_review": get_settings().pr_reviewer.require_estimate_effort_to_review,
|
||||
'require_can_be_split_review': get_settings().pr_reviewer.require_can_be_split_review,
|
||||
'require_security_review': get_settings().pr_reviewer.require_security_review,
|
||||
'require_todo_scan': get_settings().pr_reviewer.get("require_todo_scan", False),
|
||||
'question_str': question_str,
|
||||
'answer_str': answer_str,
|
||||
"extra_instructions": get_settings().pr_reviewer.extra_instructions,
|
||||
|
@ -3,6 +3,7 @@ import traceback
|
||||
|
||||
from pr_agent.config_loader import get_settings
|
||||
from pr_agent.git_providers import GithubProvider
|
||||
from pr_agent.git_providers import AzureDevopsProvider
|
||||
from pr_agent.log import get_logger
|
||||
|
||||
# Compile the regex pattern once, outside the function
|
||||
@ -131,6 +132,32 @@ async def extract_tickets(git_provider):
|
||||
|
||||
return tickets_content
|
||||
|
||||
elif isinstance(git_provider, AzureDevopsProvider):
|
||||
tickets_info = git_provider.get_linked_work_items()
|
||||
tickets_content = []
|
||||
for ticket in tickets_info:
|
||||
try:
|
||||
ticket_body_str = ticket.get("body", "")
|
||||
if len(ticket_body_str) > MAX_TICKET_CHARACTERS:
|
||||
ticket_body_str = ticket_body_str[:MAX_TICKET_CHARACTERS] + "..."
|
||||
|
||||
tickets_content.append(
|
||||
{
|
||||
"ticket_id": ticket.get("id"),
|
||||
"ticket_url": ticket.get("url"),
|
||||
"title": ticket.get("title"),
|
||||
"body": ticket_body_str,
|
||||
"requirements": ticket.get("acceptance_criteria", ""),
|
||||
"labels": ", ".join(ticket.get("labels", [])),
|
||||
}
|
||||
)
|
||||
except Exception as e:
|
||||
get_logger().error(
|
||||
f"Error processing Azure DevOps ticket: {e}",
|
||||
artifact={"traceback": traceback.format_exc()},
|
||||
)
|
||||
return tickets_content
|
||||
|
||||
except Exception as e:
|
||||
get_logger().error(f"Error extracting tickets error= {e}",
|
||||
artifact={"traceback": traceback.format_exc()})
|
||||
|
@ -1,10 +1,10 @@
|
||||
[build-system]
|
||||
requires = ["setuptools>=61.0"]
|
||||
requires = ["setuptools>=61.0", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "pr-agent"
|
||||
version = "0.2.7"
|
||||
version = "0.3.0"
|
||||
|
||||
authors = [{ name = "QodoAI", email = "tal.r@qodo.ai" }]
|
||||
|
||||
@ -16,7 +16,7 @@ description = "QodoAI PR-Agent aims to help efficiently review and handle pull r
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
keywords = ["AI", "Agents", "Pull Request", "Automation", "Code Review"]
|
||||
license = "Apache-2.0"
|
||||
license = { file = "LICENSE" }
|
||||
|
||||
classifiers = [
|
||||
"Intended Audience :: Developers",
|
||||
@ -34,7 +34,6 @@ dependencies = { file = ["requirements.txt"] }
|
||||
|
||||
[tool.setuptools]
|
||||
include-package-data = true
|
||||
license-files = ["LICENSE"]
|
||||
|
||||
[tool.setuptools.packages.find]
|
||||
where = ["."]
|
||||
|
92
tests/unittest/test_add_docs_trigger.py
Normal file
92
tests/unittest/test_add_docs_trigger.py
Normal file
@ -0,0 +1,92 @@
|
||||
import pytest
|
||||
from pr_agent.servers.github_app import handle_new_pr_opened
|
||||
from pr_agent.tools.pr_add_docs import PRAddDocs
|
||||
from pr_agent.agent.pr_agent import PRAgent
|
||||
from pr_agent.config_loader import get_settings
|
||||
from pr_agent.identity_providers.identity_provider import Eligibility
|
||||
from pr_agent.identity_providers import get_identity_provider
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
"action,draft,state,should_run",
|
||||
[
|
||||
("opened", False, "open", True),
|
||||
("edited", False, "open", False),
|
||||
("opened", True, "open", False),
|
||||
("opened", False, "closed", False),
|
||||
],
|
||||
)
|
||||
async def test_add_docs_trigger(monkeypatch, action, draft, state, should_run):
|
||||
# Mock settings to enable the "/add_docs" auto-command on PR opened
|
||||
settings = get_settings()
|
||||
settings.github_app.pr_commands = ["/add_docs"]
|
||||
settings.github_app.handle_pr_actions = ["opened"]
|
||||
|
||||
# Define a FakeGitProvider for both apply_repo_settings and PRAddDocs
|
||||
class FakeGitProvider:
|
||||
def __init__(self, pr_url, *args, **kwargs):
|
||||
self.pr = type("pr", (), {"title": "Test PR"})()
|
||||
self.get_pr_branch = lambda: "test-branch"
|
||||
self.get_pr_description = lambda: "desc"
|
||||
self.get_languages = lambda: ["Python"]
|
||||
self.get_files = lambda: []
|
||||
self.get_commit_messages = lambda: "msg"
|
||||
self.publish_comment = lambda *args, **kwargs: None
|
||||
self.remove_initial_comment = lambda: None
|
||||
self.publish_code_suggestions = lambda suggestions: True
|
||||
self.diff_files = []
|
||||
self.get_repo_settings = lambda: {}
|
||||
|
||||
# Patch Git provider lookups
|
||||
monkeypatch.setattr(
|
||||
"pr_agent.git_providers.utils.get_git_provider_with_context",
|
||||
lambda pr_url: FakeGitProvider(pr_url),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"pr_agent.tools.pr_add_docs.get_git_provider",
|
||||
lambda: FakeGitProvider,
|
||||
)
|
||||
|
||||
# Ensure identity provider always eligible
|
||||
monkeypatch.setattr(
|
||||
get_identity_provider().__class__,
|
||||
"verify_eligibility",
|
||||
lambda *args, **kwargs: Eligibility.ELIGIBLE,
|
||||
)
|
||||
|
||||
# Spy on PRAddDocs.run()
|
||||
ran = {"flag": False}
|
||||
|
||||
async def fake_run(self):
|
||||
ran["flag"] = True
|
||||
|
||||
monkeypatch.setattr(PRAddDocs, "run", fake_run)
|
||||
|
||||
# Build minimal PR payload
|
||||
body = {
|
||||
"action": action,
|
||||
"pull_request": {
|
||||
"url": "https://example.com/fake/pr",
|
||||
"state": state,
|
||||
"draft": draft,
|
||||
},
|
||||
}
|
||||
log_context = {}
|
||||
|
||||
# Invoke the PR-open handler
|
||||
agent = PRAgent()
|
||||
await handle_new_pr_opened(
|
||||
body=body,
|
||||
event="pull_request",
|
||||
sender="tester",
|
||||
sender_id="123",
|
||||
action=action,
|
||||
log_context=log_context,
|
||||
agent=agent,
|
||||
)
|
||||
|
||||
assert ran["flag"] is should_run, (
|
||||
f"Expected run() to be {'called' if should_run else 'skipped'}"
|
||||
f" for action={action!r}, draft={draft}, state={state!r}"
|
||||
)
|
@ -51,7 +51,7 @@ class TestConvertToMarkdown:
|
||||
input_data = {'review': {
|
||||
'estimated_effort_to_review_[1-5]': '1, because the changes are minimal and straightforward, focusing on a single functionality addition.\n',
|
||||
'relevant_tests': 'No\n', 'possible_issues': 'No\n', 'security_concerns': 'No\n'}}
|
||||
|
||||
|
||||
expected_output = textwrap.dedent(f"""\
|
||||
{PRReviewHeader.REGULAR.value} 🔍
|
||||
|
||||
@ -67,12 +67,12 @@ class TestConvertToMarkdown:
|
||||
""")
|
||||
|
||||
assert convert_to_markdown_v2(input_data).strip() == expected_output.strip()
|
||||
|
||||
|
||||
def test_simple_dictionary_input_without_gfm_supported(self):
|
||||
input_data = {'review': {
|
||||
'estimated_effort_to_review_[1-5]': '1, because the changes are minimal and straightforward, focusing on a single functionality addition.\n',
|
||||
'relevant_tests': 'No\n', 'possible_issues': 'No\n', 'security_concerns': 'No\n'}}
|
||||
|
||||
|
||||
expected_output = textwrap.dedent("""\
|
||||
## PR Reviewer Guide 🔍
|
||||
|
||||
@ -89,74 +89,74 @@ class TestConvertToMarkdown:
|
||||
""")
|
||||
|
||||
assert convert_to_markdown_v2(input_data, gfm_supported=False).strip() == expected_output.strip()
|
||||
|
||||
|
||||
def test_key_issues_to_review(self):
|
||||
input_data = {'review': {
|
||||
'key_issues_to_review': [
|
||||
{
|
||||
'relevant_file' : 'src/utils.py',
|
||||
'issue_header' : 'Code Smell',
|
||||
'issue_content' : 'The function is too long and complex.',
|
||||
'relevant_file': 'src/utils.py',
|
||||
'issue_header': 'Code Smell',
|
||||
'issue_content': 'The function is too long and complex.',
|
||||
'start_line': 30,
|
||||
'end_line': 50,
|
||||
}
|
||||
]
|
||||
}}
|
||||
mock_git_provider = Mock()
|
||||
reference_link = 'https://github.com/qodo/pr-agent/pull/1/files#diff-hashvalue-R174'
|
||||
reference_link = 'https://github.com/qodo/pr-agent/pull/1/files#diff-hashvalue-R174'
|
||||
mock_git_provider.get_line_link.return_value = reference_link
|
||||
|
||||
expected_output = textwrap.dedent(f"""\
|
||||
## PR Reviewer Guide 🔍
|
||||
|
||||
|
||||
Here are some key observations to aid the review process:
|
||||
|
||||
|
||||
<table>
|
||||
<tr><td>⚡ <strong>Recommended focus areas for review</strong><br><br>
|
||||
|
||||
|
||||
<a href='{reference_link}'><strong>Code Smell</strong></a><br>The function is too long and complex.
|
||||
|
||||
|
||||
</td></tr>
|
||||
</table>
|
||||
""")
|
||||
|
||||
|
||||
assert convert_to_markdown_v2(input_data, git_provider=mock_git_provider).strip() == expected_output.strip()
|
||||
mock_git_provider.get_line_link.assert_called_with('src/utils.py', 30, 50)
|
||||
|
||||
|
||||
def test_ticket_compliance(self):
|
||||
input_data = {'review': {
|
||||
'ticket_compliance_check': [
|
||||
{
|
||||
'ticket_url': 'https://example.com/ticket/123',
|
||||
'ticket_requirements': '- Requirement 1\n- Requirement 2\n',
|
||||
'fully_compliant_requirements': '- Requirement 1\n- Requirement 2\n',
|
||||
'ticket_requirements': '- Requirement 1\n- Requirement 2\n',
|
||||
'fully_compliant_requirements': '- Requirement 1\n- Requirement 2\n',
|
||||
'not_compliant_requirements': '',
|
||||
'requires_further_human_verification': '',
|
||||
}
|
||||
]
|
||||
}}
|
||||
|
||||
|
||||
expected_output = textwrap.dedent("""\
|
||||
## PR Reviewer Guide 🔍
|
||||
|
||||
|
||||
Here are some key observations to aid the review process:
|
||||
|
||||
|
||||
<table>
|
||||
<tr><td>
|
||||
|
||||
|
||||
**🎫 Ticket compliance analysis ✅**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
**[123](https://example.com/ticket/123) - Fully compliant**
|
||||
|
||||
|
||||
Compliant requirements:
|
||||
|
||||
|
||||
- Requirement 1
|
||||
- Requirement 2
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</td></tr>
|
||||
</table>
|
||||
""")
|
||||
@ -179,43 +179,43 @@ class TestConvertToMarkdown:
|
||||
],
|
||||
'title': 'Bug Fix',
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
expected_output = textwrap.dedent("""\
|
||||
## PR Reviewer Guide 🔍
|
||||
|
||||
|
||||
Here are some key observations to aid the review process:
|
||||
|
||||
<table>
|
||||
<tr><td>🔀 <strong>Multiple PR themes</strong><br><br>
|
||||
|
||||
|
||||
<details><summary>
|
||||
Sub-PR theme: <b>Refactoring</b></summary>
|
||||
|
||||
|
||||
___
|
||||
|
||||
|
||||
Relevant files:
|
||||
|
||||
|
||||
- src/file1.py
|
||||
- src/file2.py
|
||||
___
|
||||
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
<details><summary>
|
||||
Sub-PR theme: <b>Bug Fix</b></summary>
|
||||
|
||||
|
||||
___
|
||||
|
||||
|
||||
Relevant files:
|
||||
|
||||
|
||||
- src/file3.py
|
||||
___
|
||||
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
</td></tr>
|
||||
</table>
|
||||
""")
|
||||
@ -228,7 +228,6 @@ class TestConvertToMarkdown:
|
||||
|
||||
expected_output = ''
|
||||
|
||||
|
||||
assert convert_to_markdown_v2(input_data).strip() == expected_output.strip()
|
||||
|
||||
def test_dictionary_with_empty_dictionaries(self):
|
||||
@ -236,16 +235,16 @@ class TestConvertToMarkdown:
|
||||
|
||||
expected_output = ''
|
||||
|
||||
|
||||
assert convert_to_markdown_v2(input_data).strip() == expected_output.strip()
|
||||
|
||||
|
||||
class TestBR:
|
||||
def test_br1(self):
|
||||
file_change_description = '- Imported `FilePatchInfo` and `EDIT_TYPE` from `pr_agent.algo.types` instead of `pr_agent.git_providers.git_provider`.'
|
||||
file_change_description_br = insert_br_after_x_chars(file_change_description)
|
||||
expected_output = ('<li>Imported <code>FilePatchInfo</code> and <code>EDIT_TYPE</code> from '
|
||||
expected_output = ('<ul><li>Imported <code>FilePatchInfo</code> and <code>EDIT_TYPE</code> from '
|
||||
'<code>pr_agent.algo.types</code> instead <br>of '
|
||||
'<code>pr_agent.git_providers.git_provider</code>.')
|
||||
'<code>pr_agent.git_providers.git_provider</code>.</ul>')
|
||||
assert file_change_description_br == expected_output
|
||||
# print("-----")
|
||||
# print(file_change_description_br)
|
||||
@ -255,9 +254,9 @@ class TestBR:
|
||||
'- Created a - new -class `ColorPaletteResourcesCollection ColorPaletteResourcesCollection '
|
||||
'ColorPaletteResourcesCollection ColorPaletteResourcesCollection`')
|
||||
file_change_description_br = insert_br_after_x_chars(file_change_description)
|
||||
expected_output = ('<li>Created a - new -class <code>ColorPaletteResourcesCollection </code><br><code>'
|
||||
expected_output = ('<ul><li>Created a - new -class <code>ColorPaletteResourcesCollection </code><br><code>'
|
||||
'ColorPaletteResourcesCollection ColorPaletteResourcesCollection '
|
||||
'</code><br><code>ColorPaletteResourcesCollection</code>')
|
||||
'</code><br><code>ColorPaletteResourcesCollection</code></ul>')
|
||||
assert file_change_description_br == expected_output
|
||||
# print("-----")
|
||||
# print(file_change_description_br)
|
||||
|
@ -80,3 +80,53 @@ class TestIgnoreFilter:
|
||||
|
||||
filtered_files = filter_ignored(files)
|
||||
assert filtered_files == expected, f"Expected {[file.filename for file in expected]}, but got {[file.filename for file in filtered_files]}."
|
||||
|
||||
def test_language_framework_ignores(self, monkeypatch):
|
||||
"""
|
||||
Test files are ignored based on language/framework mapping (e.g., protobuf).
|
||||
"""
|
||||
monkeypatch.setattr(global_settings.config, 'ignore_language_framework', ['protobuf', 'go_gen'])
|
||||
|
||||
files = [
|
||||
type('', (object,), {'filename': 'main.go'})(),
|
||||
type('', (object,), {'filename': 'dir1/service.pb.go'})(),
|
||||
type('', (object,), {'filename': 'dir1/dir/data_pb2.py'})(),
|
||||
type('', (object,), {'filename': 'file.py'})(),
|
||||
type('', (object,), {'filename': 'dir2/file_gen.go'})(),
|
||||
type('', (object,), {'filename': 'file.generated.go'})()
|
||||
]
|
||||
expected = [
|
||||
files[0],
|
||||
files[3]
|
||||
]
|
||||
|
||||
filtered = filter_ignored(files)
|
||||
assert filtered == expected, (
|
||||
f"Expected {[f.filename for f in expected]}, "
|
||||
f"but got {[f.filename for f in filtered]}"
|
||||
)
|
||||
|
||||
def test_skip_invalid_ignore_language_framework(self, monkeypatch):
|
||||
"""
|
||||
Test skipping of generated code filtering when ignore_language_framework is not a list
|
||||
"""
|
||||
monkeypatch.setattr(global_settings.config, 'ignore_language_framework', 'protobuf')
|
||||
|
||||
files = [
|
||||
type('', (object,), {'filename': 'main.go'})(),
|
||||
type('', (object,), {'filename': 'file.py'})(),
|
||||
type('', (object,), {'filename': 'dir1/service.pb.go'})(),
|
||||
type('', (object,), {'filename': 'file_pb2.py'})()
|
||||
]
|
||||
expected = [
|
||||
files[0],
|
||||
files[1],
|
||||
files[2],
|
||||
files[3]
|
||||
]
|
||||
|
||||
filtered = filter_ignored(files)
|
||||
assert filtered == expected, (
|
||||
f"Expected {[f.filename for f in expected]}, "
|
||||
f"but got {[f.filename for f in filtered]}"
|
||||
)
|
||||
|
Reference in New Issue
Block a user