mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-13 01:00:39 +08:00
Compare commits
2 Commits
hussam789-
...
tr/static_
Author | SHA1 | Date | |
---|---|---|---|
88c2b90860 | |||
c84d84ace2 |
2
.github/workflows/build-and-test.yaml
vendored
2
.github/workflows/build-and-test.yaml
vendored
@ -37,3 +37,5 @@ jobs:
|
|||||||
name: Test dev docker
|
name: Test dev docker
|
||||||
run: |
|
run: |
|
||||||
docker run --rm codiumai/pr-agent:test pytest -v tests/unittest
|
docker run --rm codiumai/pr-agent:test pytest -v tests/unittest
|
||||||
|
|
||||||
|
|
||||||
|
3
.github/workflows/pr-agent-review.yaml
vendored
3
.github/workflows/pr-agent-review.yaml
vendored
@ -30,3 +30,6 @@ jobs:
|
|||||||
GITHUB_ACTION_CONFIG.AUTO_DESCRIBE: true
|
GITHUB_ACTION_CONFIG.AUTO_DESCRIBE: true
|
||||||
GITHUB_ACTION_CONFIG.AUTO_REVIEW: true
|
GITHUB_ACTION_CONFIG.AUTO_REVIEW: true
|
||||||
GITHUB_ACTION_CONFIG.AUTO_IMPROVE: true
|
GITHUB_ACTION_CONFIG.AUTO_IMPROVE: true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
17
.github/workflows/pre-commit.yml
vendored
17
.github/workflows/pre-commit.yml
vendored
@ -1,17 +0,0 @@
|
|||||||
# disabled. We might run it manually if needed.
|
|
||||||
name: pre-commit
|
|
||||||
|
|
||||||
on:
|
|
||||||
workflow_dispatch:
|
|
||||||
# pull_request:
|
|
||||||
# push:
|
|
||||||
# branches: [main]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
pre-commit:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- uses: actions/setup-python@v5
|
|
||||||
# SEE https://github.com/pre-commit/action
|
|
||||||
- uses: pre-commit/action@v3.0.1
|
|
@ -1,3 +1,6 @@
|
|||||||
[pr_reviewer]
|
[pr_reviewer]
|
||||||
enable_review_labels_effort = true
|
enable_review_labels_effort = true
|
||||||
enable_auto_approval = true
|
enable_auto_approval = true
|
||||||
|
|
||||||
|
[config]
|
||||||
|
model="claude-3-5-sonnet"
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
# See https://pre-commit.com for more information
|
|
||||||
# See https://pre-commit.com/hooks.html for more hooks
|
|
||||||
|
|
||||||
default_language_version:
|
|
||||||
python: python3
|
|
||||||
|
|
||||||
repos:
|
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
||||||
rev: v5.0.0
|
|
||||||
hooks:
|
|
||||||
- id: check-added-large-files
|
|
||||||
- id: check-toml
|
|
||||||
- id: check-yaml
|
|
||||||
- id: end-of-file-fixer
|
|
||||||
- id: trailing-whitespace
|
|
||||||
# - repo: https://github.com/rhysd/actionlint
|
|
||||||
# rev: v1.7.3
|
|
||||||
# hooks:
|
|
||||||
# - id: actionlint
|
|
||||||
- repo: https://github.com/pycqa/isort
|
|
||||||
# rev must match what's in dev-requirements.txt
|
|
||||||
rev: 5.13.2
|
|
||||||
hooks:
|
|
||||||
- id: isort
|
|
||||||
# - repo: https://github.com/PyCQA/bandit
|
|
||||||
# rev: 1.7.10
|
|
||||||
# hooks:
|
|
||||||
# - id: bandit
|
|
||||||
# args: [
|
|
||||||
# "-c", "pyproject.toml",
|
|
||||||
# ]
|
|
||||||
# - repo: https://github.com/astral-sh/ruff-pre-commit
|
|
||||||
# rev: v0.7.1
|
|
||||||
# hooks:
|
|
||||||
# - id: ruff
|
|
||||||
# args:
|
|
||||||
# - --fix
|
|
||||||
# - id: ruff-format
|
|
||||||
# - repo: https://github.com/PyCQA/autoflake
|
|
||||||
# rev: v2.3.1
|
|
||||||
# hooks:
|
|
||||||
# - id: autoflake
|
|
||||||
# args:
|
|
||||||
# - --in-place
|
|
||||||
# - --remove-all-unused-imports
|
|
||||||
# - --remove-unused-variables
|
|
@ -1,11 +1,10 @@
|
|||||||
FROM python:3.12 as base
|
FROM python:3.10 as base
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
ADD pyproject.toml .
|
ADD pyproject.toml .
|
||||||
ADD requirements.txt .
|
ADD requirements.txt .
|
||||||
RUN pip install . && rm pyproject.toml requirements.txt
|
RUN pip install . && rm pyproject.toml requirements.txt
|
||||||
ENV PYTHONPATH=/app
|
ENV PYTHONPATH=/app
|
||||||
ADD docs docs
|
|
||||||
ADD pr_agent pr_agent
|
ADD pr_agent pr_agent
|
||||||
ADD github_action/entrypoint.sh /
|
ADD github_action/entrypoint.sh /
|
||||||
RUN chmod +x /entrypoint.sh
|
RUN chmod +x /entrypoint.sh
|
||||||
|
83
README.md
83
README.md
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
</picture>
|
</picture>
|
||||||
<br/>
|
<br/>
|
||||||
Qode Merge PR-Agent aims to help efficiently review and handle pull requests, by providing AI feedback and suggestions
|
CodiumAI PR-Agent aims to help efficiently review and handle pull requests, by providing AI feedback and suggestions
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
[](https://github.com/Codium-ai/pr-agent/blob/main/LICENSE)
|
[](https://github.com/Codium-ai/pr-agent/blob/main/LICENSE)
|
||||||
@ -25,9 +25,9 @@ Qode Merge PR-Agent aims to help efficiently review and handle pull requests, by
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
### [Documentation](https://pr-agent-docs.codium.ai/)
|
### [Documentation](https://pr-agent-docs.codium.ai/)
|
||||||
- See the [Installation Guide](https://qodo-merge-docs.qodo.ai/installation/) for instructions on installing Qode Merge PR-Agent on different platforms.
|
- See the [Installation Guide](https://qodo-merge-docs.qodo.ai/installation/) for instructions on installing PR-Agent on different platforms.
|
||||||
|
|
||||||
- See the [Usage Guide](https://qodo-merge-docs.qodo.ai/usage-guide/) for instructions on running Qode Merge PR-Agent tools via different interfaces, such as CLI, PR Comments, or by automatically triggering them when a new PR is opened.
|
- See the [Usage Guide](https://qodo-merge-docs.qodo.ai/usage-guide/) for instructions on running PR-Agent tools via different interfaces, such as CLI, PR Comments, or by automatically triggering them when a new PR is opened.
|
||||||
|
|
||||||
- See the [Tools Guide](https://qodo-merge-docs.qodo.ai/tools/) for a detailed description of the different tools, and the available configurations for each tool.
|
- See the [Tools Guide](https://qodo-merge-docs.qodo.ai/tools/) for a detailed description of the different tools, and the available configurations for each tool.
|
||||||
|
|
||||||
@ -43,77 +43,47 @@ Qode Merge PR-Agent aims to help efficiently review and handle pull requests, by
|
|||||||
|
|
||||||
## News and Updates
|
## News and Updates
|
||||||
|
|
||||||
### November 7, 2024
|
### September 21, 2024
|
||||||
|
Need help with PR-Agent? New feature - simply comment `/help "your question"` in a pull request, and PR-Agent will provide you with the [relevant documentation](https://github.com/Codium-ai/pr-agent/pull/1241#issuecomment-2365259334).
|
||||||
|
|
||||||
Added new option: `--pr_code_suggestions.focus_only_on_problems=true`
|
<kbd><img src="https://www.codium.ai/images/pr_agent/pr_help_chat.png" width="768"></kbd>
|
||||||
|
|
||||||
When enabled, this option reduces the number of code suggestions and categorizes them into just two groups: "Possible Issues" and "General". The suggestions will focus primarily on identifying and fixing code problems, rather than style considerations like best practices, maintainability, or readability.
|
|
||||||
|
|
||||||
This mode is ideal for developers who want to concentrate specifically on finding and fixing potential bugs in their pull request code.
|
|
||||||
|
|
||||||
|
|
||||||
**Example results:**
|
### September 12, 2024
|
||||||
|
[Dynamic context](https://pr-agent-docs.codium.ai/core-abilities/dynamic_context/) is now the default option for context extension.
|
||||||
|
This feature enables PR-Agent to dynamically adjusting the relevant context for each code hunk, while avoiding overflowing the model with too much information.
|
||||||
|
|
||||||
Original mode
|
### September 3, 2024
|
||||||
|
|
||||||
<kbd><img src="https://qodo.ai/images/pr_agent/code_suggestions_original_mode.png" width="512"></kbd>
|
New version of PR-Agent, v0.24 was released. See the [release notes](https://github.com/Codium-ai/pr-agent/releases/tag/v0.24) for more information.
|
||||||
|
|
||||||
Focused mode
|
### August 26, 2024
|
||||||
|
|
||||||
<kbd><img src="https://qodo.ai/images/pr_agent/code_suggestions_focused_mode.png" width="512"></kbd>
|
New version of [PR Agent Chrome Extension](https://chromewebstore.google.com/detail/pr-agent-chrome-extension/ephlnjeghhogofkifjloamocljapahnl) was released, with full support of context-aware **PR Chat**. This novel feature is free to use for any open-source repository. See more details in [here](https://pr-agent-docs.codium.ai/chrome-extension/#pr-chat).
|
||||||
|
|
||||||
|
<kbd><img src="https://www.codium.ai/images/pr_agent/pr_chat_1.png" width="768"></kbd>
|
||||||
|
|
||||||
|
<kbd><img src="https://www.codium.ai/images/pr_agent/pr_chat_2.png" width="768"></kbd>
|
||||||
|
|
||||||
|
|
||||||
### November 4, 2024
|
### August 11, 2024
|
||||||
|
Increased PR context size for improved results, and enabled [asymmetric context](https://github.com/Codium-ai/pr-agent/pull/1114/files#diff-9290a3ad9a86690b31f0450b77acd37ef1914b41fabc8a08682d4da433a77f90R69-R70)
|
||||||
|
|
||||||
Qodo Merge PR Agent will now leverage context from Jira or GitHub tickets to enhance the PR Feedback. Read more about this feature
|
### August 10, 2024
|
||||||
[here](https://qodo-merge-docs.qodo.ai/core-abilities/fetching_ticket_context/)
|
Added support for [Azure devops pipeline](https://pr-agent-docs.codium.ai/installation/azure/) - you can now easily run PR-Agent as an Azure devops pipeline, without needing to set up your own server.
|
||||||
|
|
||||||
### November 3, 2024
|
|
||||||
|
|
||||||
Meaningful improvement to the quality of code suggestions by separating the code suggestion generation from [line number detection](https://github.com/Codium-ai/pr-agent/pull/1338)
|
|
||||||
|
|
||||||
<kbd></kbd>
|
|
||||||
|
|
||||||
|
|
||||||
### October 27, 2024
|
### August 5, 2024
|
||||||
|
Added support for [GitLab pipeline](https://pr-agent-docs.codium.ai/installation/gitlab/#run-as-a-gitlab-pipeline) - you can now run easily PR-Agent as a GitLab pipeline, without needing to set up your own server.
|
||||||
|
|
||||||
Qodo Merge PR Agent will now automatically document accepted code suggestions in a dedicated wiki page (`.pr_agent_accepted_suggestions`), enabling users to track historical changes, assess the tool's effectiveness, and learn from previously implemented recommendations in the repository.
|
### July 28, 2024
|
||||||
|
|
||||||
This dedicated wiki page will also serve as a foundation for future AI model improvements, allowing it to learn from historically implemented suggestions and generate more targeted, contextually relevant recommendations.
|
(1) improved support for bitbucket server - [auto commands](https://github.com/Codium-ai/pr-agent/pull/1059) and [direct links](https://github.com/Codium-ai/pr-agent/pull/1061)
|
||||||
Read more about this novel feature [here](https://qodo-merge-docs.qodo.ai/tools/improve/#suggestion-tracking).
|
|
||||||
|
|
||||||
<kbd><img href="https://qodo.ai/images/pr_agent/pr_agent_accepted_suggestions1.png" src="https://qodo.ai/images/pr_agent/pr_agent_accepted_suggestions1.png" width="768"></kbd>
|
(2) custom models are now [supported](https://pr-agent-docs.codium.ai/usage-guide/changing_a_model/#custom-models)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### October 21, 2024
|
|
||||||
**Disable publishing labels by default:**
|
|
||||||
|
|
||||||
The default setting for `pr_description.publish_labels` has been updated to `false`. This means that labels generated by the `/describe` tool will no longer be published, unless this configuration is explicitly set to `true`.
|
|
||||||
|
|
||||||
We constantly strive to balance informative AI analysis with reducing unnecessary noise. User feedback indicated that in many cases, the original PR title alone provides sufficient information, making the generated labels (`enhancement`, `documentation`, `bug fix`, ...) redundant.
|
|
||||||
The [`review_effort`](https://qodo-merge-docs.qodo.ai/tools/review/#configuration-options) label, generated by the `review` tool, will still be published by default, as it provides valuable information enabling reviewers to prioritize small PRs first.
|
|
||||||
|
|
||||||
However, every user has different preferences. To still publish the `describe` labels, set `pr_description.publish_labels=true` in the [configuration file](https://qodo-merge-docs.qodo.ai/usage-guide/configuration_options/).
|
|
||||||
For more tailored and relevant labeling, we recommend using the [`custom_labels 💎`](https://qodo-merge-docs.qodo.ai/tools/custom_labels/) tool, that allows generating labels specific to your project's needs.
|
|
||||||
|
|
||||||
<kbd></kbd>
|
|
||||||
|
|
||||||
→
|
|
||||||
|
|
||||||
<kbd></kbd>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### October 14, 2024
|
|
||||||
Improved support for GitHub enterprise server with [GitHub Actions](https://qodo-merge-docs.qodo.ai/installation/github/#action-for-github-enterprise-server)
|
|
||||||
|
|
||||||
### October 10, 2024
|
|
||||||
New ability for the `review` tool - **ticket compliance feedback**. If the PR contains a ticket number, PR-Agent will check if the PR code actually [complies](https://github.com/Codium-ai/pr-agent/pull/1279#issuecomment-2404042130) with the ticket requirements.
|
|
||||||
|
|
||||||
<kbd><img src="https://github.com/user-attachments/assets/4a2a728b-5f47-40fa-80cc-16efd296938c" width="768"></kbd>
|
|
||||||
|
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
<div style="text-align:left;">
|
<div style="text-align:left;">
|
||||||
|
|
||||||
@ -123,6 +93,7 @@ Supported commands per platform:
|
|||||||
|-------|---------------------------------------------------------------------------------------------------------|:--------------------:|:--------------------:|:--------------------:|:------------:|
|
|-------|---------------------------------------------------------------------------------------------------------|:--------------------:|:--------------------:|:--------------------:|:------------:|
|
||||||
| TOOLS | Review | ✅ | ✅ | ✅ | ✅ |
|
| TOOLS | Review | ✅ | ✅ | ✅ | ✅ |
|
||||||
| | ⮑ Incremental | ✅ | | | |
|
| | ⮑ Incremental | ✅ | | | |
|
||||||
|
| | ⮑ [SOC2 Compliance](https://pr-agent-docs.codium.ai/tools/review/#soc2-ticket-compliance) 💎 | ✅ | ✅ | ✅ | |
|
||||||
| | Describe | ✅ | ✅ | ✅ | ✅ |
|
| | Describe | ✅ | ✅ | ✅ | ✅ |
|
||||||
| | ⮑ [Inline File Summary](https://pr-agent-docs.codium.ai/tools/describe#inline-file-summary) 💎 | ✅ | | | |
|
| | ⮑ [Inline File Summary](https://pr-agent-docs.codium.ai/tools/describe#inline-file-summary) 💎 | ✅ | | | |
|
||||||
| | Improve | ✅ | ✅ | ✅ | ✅ |
|
| | Improve | ✅ | ✅ | ✅ | ✅ |
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
FROM python:3.12.3 AS base
|
FROM python:3.12.3 AS base
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
ADD docs/chroma_db.zip /app/docs/chroma_db.zip
|
||||||
ADD pyproject.toml .
|
ADD pyproject.toml .
|
||||||
ADD requirements.txt .
|
ADD requirements.txt .
|
||||||
ADD docs docs
|
|
||||||
RUN pip install . && rm pyproject.toml requirements.txt
|
RUN pip install . && rm pyproject.toml requirements.txt
|
||||||
ENV PYTHONPATH=/app
|
ENV PYTHONPATH=/app
|
||||||
|
|
||||||
|
BIN
docs/chroma_db.zip
Normal file
BIN
docs/chroma_db.zip
Normal file
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 15 KiB |
@ -1 +1,140 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?><svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 109.77 81.94"><defs><style>.cls-1{fill:#7968fa;}.cls-1,.cls-2{stroke-width:0px;}.cls-2{fill:#5ae3ae;}</style></defs><path class="cls-2" d="m109.77,40.98c0,22.62-7.11,40.96-15.89,40.96-3.6,0-6.89-3.09-9.58-8.31,6.82-7.46,11.22-19.3,11.22-32.64s-4.4-25.21-11.22-32.67C86.99,3.09,90.29,0,93.89,0c8.78,0,15.89,18.33,15.89,40.97"/><path class="cls-1" d="m95.53,40.99c0,13.35-4.4,25.19-11.23,32.64-3.81-7.46-6.28-19.3-6.28-32.64s2.47-25.21,6.28-32.67c6.83,7.46,11.23,19.32,11.23,32.67"/><path class="cls-2" d="m55.38,78.15c-4.99,2.42-10.52,3.79-16.38,3.79C17.46,81.93,0,63.6,0,40.98S17.46,0,39,0C44.86,0,50.39,1.37,55.38,3.79c-9.69,6.47-16.43,20.69-16.43,37.19s6.73,30.7,16.43,37.17"/><path class="cls-1" d="m78.02,40.99c0,16.48-9.27,30.7-22.65,37.17-9.69-6.47-16.43-20.69-16.43-37.17S45.68,10.28,55.38,3.81c13.37,6.49,22.65,20.69,22.65,37.19"/><path class="cls-2" d="m84.31,73.63c-4.73,5.22-10.64,8.31-17.06,8.31-4.24,0-8.27-1.35-11.87-3.79,13.37-6.48,22.65-20.7,22.65-37.17,0,13.35,2.47,25.19,6.28,32.64"/><path class="cls-2" d="m84.31,8.31c-3.81,7.46-6.28,19.32-6.28,32.67,0-16.5-9.27-30.7-22.65-37.19,3.6-2.45,7.63-3.8,11.87-3.8,6.43,0,12.33,3.09,17.06,8.31"/></svg>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Generator: Adobe Illustrator 28.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||||
|
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||||
|
width="64px" height="64px" viewBox="0 0 64 64" enable-background="new 0 0 64 64" xml:space="preserve">
|
||||||
|
<g>
|
||||||
|
<defs>
|
||||||
|
<rect id="SVGID_1_" x="0.4" y="0.1" width="63.4" height="63.4"/>
|
||||||
|
</defs>
|
||||||
|
<clipPath id="SVGID_00000008836131916906499950000015813697852011234749_">
|
||||||
|
<use xlink:href="#SVGID_1_" overflow="visible"/>
|
||||||
|
</clipPath>
|
||||||
|
<g clip-path="url(#SVGID_00000008836131916906499950000015813697852011234749_)">
|
||||||
|
<path fill="#05E5AD" d="M21.4,9.8c3,0,5.9,0.7,8.5,1.9c-5.7,3.4-9.8,11.1-9.8,20.1c0,9,4,16.7,9.8,20.1c-2.6,1.2-5.5,1.9-8.5,1.9
|
||||||
|
c-11.6,0-21-9.8-21-22S9.8,9.8,21.4,9.8z"/>
|
||||||
|
|
||||||
|
<radialGradient id="SVGID_00000150822754378345238340000008985053211526864828_" cx="-140.0905" cy="350.1757" r="4.8781" gradientTransform="matrix(-4.7708 -6.961580e-02 -0.1061 7.2704 -601.3099 -2523.8489)" gradientUnits="userSpaceOnUse">
|
||||||
|
<stop offset="0" style="stop-color:#6447FF"/>
|
||||||
|
<stop offset="6.666670e-02" style="stop-color:#6348FE"/>
|
||||||
|
<stop offset="0.1333" style="stop-color:#614DFC"/>
|
||||||
|
<stop offset="0.2" style="stop-color:#5C54F8"/>
|
||||||
|
<stop offset="0.2667" style="stop-color:#565EF3"/>
|
||||||
|
<stop offset="0.3333" style="stop-color:#4E6CEC"/>
|
||||||
|
<stop offset="0.4" style="stop-color:#447BE4"/>
|
||||||
|
<stop offset="0.4667" style="stop-color:#3A8DDB"/>
|
||||||
|
<stop offset="0.5333" style="stop-color:#2F9FD1"/>
|
||||||
|
<stop offset="0.6" style="stop-color:#25B1C8"/>
|
||||||
|
<stop offset="0.6667" style="stop-color:#1BC0C0"/>
|
||||||
|
<stop offset="0.7333" style="stop-color:#13CEB9"/>
|
||||||
|
<stop offset="0.8" style="stop-color:#0DD8B4"/>
|
||||||
|
<stop offset="0.8667" style="stop-color:#08DFB0"/>
|
||||||
|
<stop offset="0.9333" style="stop-color:#06E4AE"/>
|
||||||
|
<stop offset="1" style="stop-color:#05E5AD"/>
|
||||||
|
</radialGradient>
|
||||||
|
<path fill="url(#SVGID_00000150822754378345238340000008985053211526864828_)" d="M21.4,9.8c3,0,5.9,0.7,8.5,1.9
|
||||||
|
c-5.7,3.4-9.8,11.1-9.8,20.1c0,9,4,16.7,9.8,20.1c-2.6,1.2-5.5,1.9-8.5,1.9c-11.6,0-21-9.8-21-22S9.8,9.8,21.4,9.8z"/>
|
||||||
|
|
||||||
|
<radialGradient id="SVGID_00000022560571240417802950000012439139323268113305_" cx="-191.7649" cy="385.7387" r="4.8781" gradientTransform="matrix(-2.5514 -0.7616 -0.8125 2.7217 -130.733 -1180.2209)" gradientUnits="userSpaceOnUse">
|
||||||
|
<stop offset="0" style="stop-color:#6447FF"/>
|
||||||
|
<stop offset="6.666670e-02" style="stop-color:#6348FE"/>
|
||||||
|
<stop offset="0.1333" style="stop-color:#614DFC"/>
|
||||||
|
<stop offset="0.2" style="stop-color:#5C54F8"/>
|
||||||
|
<stop offset="0.2667" style="stop-color:#565EF3"/>
|
||||||
|
<stop offset="0.3333" style="stop-color:#4E6CEC"/>
|
||||||
|
<stop offset="0.4" style="stop-color:#447BE4"/>
|
||||||
|
<stop offset="0.4667" style="stop-color:#3A8DDB"/>
|
||||||
|
<stop offset="0.5333" style="stop-color:#2F9FD1"/>
|
||||||
|
<stop offset="0.6" style="stop-color:#25B1C8"/>
|
||||||
|
<stop offset="0.6667" style="stop-color:#1BC0C0"/>
|
||||||
|
<stop offset="0.7333" style="stop-color:#13CEB9"/>
|
||||||
|
<stop offset="0.8" style="stop-color:#0DD8B4"/>
|
||||||
|
<stop offset="0.8667" style="stop-color:#08DFB0"/>
|
||||||
|
<stop offset="0.9333" style="stop-color:#06E4AE"/>
|
||||||
|
<stop offset="1" style="stop-color:#05E5AD"/>
|
||||||
|
</radialGradient>
|
||||||
|
<path fill="url(#SVGID_00000022560571240417802950000012439139323268113305_)" d="M38,18.3c-2.1-2.8-4.9-5.1-8.1-6.6
|
||||||
|
c2-1.2,4.2-1.9,6.6-1.9c2.2,0,4.3,0.6,6.2,1.7C40.8,12.9,39.2,15.3,38,18.3L38,18.3z"/>
|
||||||
|
|
||||||
|
<radialGradient id="SVGID_00000143611122169386473660000017673587931016751800_" cx="-194.7918" cy="395.2442" r="4.8781" gradientTransform="matrix(-2.5514 -0.7616 -0.8125 2.7217 -130.733 -1172.9556)" gradientUnits="userSpaceOnUse">
|
||||||
|
<stop offset="0" style="stop-color:#6447FF"/>
|
||||||
|
<stop offset="6.666670e-02" style="stop-color:#6348FE"/>
|
||||||
|
<stop offset="0.1333" style="stop-color:#614DFC"/>
|
||||||
|
<stop offset="0.2" style="stop-color:#5C54F8"/>
|
||||||
|
<stop offset="0.2667" style="stop-color:#565EF3"/>
|
||||||
|
<stop offset="0.3333" style="stop-color:#4E6CEC"/>
|
||||||
|
<stop offset="0.4" style="stop-color:#447BE4"/>
|
||||||
|
<stop offset="0.4667" style="stop-color:#3A8DDB"/>
|
||||||
|
<stop offset="0.5333" style="stop-color:#2F9FD1"/>
|
||||||
|
<stop offset="0.6" style="stop-color:#25B1C8"/>
|
||||||
|
<stop offset="0.6667" style="stop-color:#1BC0C0"/>
|
||||||
|
<stop offset="0.7333" style="stop-color:#13CEB9"/>
|
||||||
|
<stop offset="0.8" style="stop-color:#0DD8B4"/>
|
||||||
|
<stop offset="0.8667" style="stop-color:#08DFB0"/>
|
||||||
|
<stop offset="0.9333" style="stop-color:#06E4AE"/>
|
||||||
|
<stop offset="1" style="stop-color:#05E5AD"/>
|
||||||
|
</radialGradient>
|
||||||
|
<path fill="url(#SVGID_00000143611122169386473660000017673587931016751800_)" d="M38,45.2c1.2,3,2.9,5.3,4.7,6.8
|
||||||
|
c-1.9,1.1-4,1.7-6.2,1.7c-2.3,0-4.6-0.7-6.6-1.9C33.1,50.4,35.8,48.1,38,45.2L38,45.2z"/>
|
||||||
|
<path fill="#684BFE" d="M20.1,31.8c0-9,4-16.7,9.8-20.1c3.2,1.5,6,3.8,8.1,6.6c-1.5,3.7-2.5,8.4-2.5,13.5s0.9,9.8,2.5,13.5
|
||||||
|
c-2.1,2.8-4.9,5.1-8.1,6.6C24.1,48.4,20.1,40.7,20.1,31.8z"/>
|
||||||
|
|
||||||
|
<radialGradient id="SVGID_00000147942998054305738810000004710078864578628519_" cx="-212.7358" cy="363.2475" r="4.8781" gradientTransform="matrix(-2.3342 -1.063 -1.623 3.5638 149.3813 -1470.1027)" gradientUnits="userSpaceOnUse">
|
||||||
|
<stop offset="0" style="stop-color:#6447FF"/>
|
||||||
|
<stop offset="6.666670e-02" style="stop-color:#6348FE"/>
|
||||||
|
<stop offset="0.1333" style="stop-color:#614DFC"/>
|
||||||
|
<stop offset="0.2" style="stop-color:#5C54F8"/>
|
||||||
|
<stop offset="0.2667" style="stop-color:#565EF3"/>
|
||||||
|
<stop offset="0.3333" style="stop-color:#4E6CEC"/>
|
||||||
|
<stop offset="0.4" style="stop-color:#447BE4"/>
|
||||||
|
<stop offset="0.4667" style="stop-color:#3A8DDB"/>
|
||||||
|
<stop offset="0.5333" style="stop-color:#2F9FD1"/>
|
||||||
|
<stop offset="0.6" style="stop-color:#25B1C8"/>
|
||||||
|
<stop offset="0.6667" style="stop-color:#1BC0C0"/>
|
||||||
|
<stop offset="0.7333" style="stop-color:#13CEB9"/>
|
||||||
|
<stop offset="0.8" style="stop-color:#0DD8B4"/>
|
||||||
|
<stop offset="0.8667" style="stop-color:#08DFB0"/>
|
||||||
|
<stop offset="0.9333" style="stop-color:#06E4AE"/>
|
||||||
|
<stop offset="1" style="stop-color:#05E5AD"/>
|
||||||
|
</radialGradient>
|
||||||
|
<path fill="url(#SVGID_00000147942998054305738810000004710078864578628519_)" d="M50.7,42.5c0.6,3.3,1.5,6.1,2.5,8
|
||||||
|
c-1.8,2-3.8,3.1-6,3.1c-1.6,0-3.1-0.6-4.5-1.7C46.1,50.2,48.9,46.8,50.7,42.5L50.7,42.5z"/>
|
||||||
|
|
||||||
|
<radialGradient id="SVGID_00000083770737908230256670000016126156495859285174_" cx="-208.5327" cy="357.2025" r="4.8781" gradientTransform="matrix(-2.3342 -1.063 -1.623 3.5638 149.3813 -1476.8097)" gradientUnits="userSpaceOnUse">
|
||||||
|
<stop offset="0" style="stop-color:#6447FF"/>
|
||||||
|
<stop offset="6.666670e-02" style="stop-color:#6348FE"/>
|
||||||
|
<stop offset="0.1333" style="stop-color:#614DFC"/>
|
||||||
|
<stop offset="0.2" style="stop-color:#5C54F8"/>
|
||||||
|
<stop offset="0.2667" style="stop-color:#565EF3"/>
|
||||||
|
<stop offset="0.3333" style="stop-color:#4E6CEC"/>
|
||||||
|
<stop offset="0.4" style="stop-color:#447BE4"/>
|
||||||
|
<stop offset="0.4667" style="stop-color:#3A8DDB"/>
|
||||||
|
<stop offset="0.5333" style="stop-color:#2F9FD1"/>
|
||||||
|
<stop offset="0.6" style="stop-color:#25B1C8"/>
|
||||||
|
<stop offset="0.6667" style="stop-color:#1BC0C0"/>
|
||||||
|
<stop offset="0.7333" style="stop-color:#13CEB9"/>
|
||||||
|
<stop offset="0.8" style="stop-color:#0DD8B4"/>
|
||||||
|
<stop offset="0.8667" style="stop-color:#08DFB0"/>
|
||||||
|
<stop offset="0.9333" style="stop-color:#06E4AE"/>
|
||||||
|
<stop offset="1" style="stop-color:#05E5AD"/>
|
||||||
|
</radialGradient>
|
||||||
|
<path fill="url(#SVGID_00000083770737908230256670000016126156495859285174_)" d="M42.7,11.5c1.4-1.1,2.9-1.7,4.5-1.7
|
||||||
|
c2.2,0,4.3,1.1,6,3.1c-1,2-1.9,4.7-2.5,8C48.9,16.7,46.1,13.4,42.7,11.5L42.7,11.5z"/>
|
||||||
|
<path fill="#684BFE" d="M38,45.2c2.8-3.7,4.4-8.4,4.4-13.5c0-5.1-1.7-9.8-4.4-13.5c1.2-3,2.9-5.3,4.7-6.8c3.4,1.9,6.2,5.3,8,9.5
|
||||||
|
c-0.6,3.2-0.9,6.9-0.9,10.8s0.3,7.6,0.9,10.8c-1.8,4.3-4.6,7.6-8,9.5C40.8,50.6,39.2,48.2,38,45.2L38,45.2z"/>
|
||||||
|
<path fill="#321BB2" d="M38,45.2c-1.5-3.7-2.5-8.4-2.5-13.5S36.4,22,38,18.3c2.8,3.7,4.4,8.4,4.4,13.5S40.8,41.5,38,45.2z"/>
|
||||||
|
<path fill="#05E6AD" d="M53.2,12.9c1.1-2,2.3-3.1,3.6-3.1c3.9,0,7,9.8,7,22s-3.1,22-7,22c-1.3,0-2.6-1.1-3.6-3.1
|
||||||
|
c3.4-3.8,5.7-10.8,5.7-18.8C58.8,23.8,56.6,16.8,53.2,12.9z"/>
|
||||||
|
|
||||||
|
<radialGradient id="SVGID_00000009565123575973598080000009335550354766300606_" cx="-7.8671" cy="278.2442" r="4.8781" gradientTransform="matrix(1.5187 0 0 -7.8271 69.237 2209.3281)" gradientUnits="userSpaceOnUse">
|
||||||
|
<stop offset="0" style="stop-color:#05E5AD"/>
|
||||||
|
<stop offset="0.32" style="stop-color:#05E5AD;stop-opacity:0"/>
|
||||||
|
<stop offset="0.9028" style="stop-color:#6447FF"/>
|
||||||
|
</radialGradient>
|
||||||
|
<path fill="url(#SVGID_00000009565123575973598080000009335550354766300606_)" d="M53.2,12.9c1.1-2,2.3-3.1,3.6-3.1
|
||||||
|
c3.9,0,7,9.8,7,22s-3.1,22-7,22c-1.3,0-2.6-1.1-3.6-3.1c3.4-3.8,5.7-10.8,5.7-18.8C58.8,23.8,56.6,16.8,53.2,12.9z"/>
|
||||||
|
<path fill="#684BFE" d="M52.8,31.8c0-3.9-0.8-7.6-2.1-10.8c0.6-3.3,1.5-6.1,2.5-8c3.4,3.8,5.7,10.8,5.7,18.8c0,8-2.3,15-5.7,18.8
|
||||||
|
c-1-2-1.9-4.7-2.5-8C52,39.3,52.8,35.7,52.8,31.8z"/>
|
||||||
|
<path fill="#321BB2" d="M50.7,42.5c-0.6-3.2-0.9-6.9-0.9-10.8s0.3-7.6,0.9-10.8c1.3,3.2,2.1,6.9,2.1,10.8S52,39.3,50.7,42.5z"/>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 9.0 KiB |
Binary file not shown.
Before Width: | Height: | Size: 8.7 KiB |
@ -2,3 +2,4 @@ We take your code's security and privacy seriously:
|
|||||||
|
|
||||||
- The Chrome extension will not send your code to any external servers.
|
- The Chrome extension will not send your code to any external servers.
|
||||||
- For private repositories, we will first validate the user's identity and permissions. After authentication, we generate responses using the existing Qodo Merge Pro integration.
|
- For private repositories, we will first validate the user's identity and permissions. After authentication, we generate responses using the existing Qodo Merge Pro integration.
|
||||||
|
|
||||||
|
@ -1,115 +0,0 @@
|
|||||||
# Fetching Ticket Context for PRs
|
|
||||||
## Overview
|
|
||||||
Qodo Merge PR Agent streamlines code review workflows by seamlessly connecting with multiple ticket management systems.
|
|
||||||
This integration enriches the review process by automatically surfacing relevant ticket information and context alongside code changes.
|
|
||||||
|
|
||||||
|
|
||||||
## Affected Tools
|
|
||||||
|
|
||||||
Ticket Recognition Requirements:
|
|
||||||
|
|
||||||
1. The PR description should contain a link to the ticket.
|
|
||||||
2. For Jira tickets, you should follow the instructions in [Jira Integration](https://qodo-merge-docs.qodo.ai/core-abilities/fetching_ticket_context/#jira-integration) in order to authenticate with Jira.
|
|
||||||
|
|
||||||
|
|
||||||
### Describe tool
|
|
||||||
Qodo Merge PR Agent will recognize the ticket and use the ticket content (title, description, labels) to provide additional context for the code changes.
|
|
||||||
By understanding the reasoning and intent behind modifications, the LLM can offer more insightful and relevant code analysis.
|
|
||||||
|
|
||||||
### Review tool
|
|
||||||
Similarly to the `describe` tool, the `review` tool will use the ticket content to provide additional context for the code changes.
|
|
||||||
|
|
||||||
In addition, this feature will evaluate how well a Pull Request (PR) adheres to its original purpose/intent as defined by the associated ticket or issue mentioned in the PR description.
|
|
||||||
Each ticket will be assigned a label (Compliance/Alignment level), Indicates the degree to which the PR fulfills its original purpose, Options: Fully compliant, Partially compliant or Not compliant.
|
|
||||||
|
|
||||||
|
|
||||||
{width=768}
|
|
||||||
|
|
||||||
By default, the tool will automatically validate if the PR complies with the referenced ticket.
|
|
||||||
If you want to disable this feedback, add the following line to your configuration file:
|
|
||||||
|
|
||||||
```toml
|
|
||||||
[pr_reviewer]
|
|
||||||
require_ticket_analysis_review=false
|
|
||||||
```
|
|
||||||
|
|
||||||
## Providers
|
|
||||||
|
|
||||||
### Github Issues Integration
|
|
||||||
|
|
||||||
Qodo Merge PR Agent will automatically recognize Github issues mentioned in the PR description and fetch the issue content.
|
|
||||||
Examples of valid GitHub issue references:
|
|
||||||
|
|
||||||
- `https://github.com/<ORG_NAME>/<REPO_NAME>/issues/<ISSUE_NUMBER>`
|
|
||||||
- `#<ISSUE_NUMBER>`
|
|
||||||
- `<ORG_NAME>/<REPO_NAME>#<ISSUE_NUMBER>`
|
|
||||||
|
|
||||||
Since Qodo Merge PR Agent is integrated with GitHub, it doesn't require any additional configuration to fetch GitHub issues.
|
|
||||||
|
|
||||||
### Jira Integration 💎
|
|
||||||
|
|
||||||
We support both Jira Cloud and Jira Server/Data Center.
|
|
||||||
To integrate with Jira, The PR Description should contain a link to the Jira ticket.
|
|
||||||
|
|
||||||
For Jira integration, include a ticket reference in your PR description using either the complete URL format `https://<JIRA_ORG>.atlassian.net/browse/ISSUE-123` or the shortened ticket ID `ISSUE-123`.
|
|
||||||
|
|
||||||
!!! note "Jira Base URL"
|
|
||||||
If using the shortened format, ensure your configuration file contains the Jira base URL under the [jira] section like this:
|
|
||||||
|
|
||||||
```toml
|
|
||||||
[jira]
|
|
||||||
jira_base_url = "https://<JIRA_ORG>.atlassian.net"
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Jira Cloud 💎
|
|
||||||
There are two ways to authenticate with Jira Cloud:
|
|
||||||
|
|
||||||
**1) Jira App Authentication**
|
|
||||||
|
|
||||||
The recommended way to authenticate with Jira Cloud is to install the Qodo Merge app in your Jira Cloud instance. This will allow Qodo Merge to access Jira data on your behalf.
|
|
||||||
|
|
||||||
Installation steps:
|
|
||||||
|
|
||||||
1. Click [here](https://auth.atlassian.com/authorize?audience=api.atlassian.com&client_id=8krKmA4gMD8mM8z24aRCgPCSepZNP1xf&scope=read%3Ajira-work%20offline_access&redirect_uri=https%3A%2F%2Fregister.jira.pr-agent.codium.ai&state=qodomerge&response_type=code&prompt=consent) to install the Qodo Merge app in your Jira Cloud instance, click the `accept` button.<br>
|
|
||||||
{width=384}
|
|
||||||
|
|
||||||
2. After installing the app, you will be redirected to the Qodo Merge registration page. and you will see a success message.<br>
|
|
||||||
{width=384}
|
|
||||||
|
|
||||||
3. Now you can use the Jira integration in Qodo Merge PR Agent.
|
|
||||||
|
|
||||||
**2) Email/Token Authentication**
|
|
||||||
|
|
||||||
You can create an API token from your Atlassian account:
|
|
||||||
|
|
||||||
1. Log in to https://id.atlassian.com/manage-profile/security/api-tokens.
|
|
||||||
|
|
||||||
2. Click Create API token.
|
|
||||||
|
|
||||||
3. From the dialog that appears, enter a name for your new token and click Create.
|
|
||||||
|
|
||||||
4. Click Copy to clipboard.
|
|
||||||
|
|
||||||
{width=384}
|
|
||||||
|
|
||||||
5. In your [configuration file](https://qodo-merge-docs.qodo.ai/usage-guide/configuration_options/) add the following lines:
|
|
||||||
|
|
||||||
```toml
|
|
||||||
[jira]
|
|
||||||
jira_api_token = "YOUR_API_TOKEN"
|
|
||||||
jira_api_email = "YOUR_EMAIL"
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
#### Jira Server/Data Center 💎
|
|
||||||
|
|
||||||
Currently, we only support the Personal Access Token (PAT) Authentication method.
|
|
||||||
|
|
||||||
1. Create a [Personal Access Token (PAT)](https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html) in your Jira account
|
|
||||||
2. In your Configuration file/Environment variables/Secrets file, add the following lines:
|
|
||||||
|
|
||||||
```toml
|
|
||||||
[jira]
|
|
||||||
jira_base_url = "YOUR_JIRA_BASE_URL" # e.g. https://jira.example.com
|
|
||||||
jira_api_token = "YOUR_API_TOKEN"
|
|
||||||
```
|
|
@ -1,7 +1,6 @@
|
|||||||
# Core Abilities
|
# Core Abilities
|
||||||
Qodo Merge utilizes a variety of core abilities to provide a comprehensive and efficient code review experience. These abilities include:
|
Qodo Merge utilizes a variety of core abilities to provide a comprehensive and efficient code review experience. These abilities include:
|
||||||
|
|
||||||
- [Fetching ticket context](https://qodo-merge-docs.qodo.ai/core-abilities/fetching_ticket_context/)
|
|
||||||
- [Local and global metadata](https://qodo-merge-docs.qodo.ai/core-abilities/metadata/)
|
- [Local and global metadata](https://qodo-merge-docs.qodo.ai/core-abilities/metadata/)
|
||||||
- [Dynamic context](https://qodo-merge-docs.qodo.ai/core-abilities/dynamic_context/)
|
- [Dynamic context](https://qodo-merge-docs.qodo.ai/core-abilities/dynamic_context/)
|
||||||
- [Self-reflection](https://qodo-merge-docs.qodo.ai/core-abilities/self_reflection/)
|
- [Self-reflection](https://qodo-merge-docs.qodo.ai/core-abilities/self_reflection/)
|
||||||
@ -11,19 +10,3 @@ Qodo Merge utilizes a variety of core abilities to provide a comprehensive and e
|
|||||||
- [Code-oriented YAML](https://qodo-merge-docs.qodo.ai/core-abilities/code_oriented_yaml/)
|
- [Code-oriented YAML](https://qodo-merge-docs.qodo.ai/core-abilities/code_oriented_yaml/)
|
||||||
- [Static code analysis](https://qodo-merge-docs.qodo.ai/core-abilities/static_code_analysis/)
|
- [Static code analysis](https://qodo-merge-docs.qodo.ai/core-abilities/static_code_analysis/)
|
||||||
- [Code fine-tuning benchmark](https://qodo-merge-docs.qodo.ai/finetuning_benchmark/)
|
- [Code fine-tuning benchmark](https://qodo-merge-docs.qodo.ai/finetuning_benchmark/)
|
||||||
|
|
||||||
## Blogs
|
|
||||||
|
|
||||||
Here are some additional technical blogs from Qodo, that delve deeper into the core capabilities and features of Large Language Models (LLMs) when applied to coding tasks.
|
|
||||||
These resources provide more comprehensive insights into leveraging LLMs for software development.
|
|
||||||
|
|
||||||
### Code Generation and LLMs
|
|
||||||
- [State-of-the-art Code Generation with AlphaCodium – From Prompt Engineering to Flow Engineering](https://www.qodo.ai/blog/qodoflow-state-of-the-art-code-generation-for-code-contests/)
|
|
||||||
- [RAG for a Codebase with 10k Repos](https://www.qodo.ai/blog/rag-for-large-scale-code-repos/)
|
|
||||||
|
|
||||||
### Development Processes
|
|
||||||
- [Understanding the Challenges and Pain Points of the Pull Request Cycle](https://www.qodo.ai/blog/understanding-the-challenges-and-pain-points-of-the-pull-request-cycle/)
|
|
||||||
- [Introduction to Code Coverage Testing](https://www.qodo.ai/blog/introduction-to-code-coverage-testing/)
|
|
||||||
|
|
||||||
### Cost Optimization
|
|
||||||
- [Reduce Your Costs by 30% When Using GPT for Python Code](https://www.qodo.ai/blog/reduce-your-costs-by-30-when-using-gpt-3-for-python-code/)
|
|
||||||
|
@ -49,7 +49,7 @@ __old hunk__
|
|||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
(3) The entire PR files that were retrieved are also used to expand and enhance the PR context (see [Dynamic Context](https://qodo-merge-docs.qodo.ai/core-abilities/dynamic_context/)).
|
(3) The entire PR files that were retrieved are also used to expand and enhance the PR context (see [Dynamic Context](https://qodo-merge-docs.qodo.ai/core-abilities/dynamic-context/)).
|
||||||
|
|
||||||
|
|
||||||
(4) All the metadata described above represents several level of cumulative analysis - ranging from hunk level, to file level, to PR level, to organization level.
|
(4) All the metadata described above represents several level of cumulative analysis - ranging from hunk level, to file level, to PR level, to organization level.
|
||||||
|
@ -46,5 +46,6 @@ This results in a more refined and valuable set of suggestions for the user, sav
|
|||||||
## Appendix - Relevant Configuration Options
|
## Appendix - Relevant Configuration Options
|
||||||
```
|
```
|
||||||
[pr_code_suggestions]
|
[pr_code_suggestions]
|
||||||
|
self_reflect_on_suggestions = true # Enable self-reflection on code suggestions
|
||||||
suggestions_score_threshold = 0 # Filter out suggestions with a score below this threshold (0-10)
|
suggestions_score_threshold = 0 # Filter out suggestions with a score below this threshold (0-10)
|
||||||
```
|
```
|
@ -29,6 +29,7 @@ Qodo Merge offers extensive pull request functionalities across various git prov
|
|||||||
|-------|-----------------------------------------------------------------------------------------------------------------------|:------:|:------:|:---------:|:------------:|
|
|-------|-----------------------------------------------------------------------------------------------------------------------|:------:|:------:|:---------:|:------------:|
|
||||||
| TOOLS | Review | ✅ | ✅ | ✅ | ✅ |
|
| TOOLS | Review | ✅ | ✅ | ✅ | ✅ |
|
||||||
| | ⮑ Incremental | ✅ | | | |
|
| | ⮑ Incremental | ✅ | | | |
|
||||||
|
| | ⮑ [SOC2 Compliance](https://qodo-merge-docs.qodo.ai/tools/review/#soc2-ticket-compliance){:target="_blank"} 💎 | ✅ | ✅ | ✅ | |
|
||||||
| | Ask | ✅ | ✅ | ✅ | ✅ |
|
| | Ask | ✅ | ✅ | ✅ | ✅ |
|
||||||
| | Describe | ✅ | ✅ | ✅ | ✅ |
|
| | Describe | ✅ | ✅ | ✅ | ✅ |
|
||||||
| | ⮑ [Inline file summary](https://qodo-merge-docs.qodo.ai/tools/describe/#inline-file-summary){:target="_blank"} 💎 | ✅ | ✅ | | |
|
| | ⮑ [Inline file summary](https://qodo-merge-docs.qodo.ai/tools/describe/#inline-file-summary){:target="_blank"} 💎 | ✅ | ✅ | | |
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
You can use the Bitbucket Pipeline system to run Qodo Merge on every pull request open or update.
|
You can use the Bitbucket Pipeline system to run Qodo Merge on every pull request open or update.
|
||||||
|
|
||||||
1. Add the following file in your repository bitbucket-pipelines.yml
|
1. Add the following file in your repository bitbucket_pipelines.yml
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
pipelines:
|
pipelines:
|
||||||
|
@ -27,6 +27,27 @@ jobs:
|
|||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
if you want to pin your action to a specific release (v0.23 for example) for stability reasons, use:
|
||||||
|
```yaml
|
||||||
|
...
|
||||||
|
steps:
|
||||||
|
- name: PR Agent action step
|
||||||
|
id: pragent
|
||||||
|
uses: docker://codiumai/pr-agent:0.23-github_action
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
For enhanced security, you can also specify the Docker image by its [digest](https://hub.docker.com/repository/docker/codiumai/pr-agent/tags):
|
||||||
|
```yaml
|
||||||
|
...
|
||||||
|
steps:
|
||||||
|
- name: PR Agent action step
|
||||||
|
id: pragent
|
||||||
|
uses: docker://codiumai/pr-agent@sha256:14165e525678ace7d9b51cda8652c2d74abb4e1d76b57c4a6ccaeba84663cc64
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
2) Add the following secret to your repository under `Settings > Secrets and variables > Actions > New repository secret > Add secret`:
|
2) Add the following secret to your repository under `Settings > Secrets and variables > Actions > New repository secret > Add secret`:
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -49,40 +70,6 @@ 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)
|
See detailed usage instructions in the [USAGE GUIDE](https://qodo-merge-docs.qodo.ai/usage-guide/automations_and_usage/#github-action)
|
||||||
|
|
||||||
### Using a specific release
|
|
||||||
!!! tip ""
|
|
||||||
if you want to pin your action to a specific release (v0.23 for example) for stability reasons, use:
|
|
||||||
```yaml
|
|
||||||
...
|
|
||||||
steps:
|
|
||||||
- name: PR Agent action step
|
|
||||||
id: pragent
|
|
||||||
uses: docker://codiumai/pr-agent:0.23-github_action
|
|
||||||
...
|
|
||||||
```
|
|
||||||
|
|
||||||
For enhanced security, you can also specify the Docker image by its [digest](https://hub.docker.com/repository/docker/codiumai/pr-agent/tags):
|
|
||||||
```yaml
|
|
||||||
...
|
|
||||||
steps:
|
|
||||||
- name: PR Agent action step
|
|
||||||
id: pragent
|
|
||||||
uses: docker://codiumai/pr-agent@sha256:14165e525678ace7d9b51cda8652c2d74abb4e1d76b57c4a6ccaeba84663cc64
|
|
||||||
...
|
|
||||||
```
|
|
||||||
|
|
||||||
### Action for GitHub enterprise server
|
|
||||||
!!! tip ""
|
|
||||||
To use the action with a GitHub enterprise server, add an environment variable `GITHUB.BASE_URL` with the API URL of your GitHub server.
|
|
||||||
|
|
||||||
For example, if your GitHub server is at `https://github.mycompany.com`, add the following to your workflow file:
|
|
||||||
```yaml
|
|
||||||
env:
|
|
||||||
# ... previous environment values
|
|
||||||
GITHUB.BASE_URL: "https://github.mycompany.com/api/v3"
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Run as a GitHub App
|
## Run as a GitHub App
|
||||||
|
@ -38,41 +38,25 @@ You can also modify the `script` section to run different Qodo Merge commands, o
|
|||||||
|
|
||||||
Note that if your base branches are not protected, don't set the variables as `protected`, since the pipeline will not have access to them.
|
Note that if your base branches are not protected, don't set the variables as `protected`, since the pipeline will not have access to them.
|
||||||
|
|
||||||
> **Note**: The `$CI_SERVER_FQDN` variable is available starting from GitLab version 16.10. If you're using an earlier version, this variable will not be available. However, you can combine `$CI_SERVER_HOST` and `$CI_SERVER_PORT` to achieve the same result. Please ensure you're using a compatible version or adjust your configuration.
|
|
||||||
|
|
||||||
|
|
||||||
## Run a GitLab webhook server
|
## Run a GitLab webhook server
|
||||||
|
|
||||||
1. From the GitLab workspace or group, create an access token with "Reporter" role ("Developer" if using Pro version of the agent) and "api" scope.
|
1. From the GitLab workspace or group, create an access token. Enable the "api" scope only.
|
||||||
|
|
||||||
2. Generate a random secret for your app, and save it for later. For example, you can use:
|
2. Generate a random secret for your app, and save it for later. For example, you can use:
|
||||||
|
|
||||||
```
|
```
|
||||||
WEBHOOK_SECRET=$(python -c "import secrets; print(secrets.token_hex(10))")
|
WEBHOOK_SECRET=$(python -c "import secrets; print(secrets.token_hex(10))")
|
||||||
```
|
```
|
||||||
|
3. Follow the instructions to build the Docker image, setup a secrets file and deploy on your own server from [here](https://qodo-merge-docs.qodo.ai/installation/github/#run-as-a-github-app) steps 4-7.
|
||||||
|
|
||||||
3. Clone this repository:
|
4. In the secrets file, fill in the following:
|
||||||
|
- Your OpenAI key.
|
||||||
|
- In the [gitlab] section, fill in personal_access_token and shared_secret. The access token can be a personal access token, or a group or project access token.
|
||||||
|
- Set deployment_type to 'gitlab' in [configuration.toml](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml)
|
||||||
|
|
||||||
```
|
5. Create a webhook in GitLab. Set the URL to ```http[s]://<PR_AGENT_HOSTNAME>/webhook```. Set the secret token to the generated secret from step 2.
|
||||||
git clone https://github.com/Codium-ai/pr-agent.git
|
In the "Trigger" section, check the ‘comments’ and ‘merge request events’ boxes.
|
||||||
```
|
|
||||||
|
|
||||||
4. Prepare variables and secrets. Skip this step if you plan on settings these as environment variables when running the agent:
|
6. Test your installation by opening a merge request or commenting or a merge request using one of CodiumAI's commands.
|
||||||
1. In the configuration file/variables:
|
|
||||||
- Set `deployment_type` 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 1) and `shared_secret` (with secret from step 2)
|
|
||||||
|
|
||||||
|
|
||||||
5. Build a Docker image for the app and optionally push it to a Docker repository. We'll use Dockerhub as an example:
|
|
||||||
```
|
|
||||||
docker build . -t gitlab_pr_agent --target gitlab_webhook -f docker/Dockerfile
|
|
||||||
docker push codiumai/pr-agent:gitlab_webhook # Push to your Docker repository
|
|
||||||
```
|
|
||||||
|
|
||||||
6. Create a webhook in GitLab. Set the URL to ```http[s]://<PR_AGENT_HOSTNAME>/webhook```, the secret token to the generated secret from step 2, and enable the triggers `push`, `comments` and `merge request events`.
|
|
||||||
|
|
||||||
7. Test your installation by opening a merge request or commenting on a merge request using one of CodiumAI's commands.
|
|
||||||
boxes
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Installation
|
# Installation
|
||||||
|
|
||||||
## Self-hosted Qodo Merge
|
## Self-hosted Qodo Merge
|
||||||
If you choose to host your own Qodo Merge, you first need to acquire two tokens:
|
If you choose to host you own Qodo Merge, you first need to acquire two tokens:
|
||||||
|
|
||||||
1. An OpenAI key from [here](https://platform.openai.com/api-keys), with access to GPT-4 (or a key for other [language models](https://qodo-merge-docs.qodo.ai/usage-guide/changing_a_model/), if you prefer).
|
1. An OpenAI key from [here](https://platform.openai.com/api-keys), with access to GPT-4 (or a key for other [language models](https://qodo-merge-docs.qodo.ai/usage-guide/changing_a_model/), if you prefer).
|
||||||
2. A GitHub\GitLab\BitBucket personal access token (classic), with the repo scope. [GitHub from [here](https://github.com/settings/tokens)]
|
2. A GitHub\GitLab\BitBucket personal access token (classic), with the repo scope. [GitHub from [here](https://github.com/settings/tokens)]
|
||||||
|
@ -16,8 +16,8 @@ from pr_agent.config_loader import get_settings
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Fill in the following values
|
# Fill in the following values
|
||||||
provider = "github" # github/gitlab/bitbucket/azure_devops
|
provider = "github" # GitHub provider
|
||||||
user_token = "..." # user token
|
user_token = "..." # GitHub user token
|
||||||
openai_key = "..." # OpenAI key
|
openai_key = "..." # OpenAI key
|
||||||
pr_url = "..." # PR URL, for example 'https://github.com/Codium-ai/pr-agent/pull/809'
|
pr_url = "..." # PR URL, for example 'https://github.com/Codium-ai/pr-agent/pull/809'
|
||||||
command = "/review" # Command to run (e.g. '/review', '/describe', '/ask="What is the purpose of this PR?"', ...)
|
command = "/review" # Command to run (e.g. '/review', '/describe', '/ask="What is the purpose of this PR?"', ...)
|
||||||
@ -45,20 +45,15 @@ To invoke a tool (for example `review`), you can run directly from the Docker im
|
|||||||
```
|
```
|
||||||
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 key> -e GITHUB.USER_TOKEN=<your 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.
|
|
||||||
For example, if your GitHub server is at `https://github.mycompany.com`, add the following to the command:
|
|
||||||
```
|
|
||||||
-e GITHUB.BASE_URL=https://github.mycompany.com/api/v3
|
|
||||||
```
|
|
||||||
|
|
||||||
- For GitLab:
|
- For GitLab:
|
||||||
```
|
```
|
||||||
docker run --rm -it -e OPENAI.KEY=<your key> -e CONFIG.GIT_PROVIDER=gitlab -e GITLAB.PERSONAL_ACCESS_TOKEN=<your token> codiumai/pr-agent:latest --pr_url <pr_url> review
|
docker run --rm -it -e OPENAI.KEY=<your key> -e CONFIG.GIT_PROVIDER=gitlab -e GITLAB.PERSONAL_ACCESS_TOKEN=<your token> codiumai/pr-agent:latest --pr_url <pr_url> review
|
||||||
```
|
```
|
||||||
|
|
||||||
If you have a dedicated GitLab instance, you need to specify the custom url as variable:
|
Note: If you have a dedicated GitLab instance, you need to specify the custom url as variable:
|
||||||
```
|
```
|
||||||
-e GITLAB.URL=<your gitlab instance url>
|
docker run --rm -it -e OPENAI.KEY=<your key> -e CONFIG.GIT_PROVIDER=gitlab -e GITLAB.PERSONAL_ACCESS_TOKEN=<your token> -e GITLAB.URL=<your gitlab instance url> codiumai/pr-agent:latest --pr_url <pr_url> review
|
||||||
```
|
```
|
||||||
|
|
||||||
- For BitBucket:
|
- For BitBucket:
|
||||||
@ -70,6 +65,19 @@ For other git providers, update CONFIG.GIT_PROVIDER accordingly, and check the `
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
|
If you want to ensure you're running a specific version of the Docker image, consider using the image's digest:
|
||||||
|
```bash
|
||||||
|
docker run --rm -it -e OPENAI.KEY=<your key> -e GITHUB.USER_TOKEN=<your token> codiumai/pr-agent@sha256:71b5ee15df59c745d352d84752d01561ba64b6d51327f97d46152f0c58a5f678 --pr_url <pr_url> review
|
||||||
|
```
|
||||||
|
|
||||||
|
Or you can run a [specific released versions](https://github.com/Codium-ai/pr-agent/blob/main/RELEASE_NOTES.md) of pr-agent, for example:
|
||||||
|
```
|
||||||
|
codiumai/pr-agent@v0.9
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Run from source
|
## Run from source
|
||||||
|
|
||||||
1. Clone this repository:
|
1. Clone this repository:
|
||||||
@ -107,7 +115,7 @@ python3 -m pr_agent.cli --issue_url <issue_url> similar_issue
|
|||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
[Optional] Add the pr_agent folder to your PYTHONPATH
|
[Optional] Add the pr_agent folder to your PYTHONPATH
|
||||||
```
|
```
|
||||||
export PYTHONPATH=$PYTHONPATH:<PATH to pr_agent folder>
|
export PYTHONPATH=$PYTHONPATH:<PATH to pr_agent folder>
|
||||||
```
|
```
|
@ -17,8 +17,8 @@ Users without a purchased seat who interact with a repository featuring Qodo Mer
|
|||||||
Beyond this limit, Qodo Merge Pro will cease to respond to their inquiries unless a seat is purchased.
|
Beyond this limit, Qodo Merge Pro will cease to respond to their inquiries unless a seat is purchased.
|
||||||
|
|
||||||
## Install Qodo Merge Pro for GitHub Enterprise Server
|
## Install Qodo Merge Pro for GitHub Enterprise Server
|
||||||
|
You can install Qodo Merge Pro application on your GitHub Enterprise Server, and enjoy two weeks of free trial.
|
||||||
To use Qodo Merge Pro application on your private GitHub Enterprise Server, you will need to contact us for starting an [Enterprise](https://www.codium.ai/pricing/) trial.
|
After the trial period, to continue using Qodo Merge Pro, you will need to contact us for an [Enterprise license](https://www.codium.ai/pricing/).
|
||||||
|
|
||||||
|
|
||||||
## Install Qodo Merge Pro for GitLab (Teams & Enterprise)
|
## Install Qodo Merge Pro for GitLab (Teams & Enterprise)
|
||||||
|
@ -29,6 +29,7 @@ Qodo Merge offers extensive pull request functionalities across various git prov
|
|||||||
|-------|-----------------------------------------------------------------------------------------------------------------------|:------:|:------:|:---------:|:------------:|
|
|-------|-----------------------------------------------------------------------------------------------------------------------|:------:|:------:|:---------:|:------------:|
|
||||||
| TOOLS | Review | ✅ | ✅ | ✅ | ✅ |
|
| TOOLS | Review | ✅ | ✅ | ✅ | ✅ |
|
||||||
| | ⮑ Incremental | ✅ | | | |
|
| | ⮑ Incremental | ✅ | | | |
|
||||||
|
| | ⮑ [SOC2 Compliance](https://qodo-merge-docs.qodo.ai/tools/review/#soc2-ticket-compliance){:target="_blank"} 💎 | ✅ | ✅ | ✅ | ✅ |
|
||||||
| | Ask | ✅ | ✅ | ✅ | ✅ |
|
| | Ask | ✅ | ✅ | ✅ | ✅ |
|
||||||
| | Describe | ✅ | ✅ | ✅ | ✅ |
|
| | Describe | ✅ | ✅ | ✅ | ✅ |
|
||||||
| | ⮑ [Inline file summary](https://qodo-merge-docs.qodo.ai/tools/describe/#inline-file-summary){:target="_blank"} 💎 | ✅ | ✅ | | ✅ |
|
| | ⮑ [Inline file summary](https://qodo-merge-docs.qodo.ai/tools/describe/#inline-file-summary){:target="_blank"} 💎 | ✅ | ✅ | | ✅ |
|
||||||
|
@ -20,13 +20,14 @@ Here are some of the additional features and capabilities that Qodo Merge Pro of
|
|||||||
| Feature | Description |
|
| Feature | Description |
|
||||||
|----------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|----------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| [**Model selection**](https://qodo-merge-docs.qodo.ai/usage-guide/PR_agent_pro_models/) | Choose the model that best fits your needs, among top models like `GPT4` and `Claude-Sonnet-3.5`
|
| [**Model selection**](https://qodo-merge-docs.qodo.ai/usage-guide/PR_agent_pro_models/) | Choose the model that best fits your needs, among top models like `GPT4` and `Claude-Sonnet-3.5`
|
||||||
| [**Global and wiki configuration**](https://qodo-merge-docs.qodo.ai/usage-guide/configuration_options/) | Control configurations for many repositories from a single location; <br>Edit configuration of a single repo without committing code |
|
| [**Global and wiki configuration**](https://qodo-merge-docs.qodo.ai/usage-guide/configuration_options/) | Control configurations for many repositories from a single location; <br>Edit configuration of a single repo without commiting code |
|
||||||
| [**Apply suggestions**](https://qodo-merge-docs.qodo.ai/tools/improve/#overview) | Generate committable code from the relevant suggestions interactively by clicking on a checkbox |
|
| [**Apply suggestions**](https://qodo-merge-docs.qodo.ai/tools/improve/#overview) | Generate commitable code from the relevant suggestions interactively by clicking on a checkbox |
|
||||||
| [**Suggestions impact**](https://qodo-merge-docs.qodo.ai/tools/improve/#assessing-impact) | Automatically mark suggestions that were implemented by the user (either directly in GitHub, or indirectly in the IDE) to enable tracking of the impact of the suggestions |
|
| [**Suggestions impact**](https://qodo-merge-docs.qodo.ai/tools/improve/#assessing-impact) | Automatically mark suggestions that were implemented by the user (either directly in GitHub, or indirectly in the IDE) to enable tracking of the impact of the suggestions |
|
||||||
| [**CI feedback**](https://qodo-merge-docs.qodo.ai/tools/ci_feedback/) | Automatically analyze failed CI checks on GitHub and provide actionable feedback in the PR conversation, helping to resolve issues quickly |
|
| [**CI feedback**](https://qodo-merge-docs.qodo.ai/tools/ci_feedback/) | Automatically analyze failed CI checks on GitHub and provide actionable feedback in the PR conversation, helping to resolve issues quickly |
|
||||||
| [**Advanced usage statistics**](https://www.codium.ai/contact/#/) | Qodo Merge Pro offers detailed statistics at user, repository, and company levels, including metrics about Qodo Merge usage, and also general statistics and insights |
|
| [**Advanced usage statistics**](https://www.codium.ai/contact/#/) | Qodo Merge Pro offers detailed statistics at user, repository, and company levels, including metrics about Qodo Merge usage, and also general statistics and insights |
|
||||||
| [**Incorporating companies' best practices**](https://qodo-merge-docs.qodo.ai/tools/improve/#best-practices) | Use the companies' best practices as reference to increase the effectiveness and the relevance of the code suggestions |
|
| [**Incorporating companies' best practices**](https://qodo-merge-docs.qodo.ai/tools/improve/#best-practices) | Use the companies' best practices as reference to increase the effectiveness and the relevance of the code suggestions |
|
||||||
| [**Interactive triggering**](https://qodo-merge-docs.qodo.ai/tools/analyze/#example-usage) | Interactively apply different tools via the `analyze` command |
|
| [**Interactive triggering**](https://qodo-merge-docs.qodo.ai/tools/analyze/#example-usage) | Interactively apply different tools via the `analyze` command |
|
||||||
|
| [**SOC2 compliance check**](https://qodo-merge-docs.qodo.ai/tools/review/#configuration-options) | Ensures the PR contains a ticket to a project management system (e.g., Jira, Asana, Trello, etc.)
|
||||||
| [**Custom labels**](https://qodo-merge-docs.qodo.ai/tools/describe/#handle-custom-labels-from-the-repos-labels-page) | Define custom labels for Qodo Merge to assign to the PR |
|
| [**Custom labels**](https://qodo-merge-docs.qodo.ai/tools/describe/#handle-custom-labels-from-the-repos-labels-page) | Define custom labels for Qodo Merge to assign to the PR |
|
||||||
|
|
||||||
### Additional tools
|
### Additional tools
|
||||||
|
@ -25,7 +25,7 @@ There are 3 ways to enable custom labels:
|
|||||||
When working from CLI, you need to apply the [configuration changes](#configuration-options) to the [custom_labels file](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/custom_labels.toml):
|
When working from CLI, you need to apply the [configuration changes](#configuration-options) to the [custom_labels file](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/custom_labels.toml):
|
||||||
|
|
||||||
#### 2. Repo configuration file
|
#### 2. Repo configuration file
|
||||||
To enable custom labels, you need to apply the [configuration changes](#configuration-options) to the local `.pr_agent.toml` file in your repository.
|
To enable custom labels, you need to apply the [configuration changes](#configuration-options) to the local `.pr_agent.toml` file in you repository.
|
||||||
|
|
||||||
#### 3. Handle custom labels from the Repo's labels page 💎
|
#### 3. Handle custom labels from the Repo's labels page 💎
|
||||||
> This feature is available only in Qodo Merge Pro
|
> This feature is available only in Qodo Merge Pro
|
||||||
|
@ -34,7 +34,7 @@ pr_commands = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[pr_description]
|
[pr_description]
|
||||||
publish_labels = true
|
publish_labels = ...
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ publish_labels = true
|
|||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td><b>publish_labels</b></td>
|
<td><b>publish_labels</b></td>
|
||||||
<td>If set to true, the tool will publish labels to the PR. Default is false.</td>
|
<td>If set to true, the tool will publish the labels to the PR. Default is true.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><b>publish_description_as_comment</b></td>
|
<td><b>publish_description_as_comment</b></td>
|
||||||
|
@ -67,33 +67,6 @@ In post-process, Qodo Merge counts the number of suggestions that were implement
|
|||||||
|
|
||||||
{width=512}
|
{width=512}
|
||||||
|
|
||||||
## Suggestion tracking 💎
|
|
||||||
`Platforms supported: GitHub, GitLab`
|
|
||||||
|
|
||||||
Qodo Merge employs an novel detection system to automatically [identify](https://qodo-merge-docs.qodo.ai/core-abilities/impact_evaluation/) AI code suggestions that PR authors have accepted and implemented.
|
|
||||||
|
|
||||||
Accepted suggestions are also automatically documented in a dedicated wiki page called `.pr_agent_accepted_suggestions`, allowing users to track historical changes, assess the tool's effectiveness, and learn from previously implemented recommendations in the repository.
|
|
||||||
An example [result](https://github.com/Codium-ai/pr-agent/wiki/.pr_agent_accepted_suggestions):
|
|
||||||
|
|
||||||
[{width=768}](https://github.com/Codium-ai/pr-agent/wiki/.pr_agent_accepted_suggestions)
|
|
||||||
|
|
||||||
This dedicated wiki page will also serve as a foundation for future AI model improvements, allowing it to learn from historically implemented suggestions and generate more targeted, contextually relevant recommendations.
|
|
||||||
|
|
||||||
This feature is controlled by a boolean configuration parameter: `pr_code_suggestions.wiki_page_accepted_suggestions` (default is true).
|
|
||||||
|
|
||||||
!!! note "Wiki must be enabled"
|
|
||||||
While the aggregation process is automatic, GitHub repositories require a one-time manual wiki setup.
|
|
||||||
|
|
||||||
To initialize the wiki: navigate to `Wiki`, select `Create the first page`, then click `Save page`.
|
|
||||||
|
|
||||||
{width=768}
|
|
||||||
|
|
||||||
Once a wiki repo is created, the tool will automatically use this wiki for tracking suggestions.
|
|
||||||
|
|
||||||
!!! note "Why a wiki page?"
|
|
||||||
Your code belongs to you, and we respect your privacy. Hence, we won't store any code suggestions in an external database.
|
|
||||||
|
|
||||||
Instead, we leverage a dedicated private page, within your repository wiki, to track suggestions. This approach offers convenient secure suggestion tracking while avoiding pull requests or any noise to the main repository.
|
|
||||||
|
|
||||||
## Usage Tips
|
## Usage Tips
|
||||||
|
|
||||||
@ -141,16 +114,9 @@ code_suggestions_self_review_text = "... (your text here) ..."
|
|||||||
{width=512}
|
{width=512}
|
||||||
|
|
||||||
|
|
||||||
!!! tip "Tip - Reducing visual footprint after self-review 💎"
|
|
||||||
|
|
||||||
The configuration parameter `pr_code_suggestions.fold_suggestions_on_self_review` (default is True)
|
|
||||||
can be used to automatically fold the suggestions after the user clicks the self-review checkbox.
|
|
||||||
|
|
||||||
This reduces the visual footprint of the suggestions, and also indicates to the PR reviewer that the suggestions have been reviewed by the PR author, and don't require further attention.
|
|
||||||
|
|
||||||
|
|
||||||
|
!!! tip "Tip - demanding self-review from the PR author 💎"
|
||||||
!!! tip "Tip - Demanding self-review from the PR author 💎"
|
|
||||||
|
|
||||||
By setting:
|
By setting:
|
||||||
```toml
|
```toml
|
||||||
@ -275,14 +241,14 @@ Using a combination of both can help the AI model to provide relevant and tailor
|
|||||||
<td><b>dual_publishing_score_threshold</b></td>
|
<td><b>dual_publishing_score_threshold</b></td>
|
||||||
<td>Minimum score threshold for suggestions to be presented as commitable PR comments in addition to the table. Default is -1 (disabled).</td>
|
<td>Minimum score threshold for suggestions to be presented as commitable PR comments in addition to the table. Default is -1 (disabled).</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<td><b>focus_only_on_problems</b></td>
|
|
||||||
<td>If set to true, suggestions will focus primarily on identifying and fixing code problems, and less on style considerations like best practices, maintainability, or readability. Default is false.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<td><b>persistent_comment</b></td>
|
<td><b>persistent_comment</b></td>
|
||||||
<td>If set to true, the improve comment will be persistent, meaning that every new improve request will edit the previous one. Default is false.</td>
|
<td>If set to true, the improve comment will be persistent, meaning that every new improve request will edit the previous one. Default is false.</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><b>self_reflect_on_suggestions</b></td>
|
||||||
|
<td>If set to true, the improve tool will calculate an importance score for each suggestion [1-10], and sort the suggestion labels group based on this score. Default is true.</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><b>suggestions_score_threshold</b></td>
|
<td><b>suggestions_score_threshold</b></td>
|
||||||
<td> Any suggestion with importance score less than this threshold will be removed. Default is 0. Highly recommend not to set this value above 7-8, since above it may clip relevant suggestions that can be useful. </td>
|
<td> Any suggestion with importance score less than this threshold will be removed. Default is 0. Highly recommend not to set this value above 7-8, since above it may clip relevant suggestions that can be useful. </td>
|
||||||
@ -299,10 +265,6 @@ Using a combination of both can help the AI model to provide relevant and tailor
|
|||||||
<td><b>enable_chat_text</b></td>
|
<td><b>enable_chat_text</b></td>
|
||||||
<td>If set to true, the tool will display a reference to the PR chat in the comment. Default is true.</td>
|
<td>If set to true, the tool will display a reference to the PR chat in the comment. Default is true.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<td><b>wiki_page_accepted_suggestions</b></td>
|
|
||||||
<td>If set to true, the tool will automatically track accepted suggestions in a dedicated wiki page called `.pr_agent_accepted_suggestions`. Default is true.</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
??? example "Params for number of suggestions and AI calls"
|
??? example "Params for number of suggestions and AI calls"
|
||||||
|
@ -138,9 +138,20 @@ num_code_suggestions = ...
|
|||||||
<td><b>require_security_review</b></td>
|
<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>
|
<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>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
!!! example "SOC2 ticket compliance 💎"
|
||||||
|
|
||||||
|
This sub-tool checks if the PR description properly contains a ticket to a project management system (e.g., Jira, Asana, Trello, etc.), as required by SOC2 compliance. If not, it will add a label to the PR: "Missing SOC2 ticket".
|
||||||
|
|
||||||
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td><b>require_ticket_analysis_review</b></td>
|
<td><b>require_soc2_ticket</b></td>
|
||||||
<td>If set to true, and the PR contains a GitHub or Jira ticket link, the tool will add a section that checks if the PR in fact fulfilled the ticket requirements. Default is true.</td>
|
<td>If set to true, the SOC2 ticket checker sub-tool will be enabled. Default is false.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><b>soc2_ticket_prompt</b></td>
|
||||||
|
<td>The prompt for the SOC2 ticket review. Default is: `Does the PR description include a link to ticket in a project management system (e.g., Jira, Asana, Trello, etc.) ?`. Edit this field if your compliance requirements are different.</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
@ -182,7 +193,7 @@ If enabled, the `review` tool can approve a PR when a specific comment, `/review
|
|||||||
It is recommended to review the [Configuration options](#configuration-options) section, and choose the relevant options for your use case.
|
It is recommended to review the [Configuration options](#configuration-options) section, and choose the relevant options for your use case.
|
||||||
|
|
||||||
Some of the features that are disabled by default are quite useful, and should be considered for enabling. For example:
|
Some of the features that are disabled by default are quite useful, and should be considered for enabling. For example:
|
||||||
`require_score_review`, and more.
|
`require_score_review`, `require_soc2_ticket`, and more.
|
||||||
|
|
||||||
On the other hand, if you find one of the enabled features to be irrelevant for your use case, disable it. No default configuration can fit all use cases.
|
On the other hand, if you find one of the enabled features to be irrelevant for your use case, disable it. No default configuration can fit all use cases.
|
||||||
|
|
||||||
@ -258,3 +269,4 @@ If enabled, the `review` tool can approve a PR when a specific comment, `/review
|
|||||||
[//]: # ( Notice If you are interested **only** in the code suggestions, it is recommended to use the [`improve`](./improve.md) feature instead, since it is a dedicated only to code suggestions, and usually gives better results.)
|
[//]: # ( Notice If you are interested **only** in the code suggestions, it is recommended to use the [`improve`](./improve.md) feature instead, since it is a dedicated only to code suggestions, and usually gives better results.)
|
||||||
|
|
||||||
[//]: # ( Use the `review` tool if you want to get more comprehensive feedback, which includes code suggestions as well.)
|
[//]: # ( Use the `review` tool if you want to get more comprehensive feedback, which includes code suggestions as well.)
|
||||||
|
|
||||||
|
@ -160,13 +160,3 @@ ignore_pr_target_branches = ["qa"]
|
|||||||
|
|
||||||
Where the `ignore_pr_source_branches` and `ignore_pr_target_branches` are lists of regex patterns to match the source and target branches you want to ignore.
|
Where the `ignore_pr_source_branches` and `ignore_pr_target_branches` are lists of regex patterns to match the source and target branches you want to ignore.
|
||||||
They are not mutually exclusive, you can use them together or separately.
|
They are not mutually exclusive, you can use them together or separately.
|
||||||
|
|
||||||
|
|
||||||
To allow only specific folders (often needed in large monorepos), set:
|
|
||||||
|
|
||||||
```
|
|
||||||
[config]
|
|
||||||
allow_only_specific_folders=['folder1','folder2']
|
|
||||||
```
|
|
||||||
|
|
||||||
For the configuration above, automatic feedback will only be triggered when the PR changes include files from 'folder1' or 'folder2'
|
|
||||||
|
@ -72,14 +72,13 @@ The configuration parameter `pr_commands` defines the list of tools that will be
|
|||||||
```
|
```
|
||||||
[github_app]
|
[github_app]
|
||||||
pr_commands = [
|
pr_commands = [
|
||||||
"/describe",
|
"/describe --pr_description.final_update_message=false",
|
||||||
"/review",
|
"/review --pr_reviewer.num_code_suggestions=0",
|
||||||
"/improve --pr_code_suggestions.suggestions_score_threshold=5",
|
"/improve",
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
This means that when a new PR is opened/reopened or marked as ready for review, Qodo Merge will run the `describe`, `review` and `improve` tools.
|
This means that when a new PR is opened/reopened or marked as ready for review, Qodo Merge will run the `describe`, `review` and `improve` tools.
|
||||||
For the `improve` tool, for example, the `suggestions_score_threshold` parameter will be set to 5 (suggestions below a score of 5 won't be presented)
|
For the `review` tool, for example, the `num_code_suggestions` parameter will be set to 0.
|
||||||
|
|
||||||
You can override the default tool parameters by using one the three options for a [configuration file](https://qodo-merge-docs.qodo.ai/usage-guide/configuration_options/): **wiki**, **local**, or **global**.
|
You can override the default tool parameters by using one the three options for a [configuration file](https://qodo-merge-docs.qodo.ai/usage-guide/configuration_options/): **wiki**, **local**, or **global**.
|
||||||
For example, if your local `.pr_agent.toml` file contains:
|
For example, if your local `.pr_agent.toml` file contains:
|
||||||
@ -106,7 +105,7 @@ The configuration parameter `push_commands` defines the list of tools that will
|
|||||||
handle_push_trigger = true
|
handle_push_trigger = true
|
||||||
push_commands = [
|
push_commands = [
|
||||||
"/describe",
|
"/describe",
|
||||||
"/review",
|
"/review --pr_reviewer.num_code_suggestions=0 --pr_reviewer.final_update_message=false",
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
This means that when new code is pushed to the PR, the Qodo Merge will run the `describe` and `review` tools, with the specified parameters.
|
This means that when new code is pushed to the PR, the Qodo Merge will run the `describe` and `review` tools, with the specified parameters.
|
||||||
@ -149,7 +148,7 @@ After setting up a GitLab webhook, to control which commands will run automatica
|
|||||||
[gitlab]
|
[gitlab]
|
||||||
pr_commands = [
|
pr_commands = [
|
||||||
"/describe",
|
"/describe",
|
||||||
"/review",
|
"/review --pr_reviewer.num_code_suggestions=0",
|
||||||
"/improve",
|
"/improve",
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
@ -162,7 +161,7 @@ The configuration parameter `push_commands` defines the list of tools that will
|
|||||||
handle_push_trigger = true
|
handle_push_trigger = true
|
||||||
push_commands = [
|
push_commands = [
|
||||||
"/describe",
|
"/describe",
|
||||||
"/review",
|
"/review --pr_reviewer.num_code_suggestions=0 --pr_reviewer.final_update_message=false",
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -183,7 +182,7 @@ Each time you invoke a `/review` tool, it will use the extra instructions you se
|
|||||||
|
|
||||||
|
|
||||||
Note that among other limitations, BitBucket provides relatively low rate-limits for applications (up to 1000 requests per hour), and does not provide an API to track the actual rate-limit usage.
|
Note that among other limitations, BitBucket provides relatively low rate-limits for applications (up to 1000 requests per hour), and does not provide an API to track the actual rate-limit usage.
|
||||||
If you experience a lack of responses from Qodo Merge, you might want to set: `bitbucket_app.avoid_full_files=true` in your configuration file.
|
If you experience lack of responses from Qodo Merge, you might want to set: `bitbucket_app.avoid_full_files=true` in your configuration file.
|
||||||
This will prevent Qodo Merge from acquiring the full file content, and will only use the diff content. This will reduce the number of requests made to BitBucket, at the cost of small decrease in accuracy, as dynamic context will not be applicable.
|
This will prevent Qodo Merge from acquiring the full file content, and will only use the diff content. This will reduce the number of requests made to BitBucket, at the cost of small decrease in accuracy, as dynamic context will not be applicable.
|
||||||
|
|
||||||
|
|
||||||
@ -195,23 +194,13 @@ Specifically, set the following values:
|
|||||||
```
|
```
|
||||||
[bitbucket_app]
|
[bitbucket_app]
|
||||||
pr_commands = [
|
pr_commands = [
|
||||||
"/review",
|
"/review --pr_reviewer.num_code_suggestions=0",
|
||||||
"/improve --pr_code_suggestions.commitable_code_suggestions=true --pr_code_suggestions.suggestions_score_threshold=7",
|
"/improve --pr_code_suggestions.commitable_code_suggestions=true --pr_code_suggestions.suggestions_score_threshold=7",
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
Note that we set specifically for bitbucket, we recommend using: `--pr_code_suggestions.suggestions_score_threshold=7` and that is the default value we set for bitbucket.
|
Note that we set specifically for bitbucket, we recommend using: `--pr_code_suggestions.suggestions_score_threshold=7` and that is the default value we set for bitbucket.
|
||||||
Since this platform only supports inline code suggestions, we want to limit the number of suggestions, and only present a limited number.
|
Since this platform only supports inline code suggestions, we want to limit the number of suggestions, and only present a limited number.
|
||||||
|
|
||||||
To enable BitBucket app to respond to each **push** to the PR, set (for example):
|
|
||||||
```
|
|
||||||
[bitbucket_app]
|
|
||||||
handle_push_trigger = true
|
|
||||||
push_commands = [
|
|
||||||
"/describe",
|
|
||||||
"/review",
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
## Azure DevOps provider
|
## Azure DevOps provider
|
||||||
|
|
||||||
To use Azure DevOps provider use the following settings in configuration.toml:
|
To use Azure DevOps provider use the following settings in configuration.toml:
|
||||||
|
@ -133,26 +133,9 @@ Your [application default credentials](https://cloud.google.com/docs/authenticat
|
|||||||
|
|
||||||
If you do want to set explicit credentials, then you can use the `GOOGLE_APPLICATION_CREDENTIALS` environment variable set to a path to a json credentials file.
|
If you do want to set explicit credentials, then you can use the `GOOGLE_APPLICATION_CREDENTIALS` environment variable set to a path to a json credentials file.
|
||||||
|
|
||||||
### Google AI Studio
|
|
||||||
|
|
||||||
To use [Google AI Studio](https://aistudio.google.com/) models, set the relevant models in the configuration section of the configuration file:
|
|
||||||
|
|
||||||
```toml
|
|
||||||
[config] # in configuration.toml
|
|
||||||
model="google_ai_studio/gemini-1.5-flash"
|
|
||||||
model_turbo="google_ai_studio/gemini-1.5-flash"
|
|
||||||
fallback_models=["google_ai_studio/gemini-1.5-flash"]
|
|
||||||
|
|
||||||
[google_ai_studio] # in .secrets.toml
|
|
||||||
gemini_api_key = "..."
|
|
||||||
```
|
|
||||||
|
|
||||||
If you don't want to set the API key in the .secrets.toml file, you can set the `GOOGLE_AI_STUDIO.GEMINI_API_KEY` environment variable.
|
|
||||||
|
|
||||||
### Anthropic
|
### Anthropic
|
||||||
|
|
||||||
To use Anthropic models, set the relevant models in the configuration section of the configuration file:
|
To use Anthropic models, set the relevant models in the configuration section of the configuration file:
|
||||||
|
|
||||||
```
|
```
|
||||||
[config]
|
[config]
|
||||||
model="anthropic/claude-3-opus-20240229"
|
model="anthropic/claude-3-opus-20240229"
|
||||||
|
@ -18,7 +18,7 @@ In terms of precedence, wiki configurations will override local configurations,
|
|||||||
|
|
||||||
## Wiki configuration file 💎
|
## Wiki configuration file 💎
|
||||||
|
|
||||||
`Platforms supported: GitHub, GitLab, Bitbucket`
|
`Platforms supported: GitHub, GitLab`
|
||||||
|
|
||||||
With Qodo Merge Pro, you can set configurations by creating a page called `.pr_agent.toml` in the [wiki](https://github.com/Codium-ai/pr-agent/wiki/pr_agent.toml) of the repo.
|
With Qodo Merge Pro, you can set configurations by creating a page called `.pr_agent.toml` in the [wiki](https://github.com/Codium-ai/pr-agent/wiki/pr_agent.toml) of the repo.
|
||||||
The advantage of this method is that it allows to set configurations without needing to commit new content to the repo - just edit the wiki page and **save**.
|
The advantage of this method is that it allows to set configurations without needing to commit new content to the repo - just edit the wiki page and **save**.
|
||||||
|
@ -10,3 +10,4 @@ Specifically, CLI commands can be issued by invoking a pre-built [docker image](
|
|||||||
|
|
||||||
For online usage, you will need to setup either a [GitHub App](https://qodo-merge-docs.qodo.ai/installation/github/#run-as-a-github-app) or a [GitHub Action](https://qodo-merge-docs.qodo.ai/installation/github/#run-as-a-github-action) (GitHub), a [GitLab webhook](https://qodo-merge-docs.qodo.ai/installation/gitlab/#run-a-gitlab-webhook-server) (GitLab), or a [BitBucket App](https://qodo-merge-docs.qodo.ai/installation/bitbucket/#run-using-codiumai-hosted-bitbucket-app) (BitBucket).
|
For online usage, you will need to setup either a [GitHub App](https://qodo-merge-docs.qodo.ai/installation/github/#run-as-a-github-app) or a [GitHub Action](https://qodo-merge-docs.qodo.ai/installation/github/#run-as-a-github-action) (GitHub), a [GitLab webhook](https://qodo-merge-docs.qodo.ai/installation/gitlab/#run-a-gitlab-webhook-server) (GitLab), or a [BitBucket App](https://qodo-merge-docs.qodo.ai/installation/bitbucket/#run-using-codiumai-hosted-bitbucket-app) (BitBucket).
|
||||||
These platforms also enable to run Qodo Merge specific tools automatically when a new PR is opened, or on each push to a branch.
|
These platforms also enable to run Qodo Merge specific tools automatically when a new PR is opened, or on each push to a branch.
|
||||||
|
|
||||||
|
@ -43,7 +43,6 @@ nav:
|
|||||||
- 💎 Similar Code: 'tools/similar_code.md'
|
- 💎 Similar Code: 'tools/similar_code.md'
|
||||||
- Core Abilities:
|
- Core Abilities:
|
||||||
- 'core-abilities/index.md'
|
- 'core-abilities/index.md'
|
||||||
- Fetching ticket context: 'core-abilities/fetching_ticket_context.md'
|
|
||||||
- Local and global metadata: 'core-abilities/metadata.md'
|
- Local and global metadata: 'core-abilities/metadata.md'
|
||||||
- Dynamic context: 'core-abilities/dynamic_context.md'
|
- Dynamic context: 'core-abilities/dynamic_context.md'
|
||||||
- Self-reflection: 'core-abilities/self_reflection.md'
|
- Self-reflection: 'core-abilities/self_reflection.md'
|
||||||
|
@ -82,11 +82,11 @@
|
|||||||
|
|
||||||
<footer class="wrapper">
|
<footer class="wrapper">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<p class="footer-text">© 2024 <a href="https://www.qodo.ai/" target="_blank" rel="noopener">Qodo</a></p>
|
<p class="footer-text">© 2024 <a href="https://www.codium.ai/" target="_blank" rel="noopener">CodiumAI</a></p>
|
||||||
<div class="footer-links">
|
<div class="footer-links">
|
||||||
<a href="https://qodo-gen-docs.qodo.ai/">Qodo Gen</a>
|
<a href="https://codiumate-docs.codium.ai/">Codiumate</a>
|
||||||
<p>|</p>
|
<p>|</p>
|
||||||
<a href="https://qodo-flow-docs.qodo.ai/">AlphaCodium</a>
|
<a href="https://alpha-codium-docs.codium.ai/">AlphaCodium</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="social-icons">
|
<div class="social-icons">
|
||||||
<a href="https://github.com/Codium-ai" target="_blank" rel="noopener" title="github.com" class="social-link">
|
<a href="https://github.com/Codium-ai" target="_blank" rel="noopener" title="github.com" class="social-link">
|
||||||
@ -95,16 +95,16 @@
|
|||||||
<a href="https://discord.com/invite/SgSxuQ65GF" target="_blank" rel="noopener" title="discord.com" class="social-link">
|
<a href="https://discord.com/invite/SgSxuQ65GF" target="_blank" rel="noopener" title="discord.com" class="social-link">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!--! Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M524.531 69.836a1.5 1.5 0 0 0-.764-.7A485.065 485.065 0 0 0 404.081 32.03a1.816 1.816 0 0 0-1.923.91 337.461 337.461 0 0 0-14.9 30.6 447.848 447.848 0 0 0-134.426 0 309.541 309.541 0 0 0-15.135-30.6 1.89 1.89 0 0 0-1.924-.91 483.689 483.689 0 0 0-119.688 37.107 1.712 1.712 0 0 0-.788.676C39.068 183.651 18.186 294.69 28.43 404.354a2.016 2.016 0 0 0 .765 1.375 487.666 487.666 0 0 0 146.825 74.189 1.9 1.9 0 0 0 2.063-.676A348.2 348.2 0 0 0 208.12 430.4a1.86 1.86 0 0 0-1.019-2.588 321.173 321.173 0 0 1-45.868-21.853 1.885 1.885 0 0 1-.185-3.126 251.047 251.047 0 0 0 9.109-7.137 1.819 1.819 0 0 1 1.9-.256c96.229 43.917 200.41 43.917 295.5 0a1.812 1.812 0 0 1 1.924.233 234.533 234.533 0 0 0 9.132 7.16 1.884 1.884 0 0 1-.162 3.126 301.407 301.407 0 0 1-45.89 21.83 1.875 1.875 0 0 0-1 2.611 391.055 391.055 0 0 0 30.014 48.815 1.864 1.864 0 0 0 2.063.7A486.048 486.048 0 0 0 610.7 405.729a1.882 1.882 0 0 0 .765-1.352c12.264-126.783-20.532-236.912-86.934-334.541ZM222.491 337.58c-28.972 0-52.844-26.587-52.844-59.239s23.409-59.241 52.844-59.241c29.665 0 53.306 26.82 52.843 59.239 0 32.654-23.41 59.241-52.843 59.241Zm195.38 0c-28.971 0-52.843-26.587-52.843-59.239s23.409-59.241 52.843-59.241c29.667 0 53.307 26.82 52.844 59.239 0 32.654-23.177 59.241-52.844 59.241Z"></path></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><!--! Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M524.531 69.836a1.5 1.5 0 0 0-.764-.7A485.065 485.065 0 0 0 404.081 32.03a1.816 1.816 0 0 0-1.923.91 337.461 337.461 0 0 0-14.9 30.6 447.848 447.848 0 0 0-134.426 0 309.541 309.541 0 0 0-15.135-30.6 1.89 1.89 0 0 0-1.924-.91 483.689 483.689 0 0 0-119.688 37.107 1.712 1.712 0 0 0-.788.676C39.068 183.651 18.186 294.69 28.43 404.354a2.016 2.016 0 0 0 .765 1.375 487.666 487.666 0 0 0 146.825 74.189 1.9 1.9 0 0 0 2.063-.676A348.2 348.2 0 0 0 208.12 430.4a1.86 1.86 0 0 0-1.019-2.588 321.173 321.173 0 0 1-45.868-21.853 1.885 1.885 0 0 1-.185-3.126 251.047 251.047 0 0 0 9.109-7.137 1.819 1.819 0 0 1 1.9-.256c96.229 43.917 200.41 43.917 295.5 0a1.812 1.812 0 0 1 1.924.233 234.533 234.533 0 0 0 9.132 7.16 1.884 1.884 0 0 1-.162 3.126 301.407 301.407 0 0 1-45.89 21.83 1.875 1.875 0 0 0-1 2.611 391.055 391.055 0 0 0 30.014 48.815 1.864 1.864 0 0 0 2.063.7A486.048 486.048 0 0 0 610.7 405.729a1.882 1.882 0 0 0 .765-1.352c12.264-126.783-20.532-236.912-86.934-334.541ZM222.491 337.58c-28.972 0-52.844-26.587-52.844-59.239s23.409-59.241 52.844-59.241c29.665 0 53.306 26.82 52.843 59.239 0 32.654-23.41 59.241-52.843 59.241Zm195.38 0c-28.971 0-52.843-26.587-52.843-59.239s23.409-59.241 52.843-59.241c29.667 0 53.307 26.82 52.844 59.239 0 32.654-23.177 59.241-52.844 59.241Z"></path></svg>
|
||||||
</a>
|
</a>
|
||||||
<a href="https://www.youtube.com/@QodoAI" target="_blank" rel="noopener" title="www.youtube.com" class="social-link">
|
<a href="https://www.youtube.com/@Codium-AI" target="_blank" rel="noopener" title="www.youtube.com" class="social-link">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><!--! Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M549.655 124.083c-6.281-23.65-24.787-42.276-48.284-48.597C458.781 64 288 64 288 64S117.22 64 74.629 75.486c-23.497 6.322-42.003 24.947-48.284 48.597-11.412 42.867-11.412 132.305-11.412 132.305s0 89.438 11.412 132.305c6.281 23.65 24.787 41.5 48.284 47.821C117.22 448 288 448 288 448s170.78 0 213.371-11.486c23.497-6.321 42.003-24.171 48.284-47.821 11.412-42.867 11.412-132.305 11.412-132.305s0-89.438-11.412-132.305zm-317.51 213.508V175.185l142.739 81.205-142.739 81.201z"></path></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><!--! Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M549.655 124.083c-6.281-23.65-24.787-42.276-48.284-48.597C458.781 64 288 64 288 64S117.22 64 74.629 75.486c-23.497 6.322-42.003 24.947-48.284 48.597-11.412 42.867-11.412 132.305-11.412 132.305s0 89.438 11.412 132.305c6.281 23.65 24.787 41.5 48.284 47.821C117.22 448 288 448 288 448s170.78 0 213.371-11.486c23.497-6.321 42.003-24.171 48.284-47.821 11.412-42.867 11.412-132.305 11.412-132.305s0-89.438-11.412-132.305zm-317.51 213.508V175.185l142.739 81.205-142.739 81.201z"></path></svg>
|
||||||
</a>
|
</a>
|
||||||
<a href="https://www.linkedin.com/company/qodoai" target="_blank" rel="noopener" title="www.linkedin.com" class="social-link">
|
<a href="https://www.linkedin.com/company/codiumai" target="_blank" rel="noopener" title="www.linkedin.com" class="social-link">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M416 32H31.9C14.3 32 0 46.5 0 64.3v383.4C0 465.5 14.3 480 31.9 480H416c17.6 0 32-14.5 32-32.3V64.3c0-17.8-14.4-32.3-32-32.3zM135.4 416H69V202.2h66.5V416zm-33.2-243c-21.3 0-38.5-17.3-38.5-38.5S80.9 96 102.2 96c21.2 0 38.5 17.3 38.5 38.5 0 21.3-17.2 38.5-38.5 38.5zm282.1 243h-66.4V312c0-24.8-.5-56.7-34.5-56.7-34.6 0-39.9 27-39.9 54.9V416h-66.4V202.2h63.7v29.2h.9c8.9-16.8 30.6-34.5 62.9-34.5 67.2 0 79.7 44.3 79.7 101.9V416z"></path></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M416 32H31.9C14.3 32 0 46.5 0 64.3v383.4C0 465.5 14.3 480 31.9 480H416c17.6 0 32-14.5 32-32.3V64.3c0-17.8-14.4-32.3-32-32.3zM135.4 416H69V202.2h66.5V416zm-33.2-243c-21.3 0-38.5-17.3-38.5-38.5S80.9 96 102.2 96c21.2 0 38.5 17.3 38.5 38.5 0 21.3-17.2 38.5-38.5 38.5zm282.1 243h-66.4V312c0-24.8-.5-56.7-34.5-56.7-34.6 0-39.9 27-39.9 54.9V416h-66.4V202.2h63.7v29.2h.9c8.9-16.8 30.6-34.5 62.9-34.5 67.2 0 79.7 44.3 79.7 101.9V416z"></path></svg>
|
||||||
</a>
|
</a>
|
||||||
<a href="https://twitter.com/QodoAI" target="_blank" rel="noopener" title="twitter.com" class="social-link">
|
<a href="https://twitter.com/CodiumAI" target="_blank" rel="noopener" title="twitter.com" class="social-link">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M459.37 151.716c.325 4.548.325 9.097.325 13.645 0 138.72-105.583 298.558-298.558 298.558-59.452 0-114.68-17.219-161.137-47.106 8.447.974 16.568 1.299 25.34 1.299 49.055 0 94.213-16.568 130.274-44.832-46.132-.975-84.792-31.188-98.112-72.772 6.498.974 12.995 1.624 19.818 1.624 9.421 0 18.843-1.3 27.614-3.573-48.081-9.747-84.143-51.98-84.143-102.985v-1.299c13.969 7.797 30.214 12.67 47.431 13.319-28.264-18.843-46.781-51.005-46.781-87.391 0-19.492 5.197-37.36 14.294-52.954 51.655 63.675 129.3 105.258 216.365 109.807-1.624-7.797-2.599-15.918-2.599-24.04 0-57.828 46.782-104.934 104.934-104.934 30.213 0 57.502 12.67 76.67 33.137 23.715-4.548 46.456-13.32 66.599-25.34-7.798 24.366-24.366 44.833-46.132 57.827 21.117-2.273 41.584-8.122 60.426-16.243-14.292 20.791-32.161 39.308-52.628 54.253z"></path></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M459.37 151.716c.325 4.548.325 9.097.325 13.645 0 138.72-105.583 298.558-298.558 298.558-59.452 0-114.68-17.219-161.137-47.106 8.447.974 16.568 1.299 25.34 1.299 49.055 0 94.213-16.568 130.274-44.832-46.132-.975-84.792-31.188-98.112-72.772 6.498.974 12.995 1.624 19.818 1.624 9.421 0 18.843-1.3 27.614-3.573-48.081-9.747-84.143-51.98-84.143-102.985v-1.299c13.969 7.797 30.214 12.67 47.431 13.319-28.264-18.843-46.781-51.005-46.781-87.391 0-19.492 5.197-37.36 14.294-52.954 51.655 63.675 129.3 105.258 216.365 109.807-1.624-7.797-2.599-15.918-2.599-24.04 0-57.828 46.782-104.934 104.934-104.934 30.213 0 57.502 12.67 76.67 33.137 23.715-4.548 46.456-13.32 66.599-25.34-7.798 24.366-24.366 44.833-46.132 57.827 21.117-2.273 41.584-8.122 60.426-16.243-14.292 20.791-32.161 39.308-52.628 54.253z"></path></svg>
|
||||||
</a>
|
</a>
|
||||||
<a href="https://www.instagram.com/qodo_ai" target="_blank" rel="noopener" title="www.instagram.com" class="social-link">
|
<a href="https://www.instagram.com/codiumai/" target="_blank" rel="noopener" title="www.instagram.com" class="social-link">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M224.1 141c-63.6 0-114.9 51.3-114.9 114.9s51.3 114.9 114.9 114.9S339 319.5 339 255.9 287.7 141 224.1 141zm0 189.6c-41.1 0-74.7-33.5-74.7-74.7s33.5-74.7 74.7-74.7 74.7 33.5 74.7 74.7-33.6 74.7-74.7 74.7zm146.4-194.3c0 14.9-12 26.8-26.8 26.8-14.9 0-26.8-12-26.8-26.8s12-26.8 26.8-26.8 26.8 12 26.8 26.8zm76.1 27.2c-1.7-35.9-9.9-67.7-36.2-93.9-26.2-26.2-58-34.4-93.9-36.2-37-2.1-147.9-2.1-184.9 0-35.8 1.7-67.6 9.9-93.9 36.1s-34.4 58-36.2 93.9c-2.1 37-2.1 147.9 0 184.9 1.7 35.9 9.9 67.7 36.2 93.9s58 34.4 93.9 36.2c37 2.1 147.9 2.1 184.9 0 35.9-1.7 67.7-9.9 93.9-36.2 26.2-26.2 34.4-58 36.2-93.9 2.1-37 2.1-147.8 0-184.8zM398.8 388c-7.8 19.6-22.9 34.7-42.6 42.6-29.5 11.7-99.5 9-132.1 9s-102.7 2.6-132.1-9c-19.6-7.8-34.7-22.9-42.6-42.6-11.7-29.5-9-99.5-9-132.1s-2.6-102.7 9-132.1c7.8-19.6 22.9-34.7 42.6-42.6 29.5-11.7 99.5-9 132.1-9s102.7-2.6 132.1 9c19.6 7.8 34.7 22.9 42.6 42.6 11.7 29.5 9 99.5 9 132.1s2.7 102.7-9 132.1z"></path></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.5.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M224.1 141c-63.6 0-114.9 51.3-114.9 114.9s51.3 114.9 114.9 114.9S339 319.5 339 255.9 287.7 141 224.1 141zm0 189.6c-41.1 0-74.7-33.5-74.7-74.7s33.5-74.7 74.7-74.7 74.7 33.5 74.7 74.7-33.6 74.7-74.7 74.7zm146.4-194.3c0 14.9-12 26.8-26.8 26.8-14.9 0-26.8-12-26.8-26.8s12-26.8 26.8-26.8 26.8 12 26.8 26.8zm76.1 27.2c-1.7-35.9-9.9-67.7-36.2-93.9-26.2-26.2-58-34.4-93.9-36.2-37-2.1-147.9-2.1-184.9 0-35.8 1.7-67.6 9.9-93.9 36.1s-34.4 58-36.2 93.9c-2.1 37-2.1 147.9 0 184.9 1.7 35.9 9.9 67.7 36.2 93.9s58 34.4 93.9 36.2c37 2.1 147.9 2.1 184.9 0 35.9-1.7 67.7-9.9 93.9-36.2 26.2-26.2 34.4-58 36.2-93.9 2.1-37 2.1-147.8 0-184.8zM398.8 388c-7.8 19.6-22.9 34.7-42.6 42.6-29.5 11.7-99.5 9-132.1 9s-102.7 2.6-132.1-9c-19.6-7.8-34.7-22.9-42.6-42.6-11.7-29.5-9-99.5-9-132.1s-2.6-102.7 9-132.1c7.8-19.6 22.9-34.7 42.6-42.6 29.5-11.7 99.5-9 132.1-9s102.7-2.6 132.1 9c19.6 7.8 34.7 22.9 42.6 42.6 11.7 29.5 9 99.5 9 132.1s2.7 102.7-9 132.1z"></path></svg>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
|
||||||
|
@ -3,6 +3,7 @@ from functools import partial
|
|||||||
|
|
||||||
from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler
|
from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler
|
||||||
from pr_agent.algo.ai_handlers.litellm_ai_handler import LiteLLMAIHandler
|
from pr_agent.algo.ai_handlers.litellm_ai_handler import LiteLLMAIHandler
|
||||||
|
|
||||||
from pr_agent.algo.utils import update_settings_from_args
|
from pr_agent.algo.utils import update_settings_from_args
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
from pr_agent.git_providers.utils import apply_repo_settings
|
from pr_agent.git_providers.utils import apply_repo_settings
|
||||||
|
@ -31,16 +31,12 @@ MAX_TOKENS = {
|
|||||||
'vertex_ai/codechat-bison': 6144,
|
'vertex_ai/codechat-bison': 6144,
|
||||||
'vertex_ai/codechat-bison-32k': 32000,
|
'vertex_ai/codechat-bison-32k': 32000,
|
||||||
'vertex_ai/claude-3-haiku@20240307': 100000,
|
'vertex_ai/claude-3-haiku@20240307': 100000,
|
||||||
'vertex_ai/claude-3-5-haiku@20241022': 100000,
|
|
||||||
'vertex_ai/claude-3-sonnet@20240229': 100000,
|
'vertex_ai/claude-3-sonnet@20240229': 100000,
|
||||||
'vertex_ai/claude-3-opus@20240229': 100000,
|
'vertex_ai/claude-3-opus@20240229': 100000,
|
||||||
'vertex_ai/claude-3-5-sonnet@20240620': 100000,
|
'vertex_ai/claude-3-5-sonnet@20240620': 100000,
|
||||||
'vertex_ai/claude-3-5-sonnet-v2@20241022': 100000,
|
|
||||||
'vertex_ai/gemini-1.5-pro': 1048576,
|
'vertex_ai/gemini-1.5-pro': 1048576,
|
||||||
'vertex_ai/gemini-1.5-flash': 1048576,
|
'vertex_ai/gemini-1.5-flash': 1048576,
|
||||||
'vertex_ai/gemma2': 8200,
|
'vertex_ai/gemma2': 8200,
|
||||||
'gemini/gemini-1.5-pro': 1048576,
|
|
||||||
'gemini/gemini-1.5-flash': 1048576,
|
|
||||||
'codechat-bison': 6144,
|
'codechat-bison': 6144,
|
||||||
'codechat-bison-32k': 32000,
|
'codechat-bison-32k': 32000,
|
||||||
'anthropic.claude-instant-v1': 100000,
|
'anthropic.claude-instant-v1': 100000,
|
||||||
@ -48,16 +44,12 @@ MAX_TOKENS = {
|
|||||||
'anthropic.claude-v2': 100000,
|
'anthropic.claude-v2': 100000,
|
||||||
'anthropic/claude-3-opus-20240229': 100000,
|
'anthropic/claude-3-opus-20240229': 100000,
|
||||||
'anthropic/claude-3-5-sonnet-20240620': 100000,
|
'anthropic/claude-3-5-sonnet-20240620': 100000,
|
||||||
'anthropic/claude-3-5-sonnet-20241022': 100000,
|
|
||||||
'anthropic/claude-3-5-haiku-20241022': 100000,
|
|
||||||
'bedrock/anthropic.claude-instant-v1': 100000,
|
'bedrock/anthropic.claude-instant-v1': 100000,
|
||||||
'bedrock/anthropic.claude-v2': 100000,
|
'bedrock/anthropic.claude-v2': 100000,
|
||||||
'bedrock/anthropic.claude-v2:1': 100000,
|
'bedrock/anthropic.claude-v2:1': 100000,
|
||||||
'bedrock/anthropic.claude-3-sonnet-20240229-v1:0': 100000,
|
'bedrock/anthropic.claude-3-sonnet-20240229-v1:0': 100000,
|
||||||
'bedrock/anthropic.claude-3-haiku-20240307-v1:0': 100000,
|
'bedrock/anthropic.claude-3-haiku-20240307-v1:0': 100000,
|
||||||
'bedrock/anthropic.claude-3-5-haiku-20241022-v1:0': 100000,
|
|
||||||
'bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0': 100000,
|
'bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0': 100000,
|
||||||
'bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0': 100000,
|
|
||||||
'claude-3-5-sonnet': 100000,
|
'claude-3-5-sonnet': 100000,
|
||||||
'groq/llama3-8b-8192': 8192,
|
'groq/llama3-8b-8192': 8192,
|
||||||
'groq/llama3-70b-8192': 8192,
|
'groq/llama3-70b-8192': 8192,
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
try:
|
try:
|
||||||
from langchain_core.messages import HumanMessage, SystemMessage
|
from langchain_openai import ChatOpenAI, AzureChatOpenAI
|
||||||
from langchain_openai import AzureChatOpenAI, ChatOpenAI
|
from langchain_core.messages import SystemMessage, HumanMessage
|
||||||
except: # we don't enforce langchain as a dependency, so if it's not installed, just move on
|
except: # we don't enforce langchain as a dependency, so if it's not installed, just move on
|
||||||
pass
|
pass
|
||||||
|
|
||||||
import functools
|
|
||||||
|
|
||||||
from openai import APIError, RateLimitError, Timeout
|
|
||||||
from retry import retry
|
|
||||||
|
|
||||||
from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler
|
from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
from pr_agent.log import get_logger
|
from pr_agent.log import get_logger
|
||||||
|
|
||||||
|
from openai import APIError, RateLimitError, Timeout
|
||||||
|
from retry import retry
|
||||||
|
import functools
|
||||||
|
|
||||||
OPENAI_RETRIES = 5
|
OPENAI_RETRIES = 5
|
||||||
|
|
||||||
|
|
||||||
@ -74,3 +73,4 @@ class LangChainOpenAIHandler(BaseAiHandler):
|
|||||||
raise ValueError(f"OpenAI {e.name} is required") from e
|
raise ValueError(f"OpenAI {e.name} is required") from e
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
|
import requests
|
||||||
import litellm
|
import litellm
|
||||||
import openai
|
import openai
|
||||||
import requests
|
|
||||||
from litellm import acompletion
|
from litellm import acompletion
|
||||||
from tenacity import retry, retry_if_exception_type, stop_after_attempt
|
from tenacity import retry, retry_if_exception_type, stop_after_attempt
|
||||||
|
|
||||||
@ -84,11 +83,6 @@ class LiteLLMAIHandler(BaseAiHandler):
|
|||||||
litellm.vertex_location = get_settings().get(
|
litellm.vertex_location = get_settings().get(
|
||||||
"VERTEXAI.VERTEX_LOCATION", None
|
"VERTEXAI.VERTEX_LOCATION", None
|
||||||
)
|
)
|
||||||
# Google AI Studio
|
|
||||||
# SEE https://docs.litellm.ai/docs/providers/gemini
|
|
||||||
if get_settings().get("GOOGLE_AI_STUDIO.GEMINI_API_KEY", None):
|
|
||||||
os.environ["GEMINI_API_KEY"] = get_settings().google_ai_studio.gemini_api_key
|
|
||||||
|
|
||||||
def prepare_logs(self, response, system, user, resp, finish_reason):
|
def prepare_logs(self, response, system, user, resp, finish_reason):
|
||||||
response_log = response.dict().copy()
|
response_log = response.dict().copy()
|
||||||
response_log['system'] = system
|
response_log['system'] = system
|
||||||
@ -177,7 +171,6 @@ class LiteLLMAIHandler(BaseAiHandler):
|
|||||||
get_logger().warning(
|
get_logger().warning(
|
||||||
"Empty system prompt for claude model. Adding a newline character to prevent OpenAI API error.")
|
"Empty system prompt for claude model. Adding a newline character to prevent OpenAI API error.")
|
||||||
messages = [{"role": "system", "content": system}, {"role": "user", "content": user}]
|
messages = [{"role": "system", "content": system}, {"role": "user", "content": user}]
|
||||||
|
|
||||||
if img_path:
|
if img_path:
|
||||||
try:
|
try:
|
||||||
# check if the image link is alive
|
# check if the image link is alive
|
||||||
@ -192,22 +185,6 @@ class LiteLLMAIHandler(BaseAiHandler):
|
|||||||
messages[1]["content"] = [{"type": "text", "text": messages[1]["content"]},
|
messages[1]["content"] = [{"type": "text", "text": messages[1]["content"]},
|
||||||
{"type": "image_url", "image_url": {"url": img_path}}]
|
{"type": "image_url", "image_url": {"url": img_path}}]
|
||||||
|
|
||||||
# Currently O1 does not support separate system and user prompts
|
|
||||||
O1_MODEL_PREFIX = 'o1-'
|
|
||||||
model_type = model.split('/')[-1] if '/' in model else model
|
|
||||||
if model_type.startswith(O1_MODEL_PREFIX):
|
|
||||||
user = f"{system}\n\n\n{user}"
|
|
||||||
system = ""
|
|
||||||
get_logger().info(f"Using O1 model, combining system and user prompts")
|
|
||||||
messages = [{"role": "user", "content": user}]
|
|
||||||
kwargs = {
|
|
||||||
"model": model,
|
|
||||||
"deployment_id": deployment_id,
|
|
||||||
"messages": messages,
|
|
||||||
"timeout": get_settings().config.ai_timeout,
|
|
||||||
"api_base": self.api_base,
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
kwargs = {
|
kwargs = {
|
||||||
"model": model,
|
"model": model,
|
||||||
"deployment_id": deployment_id,
|
"deployment_id": deployment_id,
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
from os import environ
|
|
||||||
from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler
|
from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler
|
||||||
import openai
|
import openai
|
||||||
from openai import APIError, AsyncOpenAI, RateLimitError, Timeout
|
from openai.error import APIError, RateLimitError, Timeout, TryAgain
|
||||||
from retry import retry
|
from retry import retry
|
||||||
|
|
||||||
from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler
|
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
from pr_agent.log import get_logger
|
from pr_agent.log import get_logger
|
||||||
|
|
||||||
@ -16,7 +14,7 @@ class OpenAIHandler(BaseAiHandler):
|
|||||||
# Initialize OpenAIHandler specific attributes here
|
# Initialize OpenAIHandler specific attributes here
|
||||||
try:
|
try:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
environ["OPENAI_API_KEY"] = get_settings().openai.key
|
openai.api_key = get_settings().openai.key
|
||||||
if get_settings().get("OPENAI.ORG", None):
|
if get_settings().get("OPENAI.ORG", None):
|
||||||
openai.organization = get_settings().openai.org
|
openai.organization = get_settings().openai.org
|
||||||
if get_settings().get("OPENAI.API_TYPE", None):
|
if get_settings().get("OPENAI.API_TYPE", None):
|
||||||
@ -26,7 +24,7 @@ class OpenAIHandler(BaseAiHandler):
|
|||||||
if get_settings().get("OPENAI.API_VERSION", None):
|
if get_settings().get("OPENAI.API_VERSION", None):
|
||||||
openai.api_version = get_settings().openai.api_version
|
openai.api_version = get_settings().openai.api_version
|
||||||
if get_settings().get("OPENAI.API_BASE", None):
|
if get_settings().get("OPENAI.API_BASE", None):
|
||||||
environ["OPENAI_BASE_URL"] = get_settings().openai.api_base
|
openai.api_base = get_settings().openai.api_base
|
||||||
|
|
||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
raise ValueError("OpenAI key is required") from e
|
raise ValueError("OpenAI key is required") from e
|
||||||
@ -38,26 +36,28 @@ class OpenAIHandler(BaseAiHandler):
|
|||||||
"""
|
"""
|
||||||
return get_settings().get("OPENAI.DEPLOYMENT_ID", None)
|
return get_settings().get("OPENAI.DEPLOYMENT_ID", None)
|
||||||
|
|
||||||
@retry(exceptions=(APIError, Timeout, AttributeError, RateLimitError),
|
@retry(exceptions=(APIError, Timeout, TryAgain, AttributeError, RateLimitError),
|
||||||
tries=OPENAI_RETRIES, delay=2, backoff=2, jitter=(1, 3))
|
tries=OPENAI_RETRIES, delay=2, backoff=2, jitter=(1, 3))
|
||||||
async def chat_completion(self, model: str, system: str, user: str, temperature: float = 0.2):
|
async def chat_completion(self, model: str, system: str, user: str, temperature: float = 0.2):
|
||||||
try:
|
try:
|
||||||
|
deployment_id = self.deployment_id
|
||||||
get_logger().info("System: ", system)
|
get_logger().info("System: ", system)
|
||||||
get_logger().info("User: ", user)
|
get_logger().info("User: ", user)
|
||||||
messages = [{"role": "system", "content": system}, {"role": "user", "content": user}]
|
messages = [{"role": "system", "content": system}, {"role": "user", "content": user}]
|
||||||
client = AsyncOpenAI()
|
|
||||||
chat_completion = await client.chat.completions.create(
|
chat_completion = await openai.ChatCompletion.acreate(
|
||||||
model=model,
|
model=model,
|
||||||
|
deployment_id=deployment_id,
|
||||||
messages=messages,
|
messages=messages,
|
||||||
temperature=temperature,
|
temperature=temperature,
|
||||||
)
|
)
|
||||||
resp = chat_completion.choices[0].message.content
|
resp = chat_completion["choices"][0]['message']['content']
|
||||||
finish_reason = chat_completion.choices[0].finish_reason
|
finish_reason = chat_completion["choices"][0]["finish_reason"]
|
||||||
usage = chat_completion.usage
|
usage = chat_completion.get("usage")
|
||||||
get_logger().info("AI response", response=resp, messages=messages, finish_reason=finish_reason,
|
get_logger().info("AI response", response=resp, messages=messages, finish_reason=finish_reason,
|
||||||
model=model, usage=usage)
|
model=model, usage=usage)
|
||||||
return resp, finish_reason
|
return resp, finish_reason
|
||||||
except (APIError, Timeout) as e:
|
except (APIError, Timeout, TryAgain) as e:
|
||||||
get_logger().error("Error during OpenAI inference: ", e)
|
get_logger().error("Error during OpenAI inference: ", e)
|
||||||
raise
|
raise
|
||||||
except (RateLimitError) as e:
|
except (RateLimitError) as e:
|
||||||
@ -65,4 +65,4 @@ class OpenAIHandler(BaseAiHandler):
|
|||||||
raise
|
raise
|
||||||
except (Exception) as e:
|
except (Exception) as e:
|
||||||
get_logger().error("Unknown error during OpenAI inference: ", e)
|
get_logger().error("Unknown error during OpenAI inference: ", e)
|
||||||
raise
|
raise TryAgain from e
|
||||||
|
@ -3,8 +3,8 @@ from __future__ import annotations
|
|||||||
import re
|
import re
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
|
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
|
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
|
||||||
from pr_agent.log import get_logger
|
from pr_agent.log import get_logger
|
||||||
|
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ def extend_patch(original_file_str, patch_str, patch_extra_lines_before=0,
|
|||||||
|
|
||||||
|
|
||||||
def decode_if_bytes(original_file_str):
|
def decode_if_bytes(original_file_str):
|
||||||
if isinstance(original_file_str, (bytes, bytearray)):
|
if isinstance(original_file_str, bytes):
|
||||||
try:
|
try:
|
||||||
return original_file_str.decode('utf-8')
|
return original_file_str.decode('utf-8')
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
@ -61,26 +61,23 @@ def process_patch_lines(patch_str, original_file_str, patch_extra_lines_before,
|
|||||||
patch_lines = patch_str.splitlines()
|
patch_lines = patch_str.splitlines()
|
||||||
extended_patch_lines = []
|
extended_patch_lines = []
|
||||||
|
|
||||||
is_valid_hunk = True
|
|
||||||
start1, size1, start2, size2 = -1, -1, -1, -1
|
start1, size1, start2, size2 = -1, -1, -1, -1
|
||||||
RE_HUNK_HEADER = re.compile(
|
RE_HUNK_HEADER = re.compile(
|
||||||
r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@[ ]?(.*)")
|
r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@[ ]?(.*)")
|
||||||
try:
|
try:
|
||||||
for i,line in enumerate(patch_lines):
|
for line in patch_lines:
|
||||||
if line.startswith('@@'):
|
if line.startswith('@@'):
|
||||||
match = RE_HUNK_HEADER.match(line)
|
match = RE_HUNK_HEADER.match(line)
|
||||||
# identify hunk header
|
# identify hunk header
|
||||||
if match:
|
if match:
|
||||||
# finish processing previous hunk
|
# finish processing previous hunk
|
||||||
if is_valid_hunk and (start1 != -1 and patch_extra_lines_after > 0):
|
if start1 != -1 and patch_extra_lines_after > 0:
|
||||||
delta_lines = [f' {line}' for line in original_lines[start1 + size1 - 1:start1 + size1 - 1 + patch_extra_lines_after]]
|
delta_lines = [f' {line}' for line in original_lines[start1 + size1 - 1:start1 + size1 - 1 + patch_extra_lines_after]]
|
||||||
extended_patch_lines.extend(delta_lines)
|
extended_patch_lines.extend(delta_lines)
|
||||||
|
|
||||||
section_header, size1, size2, start1, start2 = extract_hunk_headers(match)
|
section_header, size1, size2, start1, start2 = extract_hunk_headers(match)
|
||||||
|
|
||||||
is_valid_hunk = check_if_hunk_lines_matches_to_file(i, original_lines, patch_lines, start1)
|
if patch_extra_lines_before > 0 or patch_extra_lines_after > 0:
|
||||||
|
|
||||||
if is_valid_hunk and (patch_extra_lines_before > 0 or patch_extra_lines_after > 0):
|
|
||||||
def _calc_context_limits(patch_lines_before):
|
def _calc_context_limits(patch_lines_before):
|
||||||
extended_start1 = max(1, start1 - patch_lines_before)
|
extended_start1 = max(1, start1 - patch_lines_before)
|
||||||
extended_size1 = size1 + (start1 - extended_start1) + patch_extra_lines_after
|
extended_size1 = size1 + (start1 - extended_start1) + patch_extra_lines_after
|
||||||
@ -141,7 +138,7 @@ def process_patch_lines(patch_str, original_file_str, patch_extra_lines_before,
|
|||||||
return patch_str
|
return patch_str
|
||||||
|
|
||||||
# finish processing last hunk
|
# finish processing last hunk
|
||||||
if start1 != -1 and patch_extra_lines_after > 0 and is_valid_hunk:
|
if start1 != -1 and patch_extra_lines_after > 0:
|
||||||
delta_lines = original_lines[start1 + size1 - 1:start1 + size1 - 1 + patch_extra_lines_after]
|
delta_lines = original_lines[start1 + size1 - 1:start1 + size1 - 1 + patch_extra_lines_after]
|
||||||
# add space at the beginning of each extra line
|
# add space at the beginning of each extra line
|
||||||
delta_lines = [f' {line}' for line in delta_lines]
|
delta_lines = [f' {line}' for line in delta_lines]
|
||||||
@ -151,23 +148,6 @@ def process_patch_lines(patch_str, original_file_str, patch_extra_lines_before,
|
|||||||
return extended_patch_str
|
return extended_patch_str
|
||||||
|
|
||||||
|
|
||||||
def check_if_hunk_lines_matches_to_file(i, original_lines, patch_lines, start1):
|
|
||||||
"""
|
|
||||||
Check if the hunk lines match the original file content. We saw cases where the hunk header line doesn't match the original file content, and then
|
|
||||||
extending the hunk with extra lines before the hunk header can cause the hunk to be invalid.
|
|
||||||
"""
|
|
||||||
is_valid_hunk = True
|
|
||||||
try:
|
|
||||||
if i + 1 < len(patch_lines) and patch_lines[i + 1][0] == ' ': # an existing line in the file
|
|
||||||
if patch_lines[i + 1].strip() != original_lines[start1 - 1].strip():
|
|
||||||
is_valid_hunk = False
|
|
||||||
get_logger().error(
|
|
||||||
f"Invalid hunk in PR, line {start1} in hunk header doesn't match the original file content")
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
return is_valid_hunk
|
|
||||||
|
|
||||||
|
|
||||||
def extract_hunk_headers(match):
|
def extract_hunk_headers(match):
|
||||||
res = list(match.groups())
|
res = list(match.groups())
|
||||||
for i in range(len(res)):
|
for i in range(len(res)):
|
||||||
@ -301,7 +281,7 @@ __old hunk__
|
|||||||
prev_header_line = []
|
prev_header_line = []
|
||||||
header_line = []
|
header_line = []
|
||||||
for line_i, line in enumerate(patch_lines):
|
for line_i, line in enumerate(patch_lines):
|
||||||
if 'no newline at end of file' in line.lower():
|
if 'no newline at end of file' in line.lower().strip().strip('//'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if line.startswith('@@'):
|
if line.startswith('@@'):
|
||||||
@ -310,15 +290,14 @@ __old hunk__
|
|||||||
if match and (new_content_lines or old_content_lines): # found a new hunk, split the previous lines
|
if match and (new_content_lines or old_content_lines): # found a new hunk, split the previous lines
|
||||||
if prev_header_line:
|
if prev_header_line:
|
||||||
patch_with_lines_str += f'\n{prev_header_line}\n'
|
patch_with_lines_str += f'\n{prev_header_line}\n'
|
||||||
is_plus_lines = is_minus_lines = False
|
|
||||||
if new_content_lines:
|
if new_content_lines:
|
||||||
is_plus_lines = any([line.startswith('+') for line in new_content_lines])
|
is_plus_lines = any([line.startswith('+') for line in new_content_lines])
|
||||||
if old_content_lines:
|
if is_plus_lines:
|
||||||
is_minus_lines = any([line.startswith('-') for line in old_content_lines])
|
|
||||||
if is_plus_lines or is_minus_lines: # notice 'True' here - we always present __new hunk__ for section, otherwise LLM gets confused
|
|
||||||
patch_with_lines_str = patch_with_lines_str.rstrip() + '\n__new hunk__\n'
|
patch_with_lines_str = patch_with_lines_str.rstrip() + '\n__new hunk__\n'
|
||||||
for i, line_new in enumerate(new_content_lines):
|
for i, line_new in enumerate(new_content_lines):
|
||||||
patch_with_lines_str += f"{start2 + i} {line_new}\n"
|
patch_with_lines_str += f"{start2 + i} {line_new}\n"
|
||||||
|
if old_content_lines:
|
||||||
|
is_minus_lines = any([line.startswith('-') for line in old_content_lines])
|
||||||
if is_minus_lines:
|
if is_minus_lines:
|
||||||
patch_with_lines_str = patch_with_lines_str.rstrip() + '\n__old hunk__\n'
|
patch_with_lines_str = patch_with_lines_str.rstrip() + '\n__old hunk__\n'
|
||||||
for line_old in old_content_lines:
|
for line_old in old_content_lines:
|
||||||
@ -346,15 +325,14 @@ __old hunk__
|
|||||||
# finishing last hunk
|
# finishing last hunk
|
||||||
if match and new_content_lines:
|
if match and new_content_lines:
|
||||||
patch_with_lines_str += f'\n{header_line}\n'
|
patch_with_lines_str += f'\n{header_line}\n'
|
||||||
is_plus_lines = is_minus_lines = False
|
|
||||||
if new_content_lines:
|
if new_content_lines:
|
||||||
is_plus_lines = any([line.startswith('+') for line in new_content_lines])
|
is_plus_lines = any([line.startswith('+') for line in new_content_lines])
|
||||||
if old_content_lines:
|
if is_plus_lines:
|
||||||
is_minus_lines = any([line.startswith('-') for line in old_content_lines])
|
|
||||||
if is_plus_lines or is_minus_lines: # notice 'True' here - we always present __new hunk__ for section, otherwise LLM gets confused
|
|
||||||
patch_with_lines_str = patch_with_lines_str.rstrip() + '\n__new hunk__\n'
|
patch_with_lines_str = patch_with_lines_str.rstrip() + '\n__new hunk__\n'
|
||||||
for i, line_new in enumerate(new_content_lines):
|
for i, line_new in enumerate(new_content_lines):
|
||||||
patch_with_lines_str += f"{start2 + i} {line_new}\n"
|
patch_with_lines_str += f"{start2 + i} {line_new}\n"
|
||||||
|
if old_content_lines:
|
||||||
|
is_minus_lines = any([line.startswith('-') for line in old_content_lines])
|
||||||
if is_minus_lines:
|
if is_minus_lines:
|
||||||
patch_with_lines_str = patch_with_lines_str.rstrip() + '\n__old hunk__\n'
|
patch_with_lines_str = patch_with_lines_str.rstrip() + '\n__old hunk__\n'
|
||||||
for line_old in old_content_lines:
|
for line_old in old_content_lines:
|
||||||
|
@ -4,6 +4,8 @@ from typing import Dict
|
|||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def filter_bad_extensions(files):
|
def filter_bad_extensions(files):
|
||||||
# Bad Extensions, source: https://github.com/EleutherAI/github-downloader/blob/345e7c4cbb9e0dc8a0615fd995a08bf9d73b3fe6/download_repo_text.py # noqa: E501
|
# Bad Extensions, source: https://github.com/EleutherAI/github-downloader/blob/345e7c4cbb9e0dc8a0615fd995a08bf9d73b3fe6/download_repo_text.py # noqa: E501
|
||||||
bad_extensions = get_settings().bad_extensions.default
|
bad_extensions = get_settings().bad_extensions.default
|
||||||
|
@ -5,15 +5,14 @@ from typing import Callable, List, Tuple
|
|||||||
|
|
||||||
from github import RateLimitExceededException
|
from github import RateLimitExceededException
|
||||||
|
|
||||||
from pr_agent.algo.file_filter import filter_ignored
|
from pr_agent.algo.git_patch_processing import convert_to_hunks_with_lines_numbers, extend_patch, handle_patch_deletions
|
||||||
from pr_agent.algo.git_patch_processing import (
|
|
||||||
convert_to_hunks_with_lines_numbers, extend_patch, handle_patch_deletions)
|
|
||||||
from pr_agent.algo.language_handler import sort_files_by_main_languages
|
from pr_agent.algo.language_handler import sort_files_by_main_languages
|
||||||
|
from pr_agent.algo.file_filter import filter_ignored
|
||||||
from pr_agent.algo.token_handler import TokenHandler
|
from pr_agent.algo.token_handler import TokenHandler
|
||||||
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
|
from pr_agent.algo.utils import get_max_tokens, clip_tokens, ModelType
|
||||||
from pr_agent.algo.utils import ModelType, clip_tokens, get_max_tokens
|
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
from pr_agent.git_providers.git_provider import GitProvider
|
from pr_agent.git_providers.git_provider import GitProvider
|
||||||
|
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
|
||||||
from pr_agent.log import get_logger
|
from pr_agent.log import get_logger
|
||||||
|
|
||||||
DELETED_FILES_ = "Deleted files:\n"
|
DELETED_FILES_ = "Deleted files:\n"
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
from threading import Lock
|
|
||||||
|
|
||||||
from jinja2 import Environment, StrictUndefined
|
from jinja2 import Environment, StrictUndefined
|
||||||
from tiktoken import encoding_for_model, get_encoding
|
from tiktoken import encoding_for_model, get_encoding
|
||||||
|
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
|
from threading import Lock
|
||||||
|
|
||||||
from pr_agent.log import get_logger
|
from pr_agent.log import get_logger
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,32 +1,28 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
import html2text
|
||||||
|
|
||||||
|
import html
|
||||||
import copy
|
import copy
|
||||||
import difflib
|
import difflib
|
||||||
import hashlib
|
|
||||||
import html
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import textwrap
|
import textwrap
|
||||||
import time
|
import time
|
||||||
import traceback
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, List, Tuple
|
from typing import Any, List, Tuple
|
||||||
|
|
||||||
import html2text
|
|
||||||
import requests
|
|
||||||
import yaml
|
import yaml
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from starlette_context import context
|
from starlette_context import context
|
||||||
|
|
||||||
from pr_agent.algo import MAX_TOKENS
|
from pr_agent.algo import MAX_TOKENS
|
||||||
from pr_agent.algo.token_handler import TokenEncoder
|
from pr_agent.algo.token_handler import TokenEncoder
|
||||||
from pr_agent.algo.types import FilePatchInfo
|
|
||||||
from pr_agent.config_loader import get_settings, global_settings
|
from pr_agent.config_loader import get_settings, global_settings
|
||||||
|
from pr_agent.algo.types import FilePatchInfo
|
||||||
from pr_agent.log import get_logger
|
from pr_agent.log import get_logger
|
||||||
|
|
||||||
|
|
||||||
class Range(BaseModel):
|
class Range(BaseModel):
|
||||||
line_start: int # should be 0-indexed
|
line_start: int # should be 0-indexed
|
||||||
line_end: int
|
line_end: int
|
||||||
@ -43,10 +39,6 @@ class PRReviewHeader(str, Enum):
|
|||||||
INCREMENTAL = "## Incremental PR Reviewer Guide"
|
INCREMENTAL = "## Incremental PR Reviewer Guide"
|
||||||
|
|
||||||
|
|
||||||
class PRDescriptionHeader(str, Enum):
|
|
||||||
CHANGES_WALKTHROUGH = "### **Changes walkthrough** 📝"
|
|
||||||
|
|
||||||
|
|
||||||
def get_setting(key: str) -> Any:
|
def get_setting(key: str) -> Any:
|
||||||
try:
|
try:
|
||||||
key = key.upper()
|
key = key.upper()
|
||||||
@ -118,7 +110,6 @@ def convert_to_markdown_v2(output_data: dict,
|
|||||||
"Insights from user's answers": "📝",
|
"Insights from user's answers": "📝",
|
||||||
"Code feedback": "🤖",
|
"Code feedback": "🤖",
|
||||||
"Estimated effort to review [1-5]": "⏱️",
|
"Estimated effort to review [1-5]": "⏱️",
|
||||||
"Ticket compliance check": "🎫",
|
|
||||||
}
|
}
|
||||||
markdown_text = ""
|
markdown_text = ""
|
||||||
if not incremental_review:
|
if not incremental_review:
|
||||||
@ -174,8 +165,6 @@ def convert_to_markdown_v2(output_data: dict,
|
|||||||
markdown_text += f'### {emoji} No relevant tests\n\n'
|
markdown_text += f'### {emoji} No relevant tests\n\n'
|
||||||
else:
|
else:
|
||||||
markdown_text += f"### PR contains tests\n\n"
|
markdown_text += f"### PR contains tests\n\n"
|
||||||
elif 'ticket compliance check' in key_nice.lower():
|
|
||||||
markdown_text = ticket_markdown_logic(emoji, markdown_text, value, gfm_supported)
|
|
||||||
elif 'security concerns' in key_nice.lower():
|
elif 'security concerns' in key_nice.lower():
|
||||||
if gfm_supported:
|
if gfm_supported:
|
||||||
markdown_text += f"<tr><td>"
|
markdown_text += f"<tr><td>"
|
||||||
@ -265,52 +254,6 @@ def convert_to_markdown_v2(output_data: dict,
|
|||||||
return markdown_text
|
return markdown_text
|
||||||
|
|
||||||
|
|
||||||
def ticket_markdown_logic(emoji, markdown_text, value, gfm_supported) -> str:
|
|
||||||
ticket_compliance_str = ""
|
|
||||||
final_compliance_level = -1
|
|
||||||
if isinstance(value, list):
|
|
||||||
for v in value:
|
|
||||||
ticket_url = v.get('ticket_url', '').strip()
|
|
||||||
compliance_level = v.get('overall_compliance_level', '').strip()
|
|
||||||
# add emojis, if 'Fully compliant' ✅, 'Partially compliant' 🔶, or 'Not compliant' ❌
|
|
||||||
if compliance_level.lower() == 'fully compliant':
|
|
||||||
# compliance_level = '✅ Fully compliant'
|
|
||||||
final_compliance_level = 2 if final_compliance_level == -1 else 1
|
|
||||||
elif compliance_level.lower() == 'partially compliant':
|
|
||||||
# compliance_level = '🔶 Partially compliant'
|
|
||||||
final_compliance_level = 1
|
|
||||||
elif compliance_level.lower() == 'not compliant':
|
|
||||||
# compliance_level = '❌ Not compliant'
|
|
||||||
final_compliance_level = 0 if final_compliance_level < 1 else 1
|
|
||||||
|
|
||||||
# explanation = v.get('compliance_analysis', '').strip()
|
|
||||||
explanation = ''
|
|
||||||
fully_compliant_str = v.get('fully_compliant_requirements', '').strip()
|
|
||||||
not_compliant_str = v.get('not_compliant_requirements', '').strip()
|
|
||||||
if fully_compliant_str:
|
|
||||||
explanation += f"Fully compliant requirements:\n{fully_compliant_str}\n\n"
|
|
||||||
if not_compliant_str:
|
|
||||||
explanation += f"Not compliant requirements:\n{not_compliant_str}\n\n"
|
|
||||||
|
|
||||||
ticket_compliance_str += f"\n\n**[{ticket_url.split('/')[-1]}]({ticket_url}) - {compliance_level}**\n\n{explanation}\n\n"
|
|
||||||
if final_compliance_level == 2:
|
|
||||||
compliance_level = '✅'
|
|
||||||
elif final_compliance_level == 1:
|
|
||||||
compliance_level = '🔶'
|
|
||||||
else:
|
|
||||||
compliance_level = '❌'
|
|
||||||
|
|
||||||
if gfm_supported:
|
|
||||||
markdown_text += f"<tr><td>\n\n"
|
|
||||||
markdown_text += f"**{emoji} Ticket compliance analysis {compliance_level}**\n\n"
|
|
||||||
markdown_text += ticket_compliance_str
|
|
||||||
markdown_text += f"</td></tr>\n"
|
|
||||||
else:
|
|
||||||
markdown_text += f"### {emoji} Ticket compliance analysis {compliance_level}\n\n"
|
|
||||||
markdown_text += ticket_compliance_str+"\n\n"
|
|
||||||
return markdown_text
|
|
||||||
|
|
||||||
|
|
||||||
def process_can_be_split(emoji, value):
|
def process_can_be_split(emoji, value):
|
||||||
try:
|
try:
|
||||||
# key_nice = "Can this PR be split?"
|
# key_nice = "Can this PR be split?"
|
||||||
@ -611,8 +554,7 @@ def load_yaml(response_text: str, keys_fix_yaml: List[str] = [], first_key="", l
|
|||||||
get_logger().warning(f"Initial failure to parse AI prediction: {e}")
|
get_logger().warning(f"Initial failure to parse AI prediction: {e}")
|
||||||
data = try_fix_yaml(response_text, keys_fix_yaml=keys_fix_yaml, first_key=first_key, last_key=last_key)
|
data = try_fix_yaml(response_text, keys_fix_yaml=keys_fix_yaml, first_key=first_key, last_key=last_key)
|
||||||
if not data:
|
if not data:
|
||||||
get_logger().error(f"Failed to parse AI prediction after fallbacks",
|
get_logger().error(f"Failed to parse AI prediction after fallbacks", artifact={'response_text': response_text})
|
||||||
artifact={'response_text': response_text})
|
|
||||||
else:
|
else:
|
||||||
get_logger().info(f"Successfully parsed AI prediction after fallbacks",
|
get_logger().info(f"Successfully parsed AI prediction after fallbacks",
|
||||||
artifact={'response_text': response_text})
|
artifact={'response_text': response_text})
|
||||||
@ -899,64 +841,56 @@ def find_line_number_of_relevant_line_in_file(diff_files: List[FilePatchInfo],
|
|||||||
break
|
break
|
||||||
return position, absolute_position
|
return position, absolute_position
|
||||||
|
|
||||||
def get_rate_limit_status(github_token) -> dict:
|
def validate_and_await_rate_limit(rate_limit_status=None, git_provider=None, get_rate_limit_status_func=None):
|
||||||
GITHUB_API_URL = get_settings(use_context=False).get("GITHUB.BASE_URL", "https://api.github.com").rstrip("/") # "https://api.github.com"
|
if git_provider and not rate_limit_status:
|
||||||
# GITHUB_API_URL = "https://api.github.com"
|
rate_limit_status = {'resources': git_provider.github_client.get_rate_limit().raw_data}
|
||||||
RATE_LIMIT_URL = f"{GITHUB_API_URL}/rate_limit"
|
|
||||||
HEADERS = {
|
|
||||||
"Accept": "application/vnd.github.v3+json",
|
|
||||||
"Authorization": f"token {github_token}"
|
|
||||||
}
|
|
||||||
|
|
||||||
response = requests.get(RATE_LIMIT_URL, headers=HEADERS)
|
if not rate_limit_status:
|
||||||
try:
|
rate_limit_status = get_rate_limit_status_func()
|
||||||
rate_limit_info = response.json()
|
|
||||||
if rate_limit_info.get('message') == 'Rate limiting is not enabled.': # for github enterprise
|
|
||||||
return {'resources': {}}
|
|
||||||
response.raise_for_status() # Check for HTTP errors
|
|
||||||
except: # retry
|
|
||||||
time.sleep(0.1)
|
|
||||||
response = requests.get(RATE_LIMIT_URL, headers=HEADERS)
|
|
||||||
return response.json()
|
|
||||||
return rate_limit_info
|
|
||||||
|
|
||||||
|
|
||||||
def validate_rate_limit_github(github_token, installation_id=None, threshold=0.1) -> bool:
|
|
||||||
try:
|
|
||||||
rate_limit_status = get_rate_limit_status(github_token)
|
|
||||||
if installation_id:
|
|
||||||
get_logger().debug(f"installation_id: {installation_id}, Rate limit status: {rate_limit_status['rate']}")
|
|
||||||
# validate that the rate limit is not exceeded
|
|
||||||
# validate that the rate limit is not exceeded
|
# validate that the rate limit is not exceeded
|
||||||
|
is_rate_limit = False
|
||||||
for key, value in rate_limit_status['resources'].items():
|
for key, value in rate_limit_status['resources'].items():
|
||||||
if value['remaining'] < value['limit'] * threshold:
|
if value['remaining'] == 0:
|
||||||
get_logger().error(f"key: {key}, value: {value}")
|
print(f"key: {key}, value: {value}")
|
||||||
return False
|
is_rate_limit = True
|
||||||
return True
|
|
||||||
except Exception as e:
|
|
||||||
get_logger().error(f"Error in rate limit {e}",
|
|
||||||
artifact={"traceback": traceback.format_exc()})
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def validate_and_await_rate_limit(github_token):
|
|
||||||
try:
|
|
||||||
rate_limit_status = get_rate_limit_status(github_token)
|
|
||||||
# validate that the rate limit is not exceeded
|
|
||||||
for key, value in rate_limit_status['resources'].items():
|
|
||||||
if value['remaining'] < value['limit'] // 80:
|
|
||||||
get_logger().error(f"key: {key}, value: {value}")
|
|
||||||
sleep_time_sec = value['reset'] - datetime.now().timestamp()
|
sleep_time_sec = value['reset'] - datetime.now().timestamp()
|
||||||
sleep_time_hour = sleep_time_sec / 3600.0
|
sleep_time_hour = sleep_time_sec / 3600.0
|
||||||
get_logger().error(f"Rate limit exceeded. Sleeping for {sleep_time_hour} hours")
|
print(f"Rate limit exceeded. Sleeping for {sleep_time_hour} hours")
|
||||||
if sleep_time_sec > 0:
|
if sleep_time_sec > 0:
|
||||||
time.sleep(sleep_time_sec+1)
|
time.sleep(sleep_time_sec+1)
|
||||||
rate_limit_status = get_rate_limit_status(github_token)
|
|
||||||
return rate_limit_status
|
|
||||||
except:
|
|
||||||
get_logger().error("Error in rate limit")
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
if git_provider:
|
||||||
|
rate_limit_status = {'resources': git_provider.github_client.get_rate_limit().raw_data}
|
||||||
|
else:
|
||||||
|
rate_limit_status = get_rate_limit_status_func()
|
||||||
|
|
||||||
|
return is_rate_limit
|
||||||
|
|
||||||
|
|
||||||
|
def get_largest_component(pr_url):
|
||||||
|
from pr_agent.tools.pr_analyzer import PRAnalyzer
|
||||||
|
publish_output = get_settings().config.publish_output
|
||||||
|
get_settings().config.publish_output = False # disable publish output
|
||||||
|
analyzer = PRAnalyzer(pr_url)
|
||||||
|
methods_dict_files = analyzer.run_sync()
|
||||||
|
get_settings().config.publish_output = publish_output
|
||||||
|
max_lines_changed = 0
|
||||||
|
file_b = ""
|
||||||
|
component_name_b = ""
|
||||||
|
for file in methods_dict_files:
|
||||||
|
for method in methods_dict_files[file]:
|
||||||
|
try:
|
||||||
|
if methods_dict_files[file][method]['num_plus_lines'] > max_lines_changed:
|
||||||
|
max_lines_changed = methods_dict_files[file][method]['num_plus_lines']
|
||||||
|
file_b = file
|
||||||
|
component_name_b = method
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
if component_name_b:
|
||||||
|
get_logger().info(f"Using the largest changed component: '{component_name_b}'")
|
||||||
|
return component_name_b, file_b
|
||||||
|
else:
|
||||||
|
return None, None
|
||||||
|
|
||||||
def github_action_output(output_data: dict, key_name: str):
|
def github_action_output(output_data: dict, key_name: str):
|
||||||
try:
|
try:
|
||||||
@ -972,7 +906,7 @@ def github_action_output(output_data: dict, key_name: str):
|
|||||||
|
|
||||||
|
|
||||||
def show_relevant_configurations(relevant_section: str) -> str:
|
def show_relevant_configurations(relevant_section: str) -> str:
|
||||||
skip_keys = ['ai_disclaimer', 'ai_disclaimer_title', 'ANALYTICS_FOLDER', 'secret_provider', "skip_keys", "app_id", "redirect",
|
skip_keys = ['ai_disclaimer', 'ai_disclaimer_title', 'ANALYTICS_FOLDER', 'secret_provider', "skip_keys",
|
||||||
'trial_prefix_message', 'no_eligible_message', 'identity_provider', 'ALLOWED_REPOS','APP_NAME']
|
'trial_prefix_message', 'no_eligible_message', 'identity_provider', 'ALLOWED_REPOS','APP_NAME']
|
||||||
extra_skip_keys = get_settings().config.get('config.skip_keys', [])
|
extra_skip_keys = get_settings().config.get('config.skip_keys', [])
|
||||||
if extra_skip_keys:
|
if extra_skip_keys:
|
||||||
@ -1005,30 +939,12 @@ def is_value_no(value):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def set_pr_string(repo_name, pr_number):
|
|
||||||
return f"{repo_name}#{pr_number}"
|
|
||||||
|
|
||||||
|
|
||||||
def string_to_uniform_number(s: str) -> float:
|
|
||||||
"""
|
|
||||||
Convert a string to a uniform number in the range [0, 1].
|
|
||||||
The uniform distribution is achieved by the nature of the SHA-256 hash function, which produces a uniformly distributed hash value over its output space.
|
|
||||||
"""
|
|
||||||
# Generate a hash of the string
|
|
||||||
hash_object = hashlib.sha256(s.encode())
|
|
||||||
# Convert the hash to an integer
|
|
||||||
hash_int = int(hash_object.hexdigest(), 16)
|
|
||||||
# Normalize the integer to the range [0, 1]
|
|
||||||
max_hash_int = 2 ** 256 - 1
|
|
||||||
uniform_number = float(hash_int) / max_hash_int
|
|
||||||
return uniform_number
|
|
||||||
|
|
||||||
|
|
||||||
def process_description(description_full: str) -> Tuple[str, List]:
|
def process_description(description_full: str) -> Tuple[str, List]:
|
||||||
if not description_full:
|
if not description_full:
|
||||||
return "", []
|
return "", []
|
||||||
|
|
||||||
description_split = description_full.split(PRDescriptionHeader.CHANGES_WALKTHROUGH.value)
|
split_str = "### **Changes walkthrough** 📝"
|
||||||
|
description_split = description_full.split(split_str)
|
||||||
base_description_str = description_split[0]
|
base_description_str = description_split[0]
|
||||||
changes_walkthrough_str = ""
|
changes_walkthrough_str = ""
|
||||||
files = []
|
files = []
|
||||||
@ -1063,9 +979,6 @@ def process_description(description_full: str) -> Tuple[str, List]:
|
|||||||
if not res or res.lastindex != 4:
|
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>'
|
pattern_back = r'<details>\s*<summary><strong>(.*?)</strong><dd><code>(.*?)</code>.*?</summary>\s*<hr>\s*(.*?)\n\n\s*(.*?)</details>'
|
||||||
res = re.search(pattern_back, file_data, re.DOTALL)
|
res = re.search(pattern_back, file_data, re.DOTALL)
|
||||||
if not res or res.lastindex != 4:
|
|
||||||
pattern_back = r'<details>\s*<summary><strong>(.*?)</strong>\s*<dd><code>(.*?)</code>.*?</summary>\s*<hr>\s*(.*?)\s*-\s*(.*?)\s*</details>' # looking for hypen ('- ')
|
|
||||||
res = re.search(pattern_back, file_data, re.DOTALL)
|
|
||||||
if res and res.lastindex == 4:
|
if res and res.lastindex == 4:
|
||||||
short_filename = res.group(1).strip()
|
short_filename = res.group(1).strip()
|
||||||
short_summary = res.group(2).strip()
|
short_summary = res.group(2).strip()
|
||||||
@ -1084,9 +997,6 @@ def process_description(description_full: str) -> Tuple[str, List]:
|
|||||||
'short_summary': short_summary,
|
'short_summary': short_summary,
|
||||||
'long_summary': long_summary
|
'long_summary': long_summary
|
||||||
})
|
})
|
||||||
else:
|
|
||||||
if '<code>...</code>' in file_data:
|
|
||||||
pass # PR with many files. some did not get analyzed
|
|
||||||
else:
|
else:
|
||||||
get_logger().error(f"Failed to parse description", artifact={'description': file_data})
|
get_logger().error(f"Failed to parse description", artifact={'description': file_data})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -4,7 +4,7 @@ import os
|
|||||||
|
|
||||||
from pr_agent.agent.pr_agent import PRAgent, commands
|
from pr_agent.agent.pr_agent import PRAgent, commands
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
from pr_agent.log import get_logger, setup_logger
|
from pr_agent.log import setup_logger, get_logger
|
||||||
|
|
||||||
log_level = os.environ.get("LOG_LEVEL", "INFO")
|
log_level = os.environ.get("LOG_LEVEL", "INFO")
|
||||||
setup_logger(log_level)
|
setup_logger(log_level)
|
||||||
@ -92,4 +92,3 @@ def run(inargs=None, args=None):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
run()
|
run()
|
||||||
aa = "1"
|
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
from starlette_context import context
|
|
||||||
|
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
from pr_agent.git_providers.azuredevops_provider import AzureDevopsProvider
|
|
||||||
from pr_agent.git_providers.bitbucket_provider import BitbucketProvider
|
from pr_agent.git_providers.bitbucket_provider import BitbucketProvider
|
||||||
from pr_agent.git_providers.bitbucket_server_provider import \
|
from pr_agent.git_providers.bitbucket_server_provider import BitbucketServerProvider
|
||||||
BitbucketServerProvider
|
|
||||||
from pr_agent.git_providers.codecommit_provider import CodeCommitProvider
|
from pr_agent.git_providers.codecommit_provider import CodeCommitProvider
|
||||||
from pr_agent.git_providers.gerrit_provider import GerritProvider
|
|
||||||
from pr_agent.git_providers.git_provider import GitProvider
|
from pr_agent.git_providers.git_provider import GitProvider
|
||||||
from pr_agent.git_providers.github_provider import GithubProvider
|
from pr_agent.git_providers.github_provider import GithubProvider
|
||||||
from pr_agent.git_providers.gitlab_provider import GitLabProvider
|
from pr_agent.git_providers.gitlab_provider import GitLabProvider
|
||||||
from pr_agent.git_providers.local_git_provider import LocalGitProvider
|
from pr_agent.git_providers.local_git_provider import LocalGitProvider
|
||||||
|
from pr_agent.git_providers.azuredevops_provider import AzureDevopsProvider
|
||||||
|
from pr_agent.git_providers.gerrit_provider import GerritProvider
|
||||||
|
from starlette_context import context
|
||||||
|
|
||||||
_GIT_PROVIDERS = {
|
_GIT_PROVIDERS = {
|
||||||
'github': GithubProvider,
|
'github': GithubProvider,
|
||||||
|
@ -2,16 +2,13 @@ import os
|
|||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
|
|
||||||
|
|
||||||
from ..algo.file_filter import filter_ignored
|
from ..algo.file_filter import filter_ignored
|
||||||
from ..algo.language_handler import is_valid_file
|
|
||||||
from ..algo.utils import (PRDescriptionHeader, clip_tokens,
|
|
||||||
find_line_number_of_relevant_line_in_file,
|
|
||||||
load_large_diff)
|
|
||||||
from ..config_loader import get_settings
|
|
||||||
from ..log import get_logger
|
from ..log import get_logger
|
||||||
|
from ..algo.language_handler import is_valid_file
|
||||||
|
from ..algo.utils import clip_tokens, find_line_number_of_relevant_line_in_file, load_large_diff
|
||||||
|
from ..config_loader import get_settings
|
||||||
from .git_provider import GitProvider
|
from .git_provider import GitProvider
|
||||||
|
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
|
||||||
|
|
||||||
AZURE_DEVOPS_AVAILABLE = True
|
AZURE_DEVOPS_AVAILABLE = True
|
||||||
ADO_APP_CLIENT_DEFAULT_ID = "499b84ac-1321-427f-aa17-267ca6975798/.default"
|
ADO_APP_CLIENT_DEFAULT_ID = "499b84ac-1321-427f-aa17-267ca6975798/.default"
|
||||||
@ -19,16 +16,19 @@ MAX_PR_DESCRIPTION_AZURE_LENGTH = 4000-1
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# noinspection PyUnresolvedReferences
|
# noinspection PyUnresolvedReferences
|
||||||
|
from msrest.authentication import BasicAuthentication
|
||||||
# noinspection PyUnresolvedReferences
|
# noinspection PyUnresolvedReferences
|
||||||
from azure.devops.connection import Connection
|
from azure.devops.connection import Connection
|
||||||
# noinspection PyUnresolvedReferences
|
# noinspection PyUnresolvedReferences
|
||||||
from azure.devops.v7_1.git.models import (Comment, CommentThread,
|
from azure.identity import DefaultAzureCredential
|
||||||
|
# noinspection PyUnresolvedReferences
|
||||||
|
from azure.devops.v7_1.git.models import (
|
||||||
|
Comment,
|
||||||
|
CommentThread,
|
||||||
|
GitVersionDescriptor,
|
||||||
GitPullRequest,
|
GitPullRequest,
|
||||||
GitPullRequestIterationChanges,
|
GitPullRequestIterationChanges,
|
||||||
GitVersionDescriptor)
|
)
|
||||||
# noinspection PyUnresolvedReferences
|
|
||||||
from azure.identity import DefaultAzureCredential
|
|
||||||
from msrest.authentication import BasicAuthentication
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
AZURE_DEVOPS_AVAILABLE = False
|
AZURE_DEVOPS_AVAILABLE = False
|
||||||
|
|
||||||
@ -336,9 +336,6 @@ class AzureDevopsProvider(GitProvider):
|
|||||||
version = GitVersionDescriptor(
|
version = GitVersionDescriptor(
|
||||||
version=base_sha.commit_id, version_type="commit"
|
version=base_sha.commit_id, version_type="commit"
|
||||||
)
|
)
|
||||||
if edit_type == EDIT_TYPE.ADDED:
|
|
||||||
original_file_content_str = ""
|
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
original_file_content_str = self.azure_devops_client.get_item(
|
original_file_content_str = self.azure_devops_client.get_item(
|
||||||
repository_id=self.repo_slug,
|
repository_id=self.repo_slug,
|
||||||
@ -404,7 +401,7 @@ class AzureDevopsProvider(GitProvider):
|
|||||||
pr_body = pr_body[:ind]
|
pr_body = pr_body[:ind]
|
||||||
|
|
||||||
if len(pr_body) > MAX_PR_DESCRIPTION_AZURE_LENGTH:
|
if len(pr_body) > MAX_PR_DESCRIPTION_AZURE_LENGTH:
|
||||||
changes_walkthrough_text = PRDescriptionHeader.CHANGES_WALKTHROUGH.value
|
changes_walkthrough_text = '## **Changes walkthrough**'
|
||||||
ind = pr_body.find(changes_walkthrough_text)
|
ind = pr_body.find(changes_walkthrough_text)
|
||||||
if ind != -1:
|
if ind != -1:
|
||||||
pr_body = pr_body[:ind]
|
pr_body = pr_body[:ind]
|
||||||
@ -620,3 +617,4 @@ class AzureDevopsProvider(GitProvider):
|
|||||||
|
|
||||||
def publish_file_comments(self, file_comments: list) -> bool:
|
def publish_file_comments(self, file_comments: list) -> bool:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -6,14 +6,13 @@ import requests
|
|||||||
from atlassian.bitbucket import Cloud
|
from atlassian.bitbucket import Cloud
|
||||||
from starlette_context import context
|
from starlette_context import context
|
||||||
|
|
||||||
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
|
from pr_agent.algo.types import FilePatchInfo, EDIT_TYPE
|
||||||
|
|
||||||
from ..algo.file_filter import filter_ignored
|
from ..algo.file_filter import filter_ignored
|
||||||
from ..algo.language_handler import is_valid_file
|
from ..algo.language_handler import is_valid_file
|
||||||
from ..algo.utils import find_line_number_of_relevant_line_in_file
|
from ..algo.utils import find_line_number_of_relevant_line_in_file
|
||||||
from ..config_loader import get_settings
|
from ..config_loader import get_settings
|
||||||
from ..log import get_logger
|
from ..log import get_logger
|
||||||
from .git_provider import MAX_FILES_ALLOWED_FULL, GitProvider
|
from .git_provider import GitProvider, MAX_FILES_ALLOWED_FULL
|
||||||
|
|
||||||
|
|
||||||
def _gef_filename(diff):
|
def _gef_filename(diff):
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
from distutils.version import LooseVersion
|
from distutils.version import LooseVersion
|
||||||
|
from requests.exceptions import HTTPError
|
||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
from urllib.parse import quote_plus, urlparse
|
from urllib.parse import quote_plus, urlparse
|
||||||
|
|
||||||
from atlassian.bitbucket import Bitbucket
|
from atlassian.bitbucket import Bitbucket
|
||||||
from requests.exceptions import HTTPError
|
|
||||||
|
|
||||||
from ..algo.language_handler import is_valid_file
|
from .git_provider import GitProvider
|
||||||
from ..algo.types import EDIT_TYPE, FilePatchInfo
|
from ..algo.types import EDIT_TYPE, FilePatchInfo
|
||||||
from ..algo.utils import (find_line_number_of_relevant_line_in_file,
|
from ..algo.language_handler import is_valid_file
|
||||||
load_large_diff)
|
from ..algo.utils import load_large_diff, find_line_number_of_relevant_line_in_file
|
||||||
from ..config_loader import get_settings
|
from ..config_loader import get_settings
|
||||||
from ..log import get_logger
|
from ..log import get_logger
|
||||||
from .git_provider import GitProvider
|
|
||||||
|
|
||||||
|
|
||||||
class BitbucketServerProvider(GitProvider):
|
class BitbucketServerProvider(GitProvider):
|
||||||
|
@ -4,15 +4,13 @@ from collections import Counter
|
|||||||
from typing import List, Optional, Tuple
|
from typing import List, Optional, Tuple
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from pr_agent.algo.language_handler import is_valid_file
|
|
||||||
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
|
|
||||||
from pr_agent.git_providers.codecommit_client import CodeCommitClient
|
from pr_agent.git_providers.codecommit_client import CodeCommitClient
|
||||||
|
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
|
||||||
from ..algo.utils import load_large_diff
|
from ..algo.utils import load_large_diff
|
||||||
|
from .git_provider import GitProvider
|
||||||
from ..config_loader import get_settings
|
from ..config_loader import get_settings
|
||||||
from ..log import get_logger
|
from ..log import get_logger
|
||||||
from .git_provider import GitProvider
|
from pr_agent.algo.language_handler import is_valid_file
|
||||||
|
|
||||||
|
|
||||||
class PullRequestCCMimic:
|
class PullRequestCCMimic:
|
||||||
"""
|
"""
|
||||||
|
@ -12,9 +12,9 @@ import requests
|
|||||||
import urllib3.util
|
import urllib3.util
|
||||||
from git import Repo
|
from git import Repo
|
||||||
|
|
||||||
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
|
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
from pr_agent.git_providers.git_provider import GitProvider
|
from pr_agent.git_providers.git_provider import GitProvider
|
||||||
|
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
|
||||||
from pr_agent.git_providers.local_git_provider import PullRequestMimic
|
from pr_agent.git_providers.local_git_provider import PullRequestMimic
|
||||||
from pr_agent.log import get_logger
|
from pr_agent.log import get_logger
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
# enum EDIT_TYPE (ADDED, DELETED, MODIFIED, RENAMED)
|
# enum EDIT_TYPE (ADDED, DELETED, MODIFIED, RENAMED)
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from pr_agent.algo.types import FilePatchInfo
|
|
||||||
from pr_agent.algo.utils import Range, process_description
|
from pr_agent.algo.utils import Range, process_description
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
|
from pr_agent.algo.types import FilePatchInfo
|
||||||
from pr_agent.log import get_logger
|
from pr_agent.log import get_logger
|
||||||
|
|
||||||
MAX_FILES_ALLOWED_FULL = 50
|
MAX_FILES_ALLOWED_FULL = 50
|
||||||
|
|
||||||
class GitProvider(ABC):
|
class GitProvider(ABC):
|
||||||
@ -62,8 +62,8 @@ class GitProvider(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def get_pr_description(self, full: bool = True, split_changes_walkthrough=False) -> str or tuple:
|
def get_pr_description(self, full: bool = True, split_changes_walkthrough=False) -> str or tuple:
|
||||||
from pr_agent.algo.utils import clip_tokens
|
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
|
from pr_agent.algo.utils import clip_tokens
|
||||||
max_tokens_description = get_settings().get("CONFIG.MAX_DESCRIPTION_TOKENS", None)
|
max_tokens_description = get_settings().get("CONFIG.MAX_DESCRIPTION_TOKENS", None)
|
||||||
description = self.get_pr_description_full() if full else self.get_user_description()
|
description = self.get_pr_description_full() if full else self.get_user_description()
|
||||||
if split_changes_walkthrough:
|
if split_changes_walkthrough:
|
||||||
|
@ -1,26 +1,22 @@
|
|||||||
import hashlib
|
|
||||||
import itertools
|
import itertools
|
||||||
import time
|
import time
|
||||||
import traceback
|
import hashlib
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from github import AppAuthentication, Auth, Github
|
from github import AppAuthentication, Auth, Github, GithubException
|
||||||
from retry import retry
|
from retry import retry
|
||||||
from starlette_context import context
|
from starlette_context import context
|
||||||
|
|
||||||
from ..algo.file_filter import filter_ignored
|
from ..algo.file_filter import filter_ignored
|
||||||
from ..algo.language_handler import is_valid_file
|
from ..algo.language_handler import is_valid_file
|
||||||
from ..algo.types import EDIT_TYPE
|
from ..algo.utils import PRReviewHeader, load_large_diff, clip_tokens, find_line_number_of_relevant_line_in_file, Range
|
||||||
from ..algo.utils import (PRReviewHeader, Range, clip_tokens,
|
|
||||||
find_line_number_of_relevant_line_in_file,
|
|
||||||
load_large_diff)
|
|
||||||
from ..config_loader import get_settings
|
from ..config_loader import get_settings
|
||||||
from ..log import get_logger
|
from ..log import get_logger
|
||||||
from ..servers.utils import RateLimitExceeded
|
from ..servers.utils import RateLimitExceeded
|
||||||
from .git_provider import (MAX_FILES_ALLOWED_FULL, FilePatchInfo, GitProvider,
|
from .git_provider import GitProvider, IncrementalPR, MAX_FILES_ALLOWED_FULL
|
||||||
IncrementalPR)
|
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
|
||||||
|
|
||||||
|
|
||||||
class GithubProvider(GitProvider):
|
class GithubProvider(GitProvider):
|
||||||
@ -31,8 +27,10 @@ class GithubProvider(GitProvider):
|
|||||||
except Exception:
|
except Exception:
|
||||||
self.installation_id = None
|
self.installation_id = None
|
||||||
self.max_comment_chars = 65000
|
self.max_comment_chars = 65000
|
||||||
self.base_url = get_settings().get("GITHUB.BASE_URL", "https://api.github.com").rstrip("/") # "https://api.github.com"
|
self.base_url = get_settings().get("GITHUB.BASE_URL", "https://api.github.com").rstrip("/")
|
||||||
self.base_url_html = self.base_url.split("api/")[0].rstrip("/") if "api/" in self.base_url else "https://github.com"
|
self.base_url_html = self.base_url.split("api/")[0].rstrip("/") if "api/" in self.base_url else "https://github.com"
|
||||||
|
self.base_domain = self.base_url.replace("https://", "").replace("http://", "")
|
||||||
|
self.base_domain_html = self.base_url_html.replace("https://", "").replace("http://", "")
|
||||||
self.github_client = self._get_github_client()
|
self.github_client = self._get_github_client()
|
||||||
self.repo = None
|
self.repo = None
|
||||||
self.pr_num = None
|
self.pr_num = None
|
||||||
@ -199,24 +197,7 @@ class GithubProvider(GitProvider):
|
|||||||
if avoid_load:
|
if avoid_load:
|
||||||
original_file_content_str = ""
|
original_file_content_str = ""
|
||||||
else:
|
else:
|
||||||
# The base.sha will point to the current state of the base branch (including parallel merges), not the original base commit when the PR was created
|
original_file_content_str = self._get_pr_file_content(file, self.pr.base.sha)
|
||||||
# We can fix this by finding the merge base commit between the PR head and base branches
|
|
||||||
# Note that The pr.head.sha is actually correct as is - it points to the latest commit in your PR branch.
|
|
||||||
# This SHA isn't affected by parallel merges to the base branch since it's specific to your PR's branch.
|
|
||||||
repo = self.repo_obj
|
|
||||||
pr = self.pr
|
|
||||||
try:
|
|
||||||
compare = repo.compare(pr.base.sha, pr.head.sha)
|
|
||||||
merge_base_commit = compare.merge_base_commit
|
|
||||||
except Exception as e:
|
|
||||||
get_logger().error(f"Failed to get merge base commit: {e}")
|
|
||||||
merge_base_commit = pr.base
|
|
||||||
if merge_base_commit.sha != pr.base.sha:
|
|
||||||
get_logger().info(
|
|
||||||
f"Using merge base commit {merge_base_commit.sha} instead of base commit "
|
|
||||||
f"{pr.base.sha} for {file.filename}")
|
|
||||||
original_file_content_str = self._get_pr_file_content(file, merge_base_commit.sha)
|
|
||||||
|
|
||||||
if not patch:
|
if not patch:
|
||||||
patch = load_large_diff(file.filename, new_file_content_str, original_file_content_str)
|
patch = load_large_diff(file.filename, new_file_content_str, original_file_content_str)
|
||||||
|
|
||||||
@ -252,9 +233,8 @@ class GithubProvider(GitProvider):
|
|||||||
|
|
||||||
return diff_files
|
return diff_files
|
||||||
|
|
||||||
except Exception as e:
|
except GithubException.RateLimitExceededException as e:
|
||||||
get_logger().error(f"Failing to get diff files: {e}",
|
get_logger().error(f"Rate limit exceeded for GitHub API. Original message: {e}")
|
||||||
artifact={"traceback": traceback.format_exc()})
|
|
||||||
raise RateLimitExceeded("Rate limit exceeded for GitHub API.") from e
|
raise RateLimitExceeded("Rate limit exceeded for GitHub API.") from e
|
||||||
|
|
||||||
def publish_description(self, pr_title: str, pr_body: str):
|
def publish_description(self, pr_title: str, pr_body: str):
|
||||||
@ -276,7 +256,7 @@ class GithubProvider(GitProvider):
|
|||||||
def publish_comment(self, pr_comment: str, is_temporary: bool = False):
|
def publish_comment(self, pr_comment: str, is_temporary: bool = False):
|
||||||
if is_temporary and not get_settings().config.publish_output_progress:
|
if is_temporary and not get_settings().config.publish_output_progress:
|
||||||
get_logger().debug(f"Skipping publish_comment for temporary comment: {pr_comment}")
|
get_logger().debug(f"Skipping publish_comment for temporary comment: {pr_comment}")
|
||||||
return None
|
return
|
||||||
pr_comment = self.limit_output_characters(pr_comment, self.max_comment_chars)
|
pr_comment = self.limit_output_characters(pr_comment, self.max_comment_chars)
|
||||||
response = self.pr.create_issue_comment(pr_comment)
|
response = self.pr.create_issue_comment(pr_comment)
|
||||||
if hasattr(response, "user") and hasattr(response.user, "login"):
|
if hasattr(response, "user") and hasattr(response.user, "login"):
|
||||||
@ -300,6 +280,7 @@ class GithubProvider(GitProvider):
|
|||||||
relevant_line_in_file,
|
relevant_line_in_file,
|
||||||
absolute_position)
|
absolute_position)
|
||||||
if position == -1:
|
if position == -1:
|
||||||
|
if get_settings().config.verbosity_level >= 2:
|
||||||
get_logger().info(f"Could not find position for {relevant_file} {relevant_line_in_file}")
|
get_logger().info(f"Could not find position for {relevant_file} {relevant_line_in_file}")
|
||||||
subject_type = "FILE"
|
subject_type = "FILE"
|
||||||
else:
|
else:
|
||||||
@ -312,9 +293,11 @@ class GithubProvider(GitProvider):
|
|||||||
# publish all comments in a single message
|
# publish all comments in a single message
|
||||||
self.pr.create_review(commit=self.last_commit_id, comments=comments)
|
self.pr.create_review(commit=self.last_commit_id, comments=comments)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().info(f"Initially failed to publish inline comments as committable")
|
if get_settings().config.verbosity_level >= 2:
|
||||||
|
get_logger().error(f"Failed to publish inline comments")
|
||||||
|
|
||||||
if (getattr(e, "status", None) == 422 and not disable_fallback):
|
if (getattr(e, "status", None) == 422
|
||||||
|
and get_settings().github.publish_inline_comments_fallback_with_verification and not disable_fallback):
|
||||||
pass # continue to try _publish_inline_comments_fallback_with_verification
|
pass # continue to try _publish_inline_comments_fallback_with_verification
|
||||||
else:
|
else:
|
||||||
raise e # will end up with publishing the comments one by one
|
raise e # will end up with publishing the comments one by one
|
||||||
@ -322,6 +305,7 @@ class GithubProvider(GitProvider):
|
|||||||
try:
|
try:
|
||||||
self._publish_inline_comments_fallback_with_verification(comments)
|
self._publish_inline_comments_fallback_with_verification(comments)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
if get_settings().config.verbosity_level >= 2:
|
||||||
get_logger().error(f"Failed to publish inline code comments fallback, error: {e}")
|
get_logger().error(f"Failed to publish inline code comments fallback, error: {e}")
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
@ -347,8 +331,10 @@ class GithubProvider(GitProvider):
|
|||||||
for comment in fixed_comments_as_one_liner:
|
for comment in fixed_comments_as_one_liner:
|
||||||
try:
|
try:
|
||||||
self.publish_inline_comments([comment], disable_fallback=True)
|
self.publish_inline_comments([comment], disable_fallback=True)
|
||||||
|
if get_settings().config.verbosity_level >= 2:
|
||||||
get_logger().info(f"Published invalid comment as a single line comment: {comment}")
|
get_logger().info(f"Published invalid comment as a single line comment: {comment}")
|
||||||
except:
|
except:
|
||||||
|
if get_settings().config.verbosity_level >= 2:
|
||||||
get_logger().error(f"Failed to publish invalid comment as a single line comment: {comment}")
|
get_logger().error(f"Failed to publish invalid comment as a single line comment: {comment}")
|
||||||
|
|
||||||
def _verify_code_comment(self, comment: dict):
|
def _verify_code_comment(self, comment: dict):
|
||||||
@ -407,6 +393,7 @@ class GithubProvider(GitProvider):
|
|||||||
if fixed_comment != comment:
|
if fixed_comment != comment:
|
||||||
fixed_comments.append(fixed_comment)
|
fixed_comments.append(fixed_comment)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
if get_settings().config.verbosity_level >= 2:
|
||||||
get_logger().error(f"Failed to fix inline comment, error: {e}")
|
get_logger().error(f"Failed to fix inline comment, error: {e}")
|
||||||
return fixed_comments
|
return fixed_comments
|
||||||
|
|
||||||
@ -422,11 +409,13 @@ class GithubProvider(GitProvider):
|
|||||||
relevant_lines_end = suggestion['relevant_lines_end']
|
relevant_lines_end = suggestion['relevant_lines_end']
|
||||||
|
|
||||||
if not relevant_lines_start or relevant_lines_start == -1:
|
if not relevant_lines_start or relevant_lines_start == -1:
|
||||||
|
if get_settings().config.verbosity_level >= 2:
|
||||||
get_logger().exception(
|
get_logger().exception(
|
||||||
f"Failed to publish code suggestion, relevant_lines_start is {relevant_lines_start}")
|
f"Failed to publish code suggestion, relevant_lines_start is {relevant_lines_start}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if relevant_lines_end < relevant_lines_start:
|
if relevant_lines_end < relevant_lines_start:
|
||||||
|
if get_settings().config.verbosity_level >= 2:
|
||||||
get_logger().exception(f"Failed to publish code suggestion, "
|
get_logger().exception(f"Failed to publish code suggestion, "
|
||||||
f"relevant_lines_end is {relevant_lines_end} and "
|
f"relevant_lines_end is {relevant_lines_end} and "
|
||||||
f"relevant_lines_start is {relevant_lines_start}")
|
f"relevant_lines_start is {relevant_lines_start}")
|
||||||
@ -453,6 +442,7 @@ class GithubProvider(GitProvider):
|
|||||||
self.publish_inline_comments(post_parameters_list)
|
self.publish_inline_comments(post_parameters_list)
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
if get_settings().config.verbosity_level >= 2:
|
||||||
get_logger().error(f"Failed to publish code suggestion, error: {e}")
|
get_logger().error(f"Failed to publish code suggestion, error: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -512,7 +502,6 @@ class GithubProvider(GitProvider):
|
|||||||
elif self.deployment_type == 'user':
|
elif self.deployment_type == 'user':
|
||||||
same_comment_creator = self.github_user_id == existing_comment['user']['login']
|
same_comment_creator = self.github_user_id == existing_comment['user']['login']
|
||||||
if existing_comment['subject_type'] == 'file' and comment['path'] == existing_comment['path'] and same_comment_creator:
|
if existing_comment['subject_type'] == 'file' and comment['path'] == existing_comment['path'] and same_comment_creator:
|
||||||
|
|
||||||
headers, data_patch = self.pr._requester.requestJsonAndCheck(
|
headers, data_patch = self.pr._requester.requestJsonAndCheck(
|
||||||
"PATCH", f"{self.base_url}/repos/{self.repo}/pulls/comments/{existing_comment['id']}", input={"body":comment['body']}
|
"PATCH", f"{self.base_url}/repos/{self.repo}/pulls/comments/{existing_comment['id']}", input={"body":comment['body']}
|
||||||
)
|
)
|
||||||
@ -524,6 +513,7 @@ class GithubProvider(GitProvider):
|
|||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
if get_settings().config.verbosity_level >= 2:
|
||||||
get_logger().error(f"Failed to publish diffview file summary, error: {e}")
|
get_logger().error(f"Failed to publish diffview file summary, error: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -621,11 +611,8 @@ class GithubProvider(GitProvider):
|
|||||||
def _parse_pr_url(self, pr_url: str) -> Tuple[str, int]:
|
def _parse_pr_url(self, pr_url: str) -> Tuple[str, int]:
|
||||||
parsed_url = urlparse(pr_url)
|
parsed_url = urlparse(pr_url)
|
||||||
|
|
||||||
if parsed_url.path.startswith('/api/v3'):
|
|
||||||
parsed_url = urlparse(pr_url.replace("/api/v3", ""))
|
|
||||||
|
|
||||||
path_parts = parsed_url.path.strip('/').split('/')
|
path_parts = parsed_url.path.strip('/').split('/')
|
||||||
if 'api.github.com' in parsed_url.netloc or '/api/v3' in pr_url:
|
if self.base_domain in parsed_url.netloc:
|
||||||
if len(path_parts) < 5 or path_parts[3] != 'pulls':
|
if len(path_parts) < 5 or path_parts[3] != 'pulls':
|
||||||
raise ValueError("The provided URL does not appear to be a GitHub PR URL")
|
raise ValueError("The provided URL does not appear to be a GitHub PR URL")
|
||||||
repo_name = '/'.join(path_parts[1:3])
|
repo_name = '/'.join(path_parts[1:3])
|
||||||
@ -648,12 +635,8 @@ class GithubProvider(GitProvider):
|
|||||||
|
|
||||||
def _parse_issue_url(self, issue_url: str) -> Tuple[str, int]:
|
def _parse_issue_url(self, issue_url: str) -> Tuple[str, int]:
|
||||||
parsed_url = urlparse(issue_url)
|
parsed_url = urlparse(issue_url)
|
||||||
|
|
||||||
if 'github.com' not in parsed_url.netloc:
|
|
||||||
raise ValueError("The provided URL is not a valid GitHub URL")
|
|
||||||
|
|
||||||
path_parts = parsed_url.path.strip('/').split('/')
|
path_parts = parsed_url.path.strip('/').split('/')
|
||||||
if 'api.github.com' in parsed_url.netloc:
|
if self.base_domain in parsed_url.netloc:
|
||||||
if len(path_parts) < 5 or path_parts[3] != 'issues':
|
if len(path_parts) < 5 or path_parts[3] != 'issues':
|
||||||
raise ValueError("The provided URL does not appear to be a GitHub ISSUE URL")
|
raise ValueError("The provided URL does not appear to be a GitHub ISSUE URL")
|
||||||
repo_name = '/'.join(path_parts[1:3])
|
repo_name = '/'.join(path_parts[1:3])
|
||||||
@ -812,6 +795,7 @@ class GithubProvider(GitProvider):
|
|||||||
link = f"{self.base_url_html}/{self.repo}/pull/{self.pr_num}/files#diff-{sha_file}R{absolute_position}"
|
link = f"{self.base_url_html}/{self.repo}/pull/{self.pr_num}/files#diff-{sha_file}R{absolute_position}"
|
||||||
return link
|
return link
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
if get_settings().config.verbosity_level >= 2:
|
||||||
get_logger().info(f"Failed adding line link, error: {e}")
|
get_logger().info(f"Failed adding line link, error: {e}")
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
@ -7,16 +7,13 @@ import gitlab
|
|||||||
import requests
|
import requests
|
||||||
from gitlab import GitlabGetError
|
from gitlab import GitlabGetError
|
||||||
|
|
||||||
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
|
|
||||||
|
|
||||||
from ..algo.file_filter import filter_ignored
|
from ..algo.file_filter import filter_ignored
|
||||||
from ..algo.language_handler import is_valid_file
|
from ..algo.language_handler import is_valid_file
|
||||||
from ..algo.utils import (clip_tokens,
|
from ..algo.utils import load_large_diff, clip_tokens, find_line_number_of_relevant_line_in_file
|
||||||
find_line_number_of_relevant_line_in_file,
|
|
||||||
load_large_diff)
|
|
||||||
from ..config_loader import get_settings
|
from ..config_loader import get_settings
|
||||||
|
from .git_provider import GitProvider, MAX_FILES_ALLOWED_FULL
|
||||||
|
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
|
||||||
from ..log import get_logger
|
from ..log import get_logger
|
||||||
from .git_provider import MAX_FILES_ALLOWED_FULL, GitProvider
|
|
||||||
|
|
||||||
|
|
||||||
class DiffNotFoundError(Exception):
|
class DiffNotFoundError(Exception):
|
||||||
|
@ -4,9 +4,9 @@ from typing import List
|
|||||||
|
|
||||||
from git import Repo
|
from git import Repo
|
||||||
|
|
||||||
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
|
|
||||||
from pr_agent.config_loader import _find_repository_root, get_settings
|
from pr_agent.config_loader import _find_repository_root, get_settings
|
||||||
from pr_agent.git_providers.git_provider import GitProvider
|
from pr_agent.git_providers.git_provider import GitProvider
|
||||||
|
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
|
||||||
from pr_agent.log import get_logger
|
from pr_agent.log import get_logger
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,12 +3,11 @@ import os
|
|||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from dynaconf import Dynaconf
|
from dynaconf import Dynaconf
|
||||||
from starlette_context import context
|
|
||||||
|
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
from pr_agent.git_providers import (get_git_provider,
|
from pr_agent.git_providers import get_git_provider, get_git_provider_with_context
|
||||||
get_git_provider_with_context)
|
|
||||||
from pr_agent.log import get_logger
|
from pr_agent.log import get_logger
|
||||||
|
from starlette_context import context
|
||||||
|
|
||||||
|
|
||||||
def apply_repo_settings(pr_url):
|
def apply_repo_settings(pr_url):
|
||||||
@ -28,11 +27,8 @@ def apply_repo_settings(pr_url):
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
error_local = None
|
|
||||||
if repo_settings:
|
if repo_settings:
|
||||||
repo_settings_file = None
|
repo_settings_file = None
|
||||||
category = 'local'
|
|
||||||
try:
|
|
||||||
fd, repo_settings_file = tempfile.mkstemp(suffix='.toml')
|
fd, repo_settings_file = tempfile.mkstemp(suffix='.toml')
|
||||||
os.write(fd, repo_settings)
|
os.write(fd, repo_settings)
|
||||||
new_settings = Dynaconf(settings_files=[repo_settings_file])
|
new_settings = Dynaconf(settings_files=[repo_settings_file])
|
||||||
@ -43,12 +39,6 @@ def apply_repo_settings(pr_url):
|
|||||||
get_settings().unset(section)
|
get_settings().unset(section)
|
||||||
get_settings().set(section, section_dict, merge=False)
|
get_settings().set(section, section_dict, merge=False)
|
||||||
get_logger().info(f"Applying repo settings:\n{new_settings.as_dict()}")
|
get_logger().info(f"Applying repo settings:\n{new_settings.as_dict()}")
|
||||||
except Exception as e:
|
|
||||||
get_logger().warning(f"Failed to apply repo {category} settings, error: {str(e)}")
|
|
||||||
error_local = {'error': str(e), 'settings': repo_settings, 'category': category}
|
|
||||||
|
|
||||||
if error_local:
|
|
||||||
handle_configurations_errors([error_local], git_provider)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().exception("Failed to apply repo settings", e)
|
get_logger().exception("Failed to apply repo settings", e)
|
||||||
finally:
|
finally:
|
||||||
@ -63,36 +53,6 @@ def apply_repo_settings(pr_url):
|
|||||||
set_claude_model()
|
set_claude_model()
|
||||||
|
|
||||||
|
|
||||||
def handle_configurations_errors(config_errors, git_provider):
|
|
||||||
try:
|
|
||||||
if not any(config_errors):
|
|
||||||
return
|
|
||||||
|
|
||||||
for err in config_errors:
|
|
||||||
if err:
|
|
||||||
configuration_file_content = err['settings'].decode()
|
|
||||||
err_message = err['error']
|
|
||||||
config_type = err['category']
|
|
||||||
header = f"❌ **PR-Agent failed to apply '{config_type}' repo settings**"
|
|
||||||
body = f"{header}\n\nThe configuration file needs to be a valid [TOML](https://qodo-merge-docs.qodo.ai/usage-guide/configuration_options/), please fix it.\n\n"
|
|
||||||
body += f"___\n\n**Error message:**\n`{err_message}`\n\n"
|
|
||||||
if git_provider.is_supported("gfm_markdown"):
|
|
||||||
body += f"\n\n<details><summary>Configuration content:</summary>\n\n```toml\n{configuration_file_content}\n```\n\n</details>"
|
|
||||||
else:
|
|
||||||
body += f"\n\n**Configuration content:**\n\n```toml\n{configuration_file_content}\n```\n\n"
|
|
||||||
get_logger().warning(f"Sending a 'configuration error' comment to the PR", artifact={'body': body})
|
|
||||||
# git_provider.publish_comment(body)
|
|
||||||
if hasattr(git_provider, 'publish_persistent_comment'):
|
|
||||||
git_provider.publish_persistent_comment(body,
|
|
||||||
initial_header=header,
|
|
||||||
update_header=False,
|
|
||||||
final_update_message=False)
|
|
||||||
else:
|
|
||||||
git_provider.publish_comment(body)
|
|
||||||
except Exception as e:
|
|
||||||
get_logger().exception(f"Failed to handle configurations errors", e)
|
|
||||||
|
|
||||||
|
|
||||||
def set_claude_model():
|
def set_claude_model():
|
||||||
"""
|
"""
|
||||||
set the claude-sonnet-3.5 model easily (even by users), just by stating: --config.model='claude-3-5-sonnet'
|
set the claude-sonnet-3.5 model easily (even by users), just by stating: --config.model='claude-3-5-sonnet'
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
from pr_agent.identity_providers.default_identity_provider import \
|
from pr_agent.identity_providers.default_identity_provider import DefaultIdentityProvider
|
||||||
DefaultIdentityProvider
|
|
||||||
|
|
||||||
_IDENTITY_PROVIDERS = {
|
_IDENTITY_PROVIDERS = {
|
||||||
'default': DefaultIdentityProvider
|
'default': DefaultIdentityProvider
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
from pr_agent.identity_providers.identity_provider import (Eligibility,
|
from pr_agent.identity_providers.identity_provider import Eligibility, IdentityProvider
|
||||||
IdentityProvider)
|
|
||||||
|
|
||||||
|
|
||||||
class DefaultIdentityProvider(IdentityProvider):
|
class DefaultIdentityProvider(IdentityProvider):
|
||||||
|
@ -8,10 +8,12 @@ def get_secret_provider():
|
|||||||
provider_id = get_settings().config.secret_provider
|
provider_id = get_settings().config.secret_provider
|
||||||
if provider_id == 'google_cloud_storage':
|
if provider_id == 'google_cloud_storage':
|
||||||
try:
|
try:
|
||||||
from pr_agent.secret_providers.google_cloud_storage_secret_provider import \
|
from pr_agent.secret_providers.google_cloud_storage_secret_provider import GoogleCloudStorageSecretProvider
|
||||||
GoogleCloudStorageSecretProvider
|
|
||||||
return GoogleCloudStorageSecretProvider()
|
return GoogleCloudStorageSecretProvider()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError(f"Failed to initialize google_cloud_storage secret provider {provider_id}") from e
|
raise ValueError(f"Failed to initialize google_cloud_storage secret provider {provider_id}") from e
|
||||||
else:
|
else:
|
||||||
raise ValueError("Unknown SECRET_PROVIDER")
|
raise ValueError("Unknown SECRET_PROVIDER")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,9 +16,8 @@
|
|||||||
},
|
},
|
||||||
"scopes": [
|
"scopes": [
|
||||||
"account",
|
"account",
|
||||||
"repository:write",
|
"repository",
|
||||||
"pullrequest:write",
|
"pullrequest"
|
||||||
"wiki"
|
|
||||||
],
|
],
|
||||||
"contexts": [
|
"contexts": [
|
||||||
"account"
|
"account"
|
||||||
|
@ -9,9 +9,9 @@ import secrets
|
|||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
|
|
||||||
import uvicorn
|
import uvicorn
|
||||||
from fastapi import APIRouter, Depends, FastAPI, HTTPException, Request
|
from fastapi import APIRouter, Depends, FastAPI, HTTPException
|
||||||
from fastapi.encoders import jsonable_encoder
|
|
||||||
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
||||||
|
from fastapi.encoders import jsonable_encoder
|
||||||
from starlette import status
|
from starlette import status
|
||||||
from starlette.background import BackgroundTasks
|
from starlette.background import BackgroundTasks
|
||||||
from starlette.middleware import Middleware
|
from starlette.middleware import Middleware
|
||||||
@ -23,6 +23,9 @@ from pr_agent.agent.pr_agent import PRAgent, command2class
|
|||||||
from pr_agent.algo.utils import update_settings_from_args
|
from pr_agent.algo.utils import update_settings_from_args
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
from pr_agent.git_providers.utils import apply_repo_settings
|
from pr_agent.git_providers.utils import apply_repo_settings
|
||||||
|
from pr_agent.log import get_logger
|
||||||
|
from fastapi import Request, Depends
|
||||||
|
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
||||||
from pr_agent.log import LoggingFormat, get_logger, setup_logger
|
from pr_agent.log import LoggingFormat, get_logger, setup_logger
|
||||||
|
|
||||||
setup_logger(fmt=LoggingFormat.JSON, level="DEBUG")
|
setup_logger(fmt=LoggingFormat.JSON, level="DEBUG")
|
||||||
|
@ -75,11 +75,8 @@ async def handle_manifest(request: Request, response: Response):
|
|||||||
return JSONResponse(manifest_obj)
|
return JSONResponse(manifest_obj)
|
||||||
|
|
||||||
|
|
||||||
async def _perform_commands_bitbucket(commands_conf: str, agent: PRAgent, api_url: str, log_context: dict, data: dict):
|
async def _perform_commands_bitbucket(commands_conf: str, agent: PRAgent, api_url: str, log_context: dict):
|
||||||
apply_repo_settings(api_url)
|
apply_repo_settings(api_url)
|
||||||
if data.get("event", "") == "pullrequest:created":
|
|
||||||
if not should_process_pr_logic(data):
|
|
||||||
return
|
|
||||||
commands = get_settings().get(f"bitbucket_app.{commands_conf}", {})
|
commands = get_settings().get(f"bitbucket_app.{commands_conf}", {})
|
||||||
get_settings().set("config.is_auto_command", True)
|
get_settings().set("config.is_auto_command", True)
|
||||||
for command in commands:
|
for command in commands:
|
||||||
@ -98,14 +95,11 @@ async def _perform_commands_bitbucket(commands_conf: str, agent: PRAgent, api_ur
|
|||||||
|
|
||||||
def is_bot_user(data) -> bool:
|
def is_bot_user(data) -> bool:
|
||||||
try:
|
try:
|
||||||
actor = data.get("data", {}).get("actor", {})
|
if data["data"]["actor"]["type"] != "user":
|
||||||
# allow actor type: user . if it's "AppUser" or "team" then it is a bot user
|
get_logger().info(f"BitBucket actor type is not 'user': {data['data']['actor']['type']}")
|
||||||
allowed_actor_types = {"user"}
|
|
||||||
if actor and actor["type"].lower() not in allowed_actor_types:
|
|
||||||
get_logger().info(f"BitBucket actor type is not 'user', skipping: {actor}")
|
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().error(f"Failed 'is_bot_user' logic: {e}")
|
get_logger().error("Failed 'is_bot_user' logic: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@ -164,18 +158,16 @@ async def handle_github_webhooks(background_tasks: BackgroundTasks, request: Req
|
|||||||
return "OK"
|
return "OK"
|
||||||
|
|
||||||
# Get the username of the sender
|
# Get the username of the sender
|
||||||
actor = data.get("data", {}).get("actor", {})
|
|
||||||
if actor:
|
|
||||||
try:
|
try:
|
||||||
username = actor["username"]
|
username = data["data"]["actor"]["username"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
try:
|
try:
|
||||||
username = actor["display_name"]
|
username = data["data"]["actor"]["display_name"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
username = actor["nickname"]
|
username = data["data"]["actor"]["nickname"]
|
||||||
log_context["sender"] = username
|
log_context["sender"] = username
|
||||||
|
|
||||||
sender_id = data.get("data", {}).get("actor", {}).get("account_id", "")
|
sender_id = data["data"]["actor"]["account_id"]
|
||||||
log_context["sender_id"] = sender_id
|
log_context["sender_id"] = sender_id
|
||||||
jwt_parts = input_jwt.split(".")
|
jwt_parts = input_jwt.split(".")
|
||||||
claim_part = jwt_parts[1]
|
claim_part = jwt_parts[1]
|
||||||
@ -201,7 +193,7 @@ async def handle_github_webhooks(background_tasks: BackgroundTasks, request: Req
|
|||||||
if get_identity_provider().verify_eligibility("bitbucket",
|
if get_identity_provider().verify_eligibility("bitbucket",
|
||||||
sender_id, pr_url) is not Eligibility.NOT_ELIGIBLE:
|
sender_id, pr_url) is not Eligibility.NOT_ELIGIBLE:
|
||||||
if get_settings().get("bitbucket_app.pr_commands"):
|
if get_settings().get("bitbucket_app.pr_commands"):
|
||||||
await _perform_commands_bitbucket("pr_commands", PRAgent(), pr_url, log_context, data)
|
await _perform_commands_bitbucket("pr_commands", PRAgent(), pr_url, log_context)
|
||||||
elif event == "pullrequest:comment_created":
|
elif event == "pullrequest:comment_created":
|
||||||
pr_url = data["data"]["pullrequest"]["links"]["html"]["href"]
|
pr_url = data["data"]["pullrequest"]["links"]["html"]["href"]
|
||||||
log_context["api_url"] = pr_url
|
log_context["api_url"] = pr_url
|
||||||
|
@ -6,20 +6,20 @@ from typing import List
|
|||||||
import uvicorn
|
import uvicorn
|
||||||
from fastapi import APIRouter, FastAPI
|
from fastapi import APIRouter, FastAPI
|
||||||
from fastapi.encoders import jsonable_encoder
|
from fastapi.encoders import jsonable_encoder
|
||||||
from fastapi.responses import RedirectResponse
|
|
||||||
from starlette import status
|
from starlette import status
|
||||||
from starlette.background import BackgroundTasks
|
from starlette.background import BackgroundTasks
|
||||||
from starlette.middleware import Middleware
|
from starlette.middleware import Middleware
|
||||||
from starlette.requests import Request
|
from starlette.requests import Request
|
||||||
from starlette.responses import JSONResponse
|
from starlette.responses import JSONResponse
|
||||||
from starlette_context.middleware import RawContextMiddleware
|
from starlette_context.middleware import RawContextMiddleware
|
||||||
|
|
||||||
from pr_agent.agent.pr_agent import PRAgent
|
from pr_agent.agent.pr_agent import PRAgent
|
||||||
from pr_agent.algo.utils import update_settings_from_args
|
from pr_agent.algo.utils import update_settings_from_args
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
from pr_agent.git_providers.utils import apply_repo_settings
|
from pr_agent.git_providers.utils import apply_repo_settings
|
||||||
from pr_agent.log import LoggingFormat, get_logger, setup_logger
|
from pr_agent.log import LoggingFormat, get_logger, setup_logger
|
||||||
from pr_agent.servers.utils import verify_signature
|
from pr_agent.servers.utils import verify_signature
|
||||||
|
from fastapi.responses import RedirectResponse
|
||||||
|
|
||||||
|
|
||||||
setup_logger(fmt=LoggingFormat.JSON, level="DEBUG")
|
setup_logger(fmt=LoggingFormat.JSON, level="DEBUG")
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
@ -15,8 +15,7 @@ from starlette_context.middleware import RawContextMiddleware
|
|||||||
from pr_agent.agent.pr_agent import PRAgent
|
from pr_agent.agent.pr_agent import PRAgent
|
||||||
from pr_agent.algo.utils import update_settings_from_args
|
from pr_agent.algo.utils import update_settings_from_args
|
||||||
from pr_agent.config_loader import get_settings, global_settings
|
from pr_agent.config_loader import get_settings, global_settings
|
||||||
from pr_agent.git_providers import (get_git_provider,
|
from pr_agent.git_providers import get_git_provider, get_git_provider_with_context
|
||||||
get_git_provider_with_context)
|
|
||||||
from pr_agent.git_providers.git_provider import IncrementalPR
|
from pr_agent.git_providers.git_provider import IncrementalPR
|
||||||
from pr_agent.git_providers.utils import apply_repo_settings
|
from pr_agent.git_providers.utils import apply_repo_settings
|
||||||
from pr_agent.identity_providers import get_identity_provider
|
from pr_agent.identity_providers import get_identity_provider
|
||||||
@ -250,7 +249,7 @@ def is_bot_user(sender, sender_type):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def should_process_pr_logic(body) -> bool:
|
def should_process_pr_logic(sender_type, sender, body) -> bool:
|
||||||
try:
|
try:
|
||||||
pull_request = body.get("pull_request", {})
|
pull_request = body.get("pull_request", {})
|
||||||
title = pull_request.get("title", "")
|
title = pull_request.get("title", "")
|
||||||
@ -307,10 +306,10 @@ async def handle_request(body: Dict[str, Any], event: str):
|
|||||||
log_context, sender, sender_id, sender_type = get_log_context(body, event, action, build_number)
|
log_context, sender, sender_id, sender_type = get_log_context(body, event, action, build_number)
|
||||||
|
|
||||||
# logic to ignore PRs opened by bot, PRs with specific titles, labels, source branches, or target branches
|
# logic to ignore PRs opened by bot, PRs with specific titles, labels, source branches, or target branches
|
||||||
if is_bot_user(sender, sender_type) and 'check_run' not in body:
|
if is_bot_user(sender, sender_type):
|
||||||
return {}
|
return {}
|
||||||
if action != 'created' and 'check_run' not in body:
|
if action != 'created' and 'check_run' not in body:
|
||||||
if not should_process_pr_logic(body):
|
if not should_process_pr_logic(sender_type, sender, body):
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
if 'check_run' in body: # handle failed checks
|
if 'check_run' in body: # handle failed checks
|
||||||
@ -374,8 +373,6 @@ def _check_pull_request_event(action: str, body: dict, log_context: dict) -> Tup
|
|||||||
async def _perform_auto_commands_github(commands_conf: str, agent: PRAgent, body: dict, api_url: str,
|
async def _perform_auto_commands_github(commands_conf: str, agent: PRAgent, body: dict, api_url: str,
|
||||||
log_context: dict):
|
log_context: dict):
|
||||||
apply_repo_settings(api_url)
|
apply_repo_settings(api_url)
|
||||||
if not should_process_pr_logic(body): # Here we already updated the configuration with the repo settings
|
|
||||||
return {}
|
|
||||||
commands = get_settings().get(f"github_app.{commands_conf}")
|
commands = get_settings().get(f"github_app.{commands_conf}")
|
||||||
if not commands:
|
if not commands:
|
||||||
get_logger().info(f"New PR, but no auto commands configured")
|
get_logger().info(f"New PR, but no auto commands configured")
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import time
|
|
||||||
import traceback
|
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
import traceback
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
import time
|
||||||
import aiohttp
|
|
||||||
import requests
|
import requests
|
||||||
|
import aiohttp
|
||||||
|
|
||||||
from pr_agent.agent.pr_agent import PRAgent
|
from pr_agent.agent.pr_agent import PRAgent
|
||||||
from pr_agent.config_loader import get_settings
|
from pr_agent.config_loader import get_settings
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import copy
|
import copy
|
||||||
import json
|
|
||||||
import re
|
import re
|
||||||
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import uvicorn
|
import uvicorn
|
||||||
@ -59,10 +59,8 @@ async def handle_request(api_url: str, body: str, log_context: dict, sender_id:
|
|||||||
|
|
||||||
|
|
||||||
async def _perform_commands_gitlab(commands_conf: str, agent: PRAgent, api_url: str,
|
async def _perform_commands_gitlab(commands_conf: str, agent: PRAgent, api_url: str,
|
||||||
log_context: dict, data: dict):
|
log_context: dict):
|
||||||
apply_repo_settings(api_url)
|
apply_repo_settings(api_url)
|
||||||
if not should_process_pr_logic(data): # Here we already updated the configurations
|
|
||||||
return
|
|
||||||
commands = get_settings().get(f"gitlab.{commands_conf}", {})
|
commands = get_settings().get(f"gitlab.{commands_conf}", {})
|
||||||
get_settings().set("config.is_auto_command", True)
|
get_settings().set("config.is_auto_command", True)
|
||||||
for command in commands:
|
for command in commands:
|
||||||
@ -92,12 +90,8 @@ def is_bot_user(data) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def should_process_pr_logic(data) -> bool:
|
def should_process_pr_logic(data, title) -> bool:
|
||||||
try:
|
try:
|
||||||
if not data.get('object_attributes', {}):
|
|
||||||
return False
|
|
||||||
title = data['object_attributes'].get('title')
|
|
||||||
|
|
||||||
# logic to ignore MRs for titles, labels and source, target branches.
|
# logic to ignore MRs for titles, labels and source, target branches.
|
||||||
ignore_mr_title = get_settings().get("CONFIG.IGNORE_PR_TITLE", [])
|
ignore_mr_title = get_settings().get("CONFIG.IGNORE_PR_TITLE", [])
|
||||||
ignore_mr_labels = get_settings().get("CONFIG.IGNORE_PR_LABELS", [])
|
ignore_mr_labels = get_settings().get("CONFIG.IGNORE_PR_LABELS", [])
|
||||||
@ -139,7 +133,6 @@ def should_process_pr_logic(data) -> bool:
|
|||||||
async def gitlab_webhook(background_tasks: BackgroundTasks, request: Request):
|
async def gitlab_webhook(background_tasks: BackgroundTasks, request: Request):
|
||||||
start_time = datetime.now()
|
start_time = datetime.now()
|
||||||
request_json = await request.json()
|
request_json = await request.json()
|
||||||
context["settings"] = copy.deepcopy(global_settings)
|
|
||||||
|
|
||||||
async def inner(data: dict):
|
async def inner(data: dict):
|
||||||
log_context = {"server_type": "gitlab_app"}
|
log_context = {"server_type": "gitlab_app"}
|
||||||
@ -155,6 +148,7 @@ async def gitlab_webhook(background_tasks: BackgroundTasks, request: Request):
|
|||||||
secret_dict = json.loads(secret)
|
secret_dict = json.loads(secret)
|
||||||
gitlab_token = secret_dict["gitlab_token"]
|
gitlab_token = secret_dict["gitlab_token"]
|
||||||
log_context["token_id"] = secret_dict.get("token_name", secret_dict.get("id", "unknown"))
|
log_context["token_id"] = secret_dict.get("token_name", secret_dict.get("id", "unknown"))
|
||||||
|
context["settings"] = copy.deepcopy(global_settings)
|
||||||
context["settings"].gitlab.personal_access_token = gitlab_token
|
context["settings"].gitlab.personal_access_token = gitlab_token
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().error(f"Failed to validate secret {request_token}: {e}")
|
get_logger().error(f"Failed to validate secret {request_token}: {e}")
|
||||||
@ -179,9 +173,9 @@ async def gitlab_webhook(background_tasks: BackgroundTasks, request: Request):
|
|||||||
# ignore bot users
|
# ignore bot users
|
||||||
if is_bot_user(data):
|
if is_bot_user(data):
|
||||||
return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"}))
|
return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"}))
|
||||||
if data.get('event_type') != 'note': # not a comment
|
if data.get('event_type') != 'note' and data.get('object_attributes', {}): # not a comment
|
||||||
# ignore MRs based on title, labels, source and target branches
|
# ignore MRs based on title, labels, source and target branches
|
||||||
if not should_process_pr_logic(data):
|
if not should_process_pr_logic(data, data['object_attributes'].get('title')):
|
||||||
return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"}))
|
return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"}))
|
||||||
|
|
||||||
log_context["sender"] = sender
|
log_context["sender"] = sender
|
||||||
@ -194,7 +188,7 @@ async def gitlab_webhook(background_tasks: BackgroundTasks, request: Request):
|
|||||||
get_logger().info(f"Skipping draft MR: {url}")
|
get_logger().info(f"Skipping draft MR: {url}")
|
||||||
return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"}))
|
return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"}))
|
||||||
|
|
||||||
await _perform_commands_gitlab("pr_commands", PRAgent(), url, log_context, data)
|
await _perform_commands_gitlab("pr_commands", PRAgent(), url, log_context)
|
||||||
elif data.get('object_kind') == 'note' and data.get('event_type') == 'note': # comment on MR
|
elif data.get('object_kind') == 'note' and data.get('event_type') == 'note': # comment on MR
|
||||||
if 'merge_request' in data:
|
if 'merge_request' in data:
|
||||||
mr = data['merge_request']
|
mr = data['merge_request']
|
||||||
@ -226,7 +220,7 @@ async def gitlab_webhook(background_tasks: BackgroundTasks, request: Request):
|
|||||||
content=jsonable_encoder({"message": "success"}))
|
content=jsonable_encoder({"message": "success"}))
|
||||||
|
|
||||||
get_logger().debug(f'A push event has been received: {url}')
|
get_logger().debug(f'A push event has been received: {url}')
|
||||||
await _perform_commands_gitlab("push_commands", PRAgent(), url, log_context, data)
|
await _perform_commands_gitlab("push_commands", PRAgent(), url, log_context)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().error(f"Failed to handle push event: {e}")
|
get_logger().error(f"Failed to handle push event: {e}")
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ from starlette_context.middleware import RawContextMiddleware
|
|||||||
|
|
||||||
from pr_agent.servers.github_app import router
|
from pr_agent.servers.github_app import router
|
||||||
|
|
||||||
|
|
||||||
middleware = [Middleware(RawContextMiddleware)]
|
middleware = [Middleware(RawContextMiddleware)]
|
||||||
app = FastAPI(middleware=middleware)
|
app = FastAPI(middleware=middleware)
|
||||||
app.include_router(router)
|
app.include_router(router)
|
||||||
|
@ -2,7 +2,7 @@ import hashlib
|
|||||||
import hmac
|
import hmac
|
||||||
import time
|
import time
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import Any, Callable
|
from typing import Callable, Any
|
||||||
|
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
|
|
||||||
|
@ -43,9 +43,6 @@ api_base = "" # the base url for your local Llama 2, Code Llama, and other model
|
|||||||
vertex_project = "" # the google cloud platform project name for your vertexai deployment
|
vertex_project = "" # the google cloud platform project name for your vertexai deployment
|
||||||
vertex_location = "" # the google cloud platform location for your vertexai deployment
|
vertex_location = "" # the google cloud platform location for your vertexai deployment
|
||||||
|
|
||||||
[google_ai_studio]
|
|
||||||
gemini_api_key = "" # the google AI Studio API key
|
|
||||||
|
|
||||||
[github]
|
[github]
|
||||||
# ---- Set the following only for deployment type == "user"
|
# ---- Set the following only for deployment type == "user"
|
||||||
user_token = "" # A GitHub personal access token with 'repo' scope.
|
user_token = "" # A GitHub personal access token with 'repo' scope.
|
||||||
@ -63,7 +60,6 @@ webhook_secret = "<WEBHOOK SECRET>" # Optional, may be commented out.
|
|||||||
[gitlab]
|
[gitlab]
|
||||||
# Gitlab personal access token
|
# Gitlab personal access token
|
||||||
personal_access_token = ""
|
personal_access_token = ""
|
||||||
shared_secret = "" # webhook secret
|
|
||||||
|
|
||||||
[bitbucket]
|
[bitbucket]
|
||||||
# For Bitbucket personal/repository bearer token
|
# For Bitbucket personal/repository bearer token
|
||||||
|
@ -7,7 +7,6 @@ fallback_models=["gpt-4o-2024-05-13"]
|
|||||||
git_provider="github"
|
git_provider="github"
|
||||||
publish_output=true
|
publish_output=true
|
||||||
publish_output_progress=true
|
publish_output_progress=true
|
||||||
publish_output_no_suggestions=true
|
|
||||||
verbosity_level=0 # 0,1,2
|
verbosity_level=0 # 0,1,2
|
||||||
use_extra_bad_extensions=false
|
use_extra_bad_extensions=false
|
||||||
# Configurations
|
# Configurations
|
||||||
@ -52,7 +51,9 @@ require_tests_review=true
|
|||||||
require_estimate_effort_to_review=true
|
require_estimate_effort_to_review=true
|
||||||
require_can_be_split_review=false
|
require_can_be_split_review=false
|
||||||
require_security_review=true
|
require_security_review=true
|
||||||
require_ticket_analysis_review=true
|
# soc2
|
||||||
|
require_soc2_ticket=false
|
||||||
|
soc2_ticket_prompt="Does the PR description include a link to ticket in a project management system (e.g., Jira, Asana, Trello, etc.) ?"
|
||||||
# general options
|
# general options
|
||||||
num_code_suggestions=0
|
num_code_suggestions=0
|
||||||
inline_code_comments = false
|
inline_code_comments = false
|
||||||
@ -76,7 +77,7 @@ maximal_review_effort=5
|
|||||||
|
|
||||||
|
|
||||||
[pr_description] # /describe #
|
[pr_description] # /describe #
|
||||||
publish_labels=false
|
publish_labels=true
|
||||||
add_original_user_description=true
|
add_original_user_description=true
|
||||||
generate_ai_title=false
|
generate_ai_title=false
|
||||||
use_bullet_points=true
|
use_bullet_points=true
|
||||||
@ -107,11 +108,10 @@ enable_help_text=false
|
|||||||
|
|
||||||
|
|
||||||
[pr_code_suggestions] # /improve #
|
[pr_code_suggestions] # /improve #
|
||||||
max_context_tokens=16000
|
max_context_tokens=14000
|
||||||
#
|
#
|
||||||
commitable_code_suggestions = false
|
commitable_code_suggestions = false
|
||||||
dual_publishing_score_threshold=-1 # -1 to disable, [0-10] to set the threshold (>=) for publishing a code suggestion both in a table and as commitable
|
dual_publishing_score_threshold=-1 # -1 to disable, [0-10] to set the threshold (>=) for publishing a code suggestion both in a table and as commitable
|
||||||
focus_only_on_problems=false
|
|
||||||
#
|
#
|
||||||
extra_instructions = ""
|
extra_instructions = ""
|
||||||
rank_suggestions = false
|
rank_suggestions = false
|
||||||
@ -123,6 +123,7 @@ max_history_len=4
|
|||||||
# enable to apply suggestion 💎
|
# enable to apply suggestion 💎
|
||||||
apply_suggestions_checkbox=true
|
apply_suggestions_checkbox=true
|
||||||
# suggestions scoring
|
# suggestions scoring
|
||||||
|
self_reflect_on_suggestions=true
|
||||||
suggestions_score_threshold=0 # [0-10]| recommend not to set this value above 8, since above it may clip highly relevant suggestions
|
suggestions_score_threshold=0 # [0-10]| recommend not to set this value above 8, since above it may clip highly relevant suggestions
|
||||||
# params for '/improve --extended' mode
|
# params for '/improve --extended' mode
|
||||||
auto_extended_mode=true
|
auto_extended_mode=true
|
||||||
@ -135,10 +136,8 @@ final_clip_factor = 0.8
|
|||||||
demand_code_suggestions_self_review=false # add a checkbox for the author to self-review the code suggestions
|
demand_code_suggestions_self_review=false # add a checkbox for the author to self-review the code suggestions
|
||||||
code_suggestions_self_review_text= "**Author self-review**: I have reviewed the PR code suggestions, and addressed the relevant ones."
|
code_suggestions_self_review_text= "**Author self-review**: I have reviewed the PR code suggestions, and addressed the relevant ones."
|
||||||
approve_pr_on_self_review=false # Pro feature. if true, the PR will be auto-approved after the author clicks on the self-review checkbox
|
approve_pr_on_self_review=false # Pro feature. if true, the PR will be auto-approved after the author clicks on the self-review checkbox
|
||||||
fold_suggestions_on_self_review=true # Pro feature. if true, the code suggestions will be folded after the author clicks on the self-review checkbox
|
# Suggestion impact
|
||||||
# Suggestion impact 💎
|
|
||||||
publish_post_process_suggestion_impact=true
|
publish_post_process_suggestion_impact=true
|
||||||
wiki_page_accepted_suggestions=true
|
|
||||||
|
|
||||||
[pr_custom_prompt] # /custom_prompt #
|
[pr_custom_prompt] # /custom_prompt #
|
||||||
prompt = """\
|
prompt = """\
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
[pr_code_suggestions_prompt]
|
[pr_code_suggestions_prompt]
|
||||||
system="""You are PR-Reviewer, an AI specializing in Pull Request (PR) code analysis and suggestions.
|
system="""You are PR-Reviewer, an AI specializing in Pull Request (PR) code analysis and suggestions.
|
||||||
{%- if not focus_only_on_problems %}
|
Your task is to examine the provided code diff, focusing on new code (lines prefixed with '+'), and offer concise, actionable suggestions to fix possible bugs and problems, and enhance code quality, readability, and performance.
|
||||||
Your task is to examine the provided code diff, focusing on new code (lines prefixed with '+'), and offer concise, actionable suggestions to fix possible bugs and problems, and enhance code quality and performance.
|
|
||||||
{%- else %}
|
|
||||||
Your task is to examine the provided code diff, focusing on new code (lines prefixed with '+'), and offer concise, actionable suggestions to fix critical bugs and problems.
|
|
||||||
{%- endif %}
|
|
||||||
|
|
||||||
The PR code diff will be in the following structured format:
|
The PR code diff will be in the following structured format:
|
||||||
======
|
======
|
||||||
@ -17,10 +14,10 @@ The PR code diff will be in the following structured format:
|
|||||||
|
|
||||||
@@ ... @@ def func1():
|
@@ ... @@ def func1():
|
||||||
__new hunk__
|
__new hunk__
|
||||||
unchanged code line0 in the PR
|
11 unchanged code line0 in the PR
|
||||||
unchanged code line1 in the PR
|
12 unchanged code line1 in the PR
|
||||||
+new code line2 added in the PR
|
13 +new code line2 added in the PR
|
||||||
unchanged code line3 in the PR
|
14 unchanged code line3 in the PR
|
||||||
__old hunk__
|
__old hunk__
|
||||||
unchanged code line0
|
unchanged code line0
|
||||||
unchanged code line1
|
unchanged code line1
|
||||||
@ -29,15 +26,17 @@ __old hunk__
|
|||||||
|
|
||||||
@@ ... @@ def func2():
|
@@ ... @@ def func2():
|
||||||
__new hunk__
|
__new hunk__
|
||||||
unchanged code line4
|
...
|
||||||
+new code line5 removed in the PR
|
__old hunk__
|
||||||
unchanged code line6
|
...
|
||||||
|
|
||||||
|
|
||||||
## File: 'src/file2.py'
|
## File: 'src/file2.py'
|
||||||
...
|
...
|
||||||
======
|
======
|
||||||
|
|
||||||
- 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.
|
- 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 added or removed in a specific chunk, the corresponding section will be omitted.
|
||||||
|
- Line numbers were added for the '__new hunk__' sections to help referencing specific lines in the code suggestions. These numbers are for reference only and are not part of the actual code.
|
||||||
- Code lines are prefixed with symbols: '+' for new code added in the PR, '-' for code removed, and ' ' for unchanged code.
|
- Code lines are prefixed with symbols: '+' for new code added in the PR, '-' for code removed, and ' ' for unchanged code.
|
||||||
{%- if is_ai_metadata %}
|
{%- if is_ai_metadata %}
|
||||||
- When available, an AI-generated summary will precede each file's diff, with a high-level overview of the changes. Note that this summary may not be fully accurate or complete.
|
- When available, an AI-generated summary will precede each file's diff, with a high-level overview of the changes. Note that this summary may not be fully accurate or complete.
|
||||||
@ -45,20 +44,12 @@ __new hunk__
|
|||||||
|
|
||||||
|
|
||||||
Specific guidelines for generating code suggestions:
|
Specific guidelines for generating code suggestions:
|
||||||
{%- if not focus_only_on_problems %}
|
|
||||||
- Provide up to {{ num_code_suggestions }} distinct and insightful code suggestions.
|
- Provide up to {{ num_code_suggestions }} distinct and insightful code suggestions.
|
||||||
{%- else %}
|
- Focus solely on enhancing new code introduced in the PR, identified by '+' prefixes in '__new hunk__' sections (after the line numbers).
|
||||||
- Provide up to {{ num_code_suggestions }} distinct and insightful code suggestions. Return less suggestions if no pertinent ones are applicable.
|
|
||||||
{%- endif %}
|
|
||||||
- Focus solely on enhancing new code introduced in the PR, identified by '+' prefixes in '__new hunk__' sections.
|
|
||||||
{%- if not focus_only_on_problems %}
|
|
||||||
- Prioritize suggestions that address potential issues, critical problems, and bugs in the PR code. Avoid repeating changes already implemented in the PR. If no pertinent suggestions are applicable, return an empty list.
|
- Prioritize suggestions that address potential issues, critical problems, and bugs in the PR code. Avoid repeating changes already implemented in the PR. If no pertinent suggestions are applicable, return an empty list.
|
||||||
{%- else %}
|
- Avoid proposing additions of docstrings, type hints, or comments, or the removal of unused imports.
|
||||||
- Only give suggestions that address critical problems and bugs in the PR code. If no relevant suggestions are applicable, return an empty list.
|
|
||||||
{%- endif %}
|
|
||||||
- Don't suggest to add docstring, type hints, or comments, to remove unused imports, or to use more specific exception types.
|
|
||||||
- When referencing variables or names from the code, enclose them in backticks (`). Example: "ensure that `variable_name` is..."
|
- When referencing variables or names from the code, enclose them in backticks (`). Example: "ensure that `variable_name` is..."
|
||||||
- Be mindful you are viewing a partial PR code diff, not the full codebase. Avoid suggestions that might conflict with unseen code or alerting variables not declared in the visible scope, as the context is incomplete.
|
- Be mindful you are viewing a partial PR code diff, not the full codebase. Avoid suggestions that might conflict with unseen code or alerting on variables not declared in the visible scope, as the context is incomplete.
|
||||||
|
|
||||||
|
|
||||||
{%- if extra_instructions %}
|
{%- if extra_instructions %}
|
||||||
@ -77,14 +68,12 @@ class CodeSuggestion(BaseModel):
|
|||||||
relevant_file: str = Field(description="Full path of the relevant file")
|
relevant_file: str = Field(description="Full path of the relevant file")
|
||||||
language: str = Field(description="Programming language used by the relevant file")
|
language: str = Field(description="Programming language used by the relevant file")
|
||||||
suggestion_content: str = Field(description="An actionable suggestion to enhance, improve or fix the new code introduced in the PR. Don't present here actual code snippets, just the suggestion. Be short and concise")
|
suggestion_content: str = Field(description="An actionable suggestion to enhance, improve or fix the new code introduced in the PR. Don't present here actual code snippets, just the suggestion. Be short and concise")
|
||||||
existing_code: str = Field(description="A short code snippet from a '__new hunk__' section that the suggestion aims to enhance or fix. Include only complete code lines. Use ellipsis (...) for brevity if needed. This snippet should represent the specific PR code targeted for improvement.")
|
existing_code: str = Field(description="A short code snippet from a '__new hunk__' section that the suggestion aims to enhance or fix. Include only complete code lines, without line numbers. Use ellipsis (...) for brevity if needed. This snippet should represent the specific PR code targeted for improvement.")
|
||||||
improved_code: str = Field(description="A refined code snippet that replaces the 'existing_code' snippet after implementing the suggestion.")
|
improved_code: str = Field(description="A refined code snippet that replaces the 'existing_code' snippet after implementing the suggestion.")
|
||||||
one_sentence_summary: str = Field(description="A concise, single-sentence overview of the suggested improvement. Focus on the 'what'. Be general, and avoid method or variable names.")
|
one_sentence_summary: str = Field(description="A concise, single-sentence overview of the suggested improvement. Focus on the 'what'. Be general, and avoid method or variable names.")
|
||||||
{%- if not focus_only_on_problems %}
|
relevant_lines_start: int = Field(description="The relevant line number, from a '__new hunk__' section, where the suggestion starts (inclusive). Should be derived from the hunk line numbers, and correspond to the beginning of the 'existing code' snippet above")
|
||||||
label: str = Field(description="A single, descriptive label that best characterizes the suggestion type. Possible labels include 'security', 'possible bug', 'possible issue', 'performance', 'enhancement', 'best practice', 'maintainability', 'typo'. Other relevant labels are also acceptable.")
|
relevant_lines_end: int = Field(description="The relevant line number, from a '__new hunk__' section, where the suggestion ends (inclusive). Should be derived from the hunk line numbers, and correspond to the end of the 'existing code' snippet above")
|
||||||
{%- else %}
|
label: str = Field(description="A single, descriptive label that best characterizes the suggestion type. Possible labels include 'security', 'possible bug', 'possible issue', 'performance', 'enhancement', 'best practice', 'maintainability'. Other relevant labels are also acceptable.")
|
||||||
label: str = Field(description="A single, descriptive label that best characterizes the suggestion type. Possible labels include 'security', 'critical bug', 'general'. The 'general' section should be used for suggestions that address a major issue, but are necessarily on a critical level.")
|
|
||||||
{%- endif %}
|
|
||||||
|
|
||||||
|
|
||||||
class PRCodeSuggestions(BaseModel):
|
class PRCodeSuggestions(BaseModel):
|
||||||
@ -107,6 +96,8 @@ code_suggestions:
|
|||||||
...
|
...
|
||||||
one_sentence_summary: |
|
one_sentence_summary: |
|
||||||
...
|
...
|
||||||
|
relevant_lines_start: 12
|
||||||
|
relevant_lines_end: 13
|
||||||
label: |
|
label: |
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
@ -122,7 +113,7 @@ Title: '{{title}}'
|
|||||||
|
|
||||||
The PR Diff:
|
The PR Diff:
|
||||||
======
|
======
|
||||||
{{ diff_no_line_numbers|trim }}
|
{{ diff|trim }}
|
||||||
======
|
======
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@ Be particularly vigilant for suggestions that:
|
|||||||
- Contradict or ignore parts of the PR's modifications
|
- Contradict or ignore parts of the PR's modifications
|
||||||
In such cases, assign the suggestion a score of 0.
|
In such cases, assign the suggestion a score of 0.
|
||||||
|
|
||||||
Evaluate each valid suggestion by scoring its potential impact on the PR's correctness, quality and functionality.
|
For valid suggestions, your role is to provide an impartial and precise score assessment that accurately reflects each suggestion's potential impact on the PR's correctness, quality and functionality.
|
||||||
In addition, you should also detect the line numbers in the '__new hunk__' section that correspond to the 'existing_code' snippet.
|
|
||||||
|
|
||||||
Key guidelines for evaluation:
|
Key guidelines for evaluation:
|
||||||
- Thoroughly examine both the suggestion content and the corresponding PR code diff. Be vigilant for potential errors in each suggestion, ensuring they are logically sound, accurate, and directly derived from the PR code diff.
|
- Thoroughly examine both the suggestion content and the corresponding PR code diff. Be vigilant for potential errors in each suggestion, ensuring they are logically sound, accurate, and directly derived from the PR code diff.
|
||||||
@ -29,14 +29,6 @@ Key guidelines for evaluation:
|
|||||||
- Avoid inflating scores for suggestions that, while correct, offer only marginal improvements or optimizations.
|
- Avoid inflating scores for suggestions that, while correct, offer only marginal improvements or optimizations.
|
||||||
- Maintain the original order of suggestions in your feedback, corresponding to their input sequence.
|
- Maintain the original order of suggestions in your feedback, corresponding to their input sequence.
|
||||||
|
|
||||||
Additional scoring considerations:
|
|
||||||
- If the suggestion is not actionable, and only asks the user to verify or ensure a change, reduce its score by 1-2 points.
|
|
||||||
- Assign a score of 0 to suggestions aiming at:
|
|
||||||
- Adding docstring, type hints, or comments
|
|
||||||
- Remove unused imports or variables
|
|
||||||
- Using more specific exception types.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
The PR code diff will be presented in the following structured format:
|
The PR code diff will be presented in the following structured format:
|
||||||
======
|
======
|
||||||
@ -82,8 +74,6 @@ The output must be a YAML object equivalent to type $PRCodeSuggestionsFeedback,
|
|||||||
class CodeSuggestionFeedback(BaseModel):
|
class CodeSuggestionFeedback(BaseModel):
|
||||||
suggestion_summary: str = Field(description="Repeated from the input")
|
suggestion_summary: str = Field(description="Repeated from the input")
|
||||||
relevant_file: str = Field(description="Repeated from the input")
|
relevant_file: str = Field(description="Repeated from the input")
|
||||||
relevant_lines_start: int = Field(description="The relevant line number, from a '__new hunk__' section, where the suggestion starts (inclusive). Should be derived from the hunk line numbers, and correspond to the beginning of the relevant 'existing code' snippet")
|
|
||||||
relevant_lines_end: int = Field(description="The relevant line number, from a '__new hunk__' section, where the suggestion ends (inclusive). Should be derived from the hunk line numbers, and correspond to the end of the relevant 'existing code' snippet")
|
|
||||||
suggestion_score: int = Field(description="Evaluate the suggestion and assign a score from 0 to 10. Give 0 if the suggestion is wrong. For valid suggestions, score from 1 (lowest impact/importance) to 10 (highest impact/importance).")
|
suggestion_score: int = Field(description="Evaluate the suggestion and assign a score from 0 to 10. Give 0 if the suggestion is wrong. For valid suggestions, score from 1 (lowest impact/importance) to 10 (highest impact/importance).")
|
||||||
why: str = Field(description="Briefly explain the score given in 1-2 sentences, focusing on the suggestion's impact, relevance, and accuracy.")
|
why: str = Field(description="Briefly explain the score given in 1-2 sentences, focusing on the suggestion's impact, relevance, and accuracy.")
|
||||||
|
|
||||||
@ -98,8 +88,6 @@ code_suggestions:
|
|||||||
- suggestion_summary: |
|
- suggestion_summary: |
|
||||||
Use a more descriptive variable name here
|
Use a more descriptive variable name here
|
||||||
relevant_file: "src/file1.py"
|
relevant_file: "src/file1.py"
|
||||||
relevant_lines_start: 13
|
|
||||||
relevant_lines_end: 14
|
|
||||||
suggestion_score: 6
|
suggestion_score: 6
|
||||||
why: |
|
why: |
|
||||||
The variable name 't' is not descriptive enough
|
The variable name 't' is not descriptive enough
|
||||||
|
@ -78,9 +78,9 @@ pr_files:
|
|||||||
...
|
...
|
||||||
...
|
...
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
description: |
|
description: |-
|
||||||
...
|
...
|
||||||
title: |
|
title: |-
|
||||||
...
|
...
|
||||||
{%- if enable_custom_labels %}
|
{%- if enable_custom_labels %}
|
||||||
labels:
|
labels:
|
||||||
@ -94,26 +94,7 @@ labels:
|
|||||||
Answer should be a valid YAML, and nothing else. Each YAML output MUST be after a newline, with proper indent, and block scalar indicator ('|')
|
Answer should be a valid YAML, and nothing else. Each YAML output MUST be after a newline, with proper indent, and block scalar indicator ('|')
|
||||||
"""
|
"""
|
||||||
|
|
||||||
user="""
|
user="""PR Info:
|
||||||
{%- if related_tickets %}
|
|
||||||
Related Ticket Info:
|
|
||||||
{% for ticket in related_tickets %}
|
|
||||||
=====
|
|
||||||
Ticket Title: '{{ ticket.title }}'
|
|
||||||
{%- if ticket.labels %}
|
|
||||||
Ticket Labels: {{ ticket.labels }}
|
|
||||||
{%- endif %}
|
|
||||||
{%- if ticket.body %}
|
|
||||||
Ticket Description:
|
|
||||||
#####
|
|
||||||
{{ ticket.body }}
|
|
||||||
#####
|
|
||||||
{%- endif %}
|
|
||||||
=====
|
|
||||||
{% endfor %}
|
|
||||||
{%- endif %}
|
|
||||||
|
|
||||||
PR Info:
|
|
||||||
|
|
||||||
Previous title: '{{title}}'
|
Previous title: '{{title}}'
|
||||||
|
|
||||||
|
@ -1,24 +1,20 @@
|
|||||||
[pr_help_prompts]
|
[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").
|
system="""You are Doc-helper, a language models designed to answer questions about a documentation website for an open-soure project called "PR-Agent".
|
||||||
You will recieve a question, and the full documentation website content.
|
You will recieve a question, and a list of snippets that were collected for a documentation site using RAG as the retrieval method.
|
||||||
Your goal is to provide the best answer to the question using the documentation provided.
|
Your goal is to provide the best answer to the question using the snippets provided.
|
||||||
|
|
||||||
Additional instructions:
|
Additional instructions:
|
||||||
- Try to be short and concise in your answers. Try to give examples if needed.
|
- Try to be short and concise in your answers. 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.
|
- It is possible some of the snippets may not be relevant to the question. In that case, you should ignore them and focus on the ones that are relevant.
|
||||||
- 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.
|
- 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.
|
||||||
|
|
||||||
|
|
||||||
The output must be a YAML object equivalent to type $DocHelper, according to the following Pydantic definitions:
|
The output must be a YAML object equivalent to type $DocHelper, according to the following Pydantic definitions:
|
||||||
=====
|
=====
|
||||||
class relevant_section(BaseModel):
|
|
||||||
file_name: str = Field(description="The name of the relevant file")
|
|
||||||
relevant_section_header_string: str = Field(description="From the relevant file, exact text of the relevant section heading. If no markdown heading is relevant, return empty string")
|
|
||||||
|
|
||||||
class DocHelper(BaseModel):
|
class DocHelper(BaseModel):
|
||||||
user_question: str = Field(description="The user's question")
|
user_question: str = Field(description="The user's question")
|
||||||
response: str = Field(description="The response to the user's question")
|
response: str = Field(description="The response to the user's question")
|
||||||
relevant_sections: List[relevant_section] = Field(description="A list of the relevant markdown sections in the documentation that answer the user's question, ordered by importance (most relevant first)")
|
relevant_snippets: List[int] = Field(description="One-based index of the relevant snippets in the list of snippets provided. Order the by relevance, with the most relevant first. If a snippet was not relevant, do not include it in the list.")
|
||||||
=====
|
=====
|
||||||
|
|
||||||
|
|
||||||
@ -28,11 +24,10 @@ user_question: |
|
|||||||
...
|
...
|
||||||
response: |
|
response: |
|
||||||
...
|
...
|
||||||
relevant_sections:
|
relevant_snippets:
|
||||||
- file_name: "src/file1.py"
|
- 1
|
||||||
relevant_section_header_string: |
|
- 2
|
||||||
...
|
- 4
|
||||||
- ...
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
user="""\
|
user="""\
|
||||||
@ -42,7 +37,7 @@ User's Question:
|
|||||||
=====
|
=====
|
||||||
|
|
||||||
|
|
||||||
Documentation website content:
|
Relevant doc snippets retrieved:
|
||||||
=====
|
=====
|
||||||
{{ snippets|trim }}
|
{{ snippets|trim }}
|
||||||
=====
|
=====
|
||||||
|
@ -32,15 +32,16 @@ __old hunk__
|
|||||||
|
|
||||||
@@ ... @@ def func2():
|
@@ ... @@ def func2():
|
||||||
__new hunk__
|
__new hunk__
|
||||||
unchanged code line4
|
...
|
||||||
+new code line5 removed in the PR
|
__old hunk__
|
||||||
unchanged code line6
|
...
|
||||||
|
|
||||||
|
|
||||||
## File: 'src/file2.py'
|
## File: 'src/file2.py'
|
||||||
...
|
...
|
||||||
======
|
======
|
||||||
|
|
||||||
- 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.
|
- In this format, we separated each hunk of diff code to '__new hunk__' and '__old hunk__' sections. The '__new hunk__' section contains the new code of the chunk, and the '__old hunk__' section contains the old code, that was removed. If no new code was added in a specific hunk, '__new hunk__' section will not be presented. If no code was removed, '__old hunk__' section will not be presented.
|
||||||
- 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 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. \
|
- 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 '+')
|
||||||
@ -85,20 +86,7 @@ class KeyIssuesComponentLink(BaseModel):
|
|||||||
start_line: int = Field(description="The start line that corresponds to this issue in the relevant file")
|
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")
|
end_line: int = Field(description="The end line that corresponds to this issue in the relevant file")
|
||||||
|
|
||||||
{%- if related_tickets %}
|
|
||||||
|
|
||||||
class TicketCompliance(BaseModel):
|
|
||||||
ticket_url: str = Field(description="Ticket URL or ID")
|
|
||||||
ticket_requirements: str = Field(description="Repeat, in your own words, all ticket requirements, in bullet points")
|
|
||||||
fully_compliant_requirements: str = Field(description="A list, in bullet points, of which requirements are met by the PR code. Don't explain how the requirements are met, just list them shortly. Can be empty")
|
|
||||||
not_compliant_requirements: str = Field(description="A list, in bullet points, of which requirements are not met by the PR code. Don't explain how the requirements are not met, just list them shortly. Can be empty")
|
|
||||||
overall_compliance_level: str = Field(description="Overall give this PR one of these three values in relation to the ticket: 'Fully compliant', 'Partially compliant', or 'Not compliant'")
|
|
||||||
{%- endif %}
|
|
||||||
|
|
||||||
class Review(BaseModel):
|
class Review(BaseModel):
|
||||||
{%- if related_tickets %}
|
|
||||||
ticket_compliance_check: List[TicketCompliance] = Field(description="A list of compliance checks for the related tickets")
|
|
||||||
{%- endif %}
|
|
||||||
{%- if require_estimate_effort_to_review %}
|
{%- if require_estimate_effort_to_review %}
|
||||||
estimated_effort_to_review_[1-5]: int = Field(description="Estimate, on a scale of 1-5 (inclusive), the time and effort required to review this PR by an experienced and knowledgeable developer. 1 means short and easy review , 5 means long and hard review. Take into account the size, complexity, quality, and the needed changes of the PR code diff.")
|
estimated_effort_to_review_[1-5]: int = Field(description="Estimate, on a scale of 1-5 (inclusive), the time and effort required to review this PR by an experienced and knowledgeable developer. 1 means short and easy review , 5 means long and hard review. Take into account the size, complexity, quality, and the needed changes of the PR code diff.")
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
@ -143,19 +131,6 @@ class PRReview(BaseModel):
|
|||||||
Example output:
|
Example output:
|
||||||
```yaml
|
```yaml
|
||||||
review:
|
review:
|
||||||
{%- if related_tickets %}
|
|
||||||
ticket_compliance_check:
|
|
||||||
- ticket_url: |
|
|
||||||
...
|
|
||||||
ticket_requirements: |
|
|
||||||
...
|
|
||||||
fully_compliant_requirements: |
|
|
||||||
...
|
|
||||||
not_compliant_requirements: |
|
|
||||||
...
|
|
||||||
overall_compliance_level: |
|
|
||||||
...
|
|
||||||
{%- endif %}
|
|
||||||
{%- if require_estimate_effort_to_review %}
|
{%- if require_estimate_effort_to_review %}
|
||||||
estimated_effort_to_review_[1-5]: |
|
estimated_effort_to_review_[1-5]: |
|
||||||
3
|
3
|
||||||
@ -202,33 +177,7 @@ code_feedback:
|
|||||||
Answer should be a valid YAML, and nothing else. Each YAML output MUST be after a newline, with proper indent, and block scalar indicator ('|')
|
Answer should be a valid YAML, and nothing else. Each YAML output MUST be after a newline, with proper indent, and block scalar indicator ('|')
|
||||||
"""
|
"""
|
||||||
|
|
||||||
user="""
|
user="""--PR Info--
|
||||||
{%- if related_tickets %}
|
|
||||||
--PR Ticket Info--
|
|
||||||
{%- for ticket in related_tickets %}
|
|
||||||
=====
|
|
||||||
Ticket URL: '{{ ticket.ticket_url }}'
|
|
||||||
|
|
||||||
Ticket Title: '{{ ticket.title }}'
|
|
||||||
|
|
||||||
{%- if ticket.labels %}
|
|
||||||
|
|
||||||
Ticket Labels: {{ ticket.labels }}
|
|
||||||
|
|
||||||
{%- endif %}
|
|
||||||
{%- if ticket.body %}
|
|
||||||
|
|
||||||
Ticket Description:
|
|
||||||
#####
|
|
||||||
{{ ticket.body }}
|
|
||||||
#####
|
|
||||||
{%- endif %}
|
|
||||||
=====
|
|
||||||
{% endfor %}
|
|
||||||
{%- endif %}
|
|
||||||
|
|
||||||
|
|
||||||
--PR Info--
|
|
||||||
|
|
||||||
Title: '{{title}}'
|
Title: '{{title}}'
|
||||||
|
|
||||||
|
5
pr_agent/static_analysis/queries/Credits.md
Normal file
5
pr_agent/static_analysis/queries/Credits.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
# Credits
|
||||||
|
|
||||||
|
These queries, and some of the logic, were adopted from the excellent [Aider](https://github.com/paul-gauthier/aider/blob/main/aider/queries/README.md) project.
|
||||||
|
|
9
pr_agent/static_analysis/queries/tree-sitter-c-tags.scm
Normal file
9
pr_agent/static_analysis/queries/tree-sitter-c-tags.scm
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
(struct_specifier name: (type_identifier) @name.definition.class body:(_)) @definition.class
|
||||||
|
|
||||||
|
(declaration type: (union_specifier name: (type_identifier) @name.definition.class)) @definition.class
|
||||||
|
|
||||||
|
(function_declarator declarator: (identifier) @name.definition.function) @definition.function
|
||||||
|
|
||||||
|
(type_definition declarator: (type_identifier) @name.definition.type) @definition.type
|
||||||
|
|
||||||
|
(enum_specifier name: (type_identifier) @name.definition.type) @definition.type
|
@ -0,0 +1,46 @@
|
|||||||
|
(class_declaration
|
||||||
|
name: (identifier) @name.definition.class
|
||||||
|
) @definition.class
|
||||||
|
|
||||||
|
(class_declaration
|
||||||
|
bases: (base_list (_) @name.reference.class)
|
||||||
|
) @reference.class
|
||||||
|
|
||||||
|
(interface_declaration
|
||||||
|
name: (identifier) @name.definition.interface
|
||||||
|
) @definition.interface
|
||||||
|
|
||||||
|
(interface_declaration
|
||||||
|
bases: (base_list (_) @name.reference.interface)
|
||||||
|
) @reference.interface
|
||||||
|
|
||||||
|
(method_declaration
|
||||||
|
name: (identifier) @name.definition.method
|
||||||
|
) @definition.method
|
||||||
|
|
||||||
|
(object_creation_expression
|
||||||
|
type: (identifier) @name.reference.class
|
||||||
|
) @reference.class
|
||||||
|
|
||||||
|
(type_parameter_constraints_clause
|
||||||
|
target: (identifier) @name.reference.class
|
||||||
|
) @reference.class
|
||||||
|
|
||||||
|
(type_constraint
|
||||||
|
type: (identifier) @name.reference.class
|
||||||
|
) @reference.class
|
||||||
|
|
||||||
|
(variable_declaration
|
||||||
|
type: (identifier) @name.reference.class
|
||||||
|
) @reference.class
|
||||||
|
|
||||||
|
(invocation_expression
|
||||||
|
function:
|
||||||
|
(member_access_expression
|
||||||
|
name: (identifier) @name.reference.send
|
||||||
|
)
|
||||||
|
) @reference.send
|
||||||
|
|
||||||
|
(namespace_declaration
|
||||||
|
name: (identifier) @name.definition.module
|
||||||
|
) @definition.module
|
15
pr_agent/static_analysis/queries/tree-sitter-cpp-tags.scm
Normal file
15
pr_agent/static_analysis/queries/tree-sitter-cpp-tags.scm
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
(struct_specifier name: (type_identifier) @name.definition.class body:(_)) @definition.class
|
||||||
|
|
||||||
|
(declaration type: (union_specifier name: (type_identifier) @name.definition.class)) @definition.class
|
||||||
|
|
||||||
|
(function_declarator declarator: (identifier) @name.definition.function) @definition.function
|
||||||
|
|
||||||
|
(function_declarator declarator: (field_identifier) @name.definition.function) @definition.function
|
||||||
|
|
||||||
|
(function_declarator declarator: (qualified_identifier scope: (namespace_identifier) @scope name: (identifier) @name.definition.method)) @definition.method
|
||||||
|
|
||||||
|
(type_definition declarator: (type_identifier) @name.definition.type) @definition.type
|
||||||
|
|
||||||
|
(enum_specifier name: (type_identifier) @name.definition.type) @definition.type
|
||||||
|
|
||||||
|
(class_specifier name: (type_identifier) @name.definition.class) @definition.class
|
@ -0,0 +1,8 @@
|
|||||||
|
;; defun/defsubst
|
||||||
|
(function_definition name: (symbol) @name.definition.function) @definition.function
|
||||||
|
|
||||||
|
;; Treat macros as function definitions for the sake of TAGS.
|
||||||
|
(macro_definition name: (symbol) @name.definition.function) @definition.function
|
||||||
|
|
||||||
|
;; Match function calls
|
||||||
|
(list (symbol) @name.reference.function) @reference.function
|
54
pr_agent/static_analysis/queries/tree-sitter-elixir-tags.scm
Normal file
54
pr_agent/static_analysis/queries/tree-sitter-elixir-tags.scm
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
; Definitions
|
||||||
|
|
||||||
|
; * modules and protocols
|
||||||
|
(call
|
||||||
|
target: (identifier) @ignore
|
||||||
|
(arguments (alias) @name.definition.module)
|
||||||
|
(#match? @ignore "^(defmodule|defprotocol)$")) @definition.module
|
||||||
|
|
||||||
|
; * functions/macros
|
||||||
|
(call
|
||||||
|
target: (identifier) @ignore
|
||||||
|
(arguments
|
||||||
|
[
|
||||||
|
; zero-arity functions with no parentheses
|
||||||
|
(identifier) @name.definition.function
|
||||||
|
; regular function clause
|
||||||
|
(call target: (identifier) @name.definition.function)
|
||||||
|
; function clause with a guard clause
|
||||||
|
(binary_operator
|
||||||
|
left: (call target: (identifier) @name.definition.function)
|
||||||
|
operator: "when")
|
||||||
|
])
|
||||||
|
(#match? @ignore "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp)$")) @definition.function
|
||||||
|
|
||||||
|
; References
|
||||||
|
|
||||||
|
; ignore calls to kernel/special-forms keywords
|
||||||
|
(call
|
||||||
|
target: (identifier) @ignore
|
||||||
|
(#match? @ignore "^(def|defp|defdelegate|defguard|defguardp|defmacro|defmacrop|defn|defnp|defmodule|defprotocol|defimpl|defstruct|defexception|defoverridable|alias|case|cond|else|for|if|import|quote|raise|receive|require|reraise|super|throw|try|unless|unquote|unquote_splicing|use|with)$"))
|
||||||
|
|
||||||
|
; ignore module attributes
|
||||||
|
(unary_operator
|
||||||
|
operator: "@"
|
||||||
|
operand: (call
|
||||||
|
target: (identifier) @ignore))
|
||||||
|
|
||||||
|
; * function call
|
||||||
|
(call
|
||||||
|
target: [
|
||||||
|
; local
|
||||||
|
(identifier) @name.reference.call
|
||||||
|
; remote
|
||||||
|
(dot
|
||||||
|
right: (identifier) @name.reference.call)
|
||||||
|
]) @reference.call
|
||||||
|
|
||||||
|
; * pipe into function call
|
||||||
|
(binary_operator
|
||||||
|
operator: "|>"
|
||||||
|
right: (identifier) @name.reference.call) @reference.call
|
||||||
|
|
||||||
|
; * modules
|
||||||
|
(alias) @name.reference.module @reference.module
|
19
pr_agent/static_analysis/queries/tree-sitter-elm-tags.scm
Normal file
19
pr_agent/static_analysis/queries/tree-sitter-elm-tags.scm
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
(value_declaration (function_declaration_left (lower_case_identifier) @name.definition.function)) @definition.function
|
||||||
|
|
||||||
|
(function_call_expr (value_expr (value_qid) @name.reference.function)) @reference.function
|
||||||
|
(exposed_value (lower_case_identifier) @name.reference.function) @reference.function
|
||||||
|
(type_annotation ((lower_case_identifier) @name.reference.function) (colon)) @reference.function
|
||||||
|
|
||||||
|
(type_declaration ((upper_case_identifier) @name.definition.type)) @definition.type
|
||||||
|
|
||||||
|
(type_ref (upper_case_qid (upper_case_identifier) @name.reference.type)) @reference.type
|
||||||
|
(exposed_type (upper_case_identifier) @name.reference.type) @reference.type
|
||||||
|
|
||||||
|
(type_declaration (union_variant (upper_case_identifier) @name.definition.union)) @definition.union
|
||||||
|
|
||||||
|
(value_expr (upper_case_qid (upper_case_identifier) @name.reference.union)) @reference.union
|
||||||
|
|
||||||
|
|
||||||
|
(module_declaration
|
||||||
|
(upper_case_qid (upper_case_identifier)) @name.definition.module
|
||||||
|
) @definition.module
|
30
pr_agent/static_analysis/queries/tree-sitter-go-tags.scm
Normal file
30
pr_agent/static_analysis/queries/tree-sitter-go-tags.scm
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
(
|
||||||
|
(comment)* @doc
|
||||||
|
.
|
||||||
|
(function_declaration
|
||||||
|
name: (identifier) @name.definition.function) @definition.function
|
||||||
|
(#strip! @doc "^//\\s*")
|
||||||
|
(#set-adjacent! @doc @definition.function)
|
||||||
|
)
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)* @doc
|
||||||
|
.
|
||||||
|
(method_declaration
|
||||||
|
name: (field_identifier) @name.definition.method) @definition.method
|
||||||
|
(#strip! @doc "^//\\s*")
|
||||||
|
(#set-adjacent! @doc @definition.method)
|
||||||
|
)
|
||||||
|
|
||||||
|
(call_expression
|
||||||
|
function: [
|
||||||
|
(identifier) @name.reference.call
|
||||||
|
(parenthesized_expression (identifier) @name.reference.call)
|
||||||
|
(selector_expression field: (field_identifier) @name.reference.call)
|
||||||
|
(parenthesized_expression (selector_expression field: (field_identifier) @name.reference.call))
|
||||||
|
]) @reference.call
|
||||||
|
|
||||||
|
(type_spec
|
||||||
|
name: (type_identifier) @name.definition.type) @definition.type
|
||||||
|
|
||||||
|
(type_identifier) @name.reference.type @reference.type
|
20
pr_agent/static_analysis/queries/tree-sitter-java-tags.scm
Normal file
20
pr_agent/static_analysis/queries/tree-sitter-java-tags.scm
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
(class_declaration
|
||||||
|
name: (identifier) @name.definition.class) @definition.class
|
||||||
|
|
||||||
|
(method_declaration
|
||||||
|
name: (identifier) @name.definition.method) @definition.method
|
||||||
|
|
||||||
|
(method_invocation
|
||||||
|
name: (identifier) @name.reference.call
|
||||||
|
arguments: (argument_list) @reference.call)
|
||||||
|
|
||||||
|
(interface_declaration
|
||||||
|
name: (identifier) @name.definition.interface) @definition.interface
|
||||||
|
|
||||||
|
(type_list
|
||||||
|
(type_identifier) @name.reference.implementation) @reference.implementation
|
||||||
|
|
||||||
|
(object_creation_expression
|
||||||
|
type: (type_identifier) @name.reference.class) @reference.class
|
||||||
|
|
||||||
|
(superclass (type_identifier) @name.reference.class) @reference.class
|
@ -0,0 +1,88 @@
|
|||||||
|
(
|
||||||
|
(comment)* @doc
|
||||||
|
.
|
||||||
|
(method_definition
|
||||||
|
name: (property_identifier) @name.definition.method) @definition.method
|
||||||
|
(#not-eq? @name.definition.method "constructor")
|
||||||
|
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
|
||||||
|
(#select-adjacent! @doc @definition.method)
|
||||||
|
)
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)* @doc
|
||||||
|
.
|
||||||
|
[
|
||||||
|
(class
|
||||||
|
name: (_) @name.definition.class)
|
||||||
|
(class_declaration
|
||||||
|
name: (_) @name.definition.class)
|
||||||
|
] @definition.class
|
||||||
|
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
|
||||||
|
(#select-adjacent! @doc @definition.class)
|
||||||
|
)
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)* @doc
|
||||||
|
.
|
||||||
|
[
|
||||||
|
(function
|
||||||
|
name: (identifier) @name.definition.function)
|
||||||
|
(function_declaration
|
||||||
|
name: (identifier) @name.definition.function)
|
||||||
|
(generator_function
|
||||||
|
name: (identifier) @name.definition.function)
|
||||||
|
(generator_function_declaration
|
||||||
|
name: (identifier) @name.definition.function)
|
||||||
|
] @definition.function
|
||||||
|
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
|
||||||
|
(#select-adjacent! @doc @definition.function)
|
||||||
|
)
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)* @doc
|
||||||
|
.
|
||||||
|
(lexical_declaration
|
||||||
|
(variable_declarator
|
||||||
|
name: (identifier) @name.definition.function
|
||||||
|
value: [(arrow_function) (function)]) @definition.function)
|
||||||
|
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
|
||||||
|
(#select-adjacent! @doc @definition.function)
|
||||||
|
)
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)* @doc
|
||||||
|
.
|
||||||
|
(variable_declaration
|
||||||
|
(variable_declarator
|
||||||
|
name: (identifier) @name.definition.function
|
||||||
|
value: [(arrow_function) (function)]) @definition.function)
|
||||||
|
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
|
||||||
|
(#select-adjacent! @doc @definition.function)
|
||||||
|
)
|
||||||
|
|
||||||
|
(assignment_expression
|
||||||
|
left: [
|
||||||
|
(identifier) @name.definition.function
|
||||||
|
(member_expression
|
||||||
|
property: (property_identifier) @name.definition.function)
|
||||||
|
]
|
||||||
|
right: [(arrow_function) (function)]
|
||||||
|
) @definition.function
|
||||||
|
|
||||||
|
(pair
|
||||||
|
key: (property_identifier) @name.definition.function
|
||||||
|
value: [(arrow_function) (function)]) @definition.function
|
||||||
|
|
||||||
|
(
|
||||||
|
(call_expression
|
||||||
|
function: (identifier) @name.reference.call) @reference.call
|
||||||
|
(#not-match? @name.reference.call "^(require)$")
|
||||||
|
)
|
||||||
|
|
||||||
|
(call_expression
|
||||||
|
function: (member_expression
|
||||||
|
property: (property_identifier) @name.reference.call)
|
||||||
|
arguments: (_) @reference.call)
|
||||||
|
|
||||||
|
(new_expression
|
||||||
|
constructor: (_) @name.reference.class) @reference.class
|
115
pr_agent/static_analysis/queries/tree-sitter-ocaml-tags.scm
Normal file
115
pr_agent/static_analysis/queries/tree-sitter-ocaml-tags.scm
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
; Modules
|
||||||
|
;--------
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)? @doc .
|
||||||
|
(module_definition (module_binding (module_name) @name.definition.module) @definition.module)
|
||||||
|
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||||
|
)
|
||||||
|
|
||||||
|
(module_path (module_name) @name.reference.module) @reference.module
|
||||||
|
|
||||||
|
; Module types
|
||||||
|
;--------------
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)? @doc .
|
||||||
|
(module_type_definition (module_type_name) @name.definition.interface) @definition.interface
|
||||||
|
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||||
|
)
|
||||||
|
|
||||||
|
(module_type_path (module_type_name) @name.reference.implementation) @reference.implementation
|
||||||
|
|
||||||
|
; Functions
|
||||||
|
;----------
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)? @doc .
|
||||||
|
(value_definition
|
||||||
|
[
|
||||||
|
(let_binding
|
||||||
|
pattern: (value_name) @name.definition.function
|
||||||
|
(parameter))
|
||||||
|
(let_binding
|
||||||
|
pattern: (value_name) @name.definition.function
|
||||||
|
body: [(fun_expression) (function_expression)])
|
||||||
|
] @definition.function
|
||||||
|
)
|
||||||
|
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||||
|
)
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)? @doc .
|
||||||
|
(external (value_name) @name.definition.function) @definition.function
|
||||||
|
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||||
|
)
|
||||||
|
|
||||||
|
(application_expression
|
||||||
|
function: (value_path (value_name) @name.reference.call)) @reference.call
|
||||||
|
|
||||||
|
(infix_expression
|
||||||
|
left: (value_path (value_name) @name.reference.call)
|
||||||
|
operator: (concat_operator) @reference.call
|
||||||
|
(#eq? @reference.call "@@"))
|
||||||
|
|
||||||
|
(infix_expression
|
||||||
|
operator: (rel_operator) @reference.call
|
||||||
|
right: (value_path (value_name) @name.reference.call)
|
||||||
|
(#eq? @reference.call "|>"))
|
||||||
|
|
||||||
|
; Operator
|
||||||
|
;---------
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)? @doc .
|
||||||
|
(value_definition
|
||||||
|
(let_binding
|
||||||
|
pattern: (parenthesized_operator (_) @name.definition.function)) @definition.function)
|
||||||
|
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||||
|
)
|
||||||
|
|
||||||
|
[
|
||||||
|
(prefix_operator)
|
||||||
|
(sign_operator)
|
||||||
|
(pow_operator)
|
||||||
|
(mult_operator)
|
||||||
|
(add_operator)
|
||||||
|
(concat_operator)
|
||||||
|
(rel_operator)
|
||||||
|
(and_operator)
|
||||||
|
(or_operator)
|
||||||
|
(assign_operator)
|
||||||
|
(hash_operator)
|
||||||
|
(indexing_operator)
|
||||||
|
(let_operator)
|
||||||
|
(let_and_operator)
|
||||||
|
(match_operator)
|
||||||
|
] @name.reference.call @reference.call
|
||||||
|
|
||||||
|
; Classes
|
||||||
|
;--------
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)? @doc .
|
||||||
|
[
|
||||||
|
(class_definition (class_binding (class_name) @name.definition.class) @definition.class)
|
||||||
|
(class_type_definition (class_type_binding (class_type_name) @name.definition.class) @definition.class)
|
||||||
|
]
|
||||||
|
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||||
|
)
|
||||||
|
|
||||||
|
[
|
||||||
|
(class_path (class_name) @name.reference.class)
|
||||||
|
(class_type_path (class_type_name) @name.reference.class)
|
||||||
|
] @reference.class
|
||||||
|
|
||||||
|
; Methods
|
||||||
|
;--------
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)? @doc .
|
||||||
|
(method_definition (method_name) @name.definition.method) @definition.method
|
||||||
|
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||||
|
)
|
||||||
|
|
||||||
|
(method_invocation (method_name) @name.reference.call) @reference.call
|
26
pr_agent/static_analysis/queries/tree-sitter-php-tags.scm
Normal file
26
pr_agent/static_analysis/queries/tree-sitter-php-tags.scm
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
(class_declaration
|
||||||
|
name: (name) @name.definition.class) @definition.class
|
||||||
|
|
||||||
|
(function_definition
|
||||||
|
name: (name) @name.definition.function) @definition.function
|
||||||
|
|
||||||
|
(method_declaration
|
||||||
|
name: (name) @name.definition.function) @definition.function
|
||||||
|
|
||||||
|
(object_creation_expression
|
||||||
|
[
|
||||||
|
(qualified_name (name) @name.reference.class)
|
||||||
|
(variable_name (name) @name.reference.class)
|
||||||
|
]) @reference.class
|
||||||
|
|
||||||
|
(function_call_expression
|
||||||
|
function: [
|
||||||
|
(qualified_name (name) @name.reference.call)
|
||||||
|
(variable_name (name)) @name.reference.call
|
||||||
|
]) @reference.call
|
||||||
|
|
||||||
|
(scoped_call_expression
|
||||||
|
name: (name) @name.reference.call) @reference.call
|
||||||
|
|
||||||
|
(member_call_expression
|
||||||
|
name: (name) @name.reference.call) @reference.call
|
12
pr_agent/static_analysis/queries/tree-sitter-python-tags.scm
Normal file
12
pr_agent/static_analysis/queries/tree-sitter-python-tags.scm
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
(class_definition
|
||||||
|
name: (identifier) @name.definition.class) @definition.class
|
||||||
|
|
||||||
|
(function_definition
|
||||||
|
name: (identifier) @name.definition.function) @definition.function
|
||||||
|
|
||||||
|
(call
|
||||||
|
function: [
|
||||||
|
(identifier) @name.reference.call
|
||||||
|
(attribute
|
||||||
|
attribute: (identifier) @name.reference.call)
|
||||||
|
]) @reference.call
|
26
pr_agent/static_analysis/queries/tree-sitter-ql-tags.scm
Normal file
26
pr_agent/static_analysis/queries/tree-sitter-ql-tags.scm
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
(classlessPredicate
|
||||||
|
name: (predicateName) @name.definition.function) @definition.function
|
||||||
|
|
||||||
|
(memberPredicate
|
||||||
|
name: (predicateName) @name.definition.method) @definition.method
|
||||||
|
|
||||||
|
(aritylessPredicateExpr
|
||||||
|
name: (literalId) @name.reference.call) @reference.call
|
||||||
|
|
||||||
|
(module
|
||||||
|
name: (moduleName) @name.definition.module) @definition.module
|
||||||
|
|
||||||
|
(dataclass
|
||||||
|
name: (className) @name.definition.class) @definition.class
|
||||||
|
|
||||||
|
(datatype
|
||||||
|
name: (className) @name.definition.class) @definition.class
|
||||||
|
|
||||||
|
(datatypeBranch
|
||||||
|
name: (className) @name.definition.class) @definition.class
|
||||||
|
|
||||||
|
(qualifiedRhs
|
||||||
|
name: (predicateName) @name.reference.call) @reference.call
|
||||||
|
|
||||||
|
(typeExpr
|
||||||
|
name: (className) @name.reference.type) @reference.type
|
64
pr_agent/static_analysis/queries/tree-sitter-ruby-tags.scm
Normal file
64
pr_agent/static_analysis/queries/tree-sitter-ruby-tags.scm
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
; Method definitions
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)* @doc
|
||||||
|
.
|
||||||
|
[
|
||||||
|
(method
|
||||||
|
name: (_) @name.definition.method) @definition.method
|
||||||
|
(singleton_method
|
||||||
|
name: (_) @name.definition.method) @definition.method
|
||||||
|
]
|
||||||
|
(#strip! @doc "^#\\s*")
|
||||||
|
(#select-adjacent! @doc @definition.method)
|
||||||
|
)
|
||||||
|
|
||||||
|
(alias
|
||||||
|
name: (_) @name.definition.method) @definition.method
|
||||||
|
|
||||||
|
(setter
|
||||||
|
(identifier) @ignore)
|
||||||
|
|
||||||
|
; Class definitions
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)* @doc
|
||||||
|
.
|
||||||
|
[
|
||||||
|
(class
|
||||||
|
name: [
|
||||||
|
(constant) @name.definition.class
|
||||||
|
(scope_resolution
|
||||||
|
name: (_) @name.definition.class)
|
||||||
|
]) @definition.class
|
||||||
|
(singleton_class
|
||||||
|
value: [
|
||||||
|
(constant) @name.definition.class
|
||||||
|
(scope_resolution
|
||||||
|
name: (_) @name.definition.class)
|
||||||
|
]) @definition.class
|
||||||
|
]
|
||||||
|
(#strip! @doc "^#\\s*")
|
||||||
|
(#select-adjacent! @doc @definition.class)
|
||||||
|
)
|
||||||
|
|
||||||
|
; Module definitions
|
||||||
|
|
||||||
|
(
|
||||||
|
(module
|
||||||
|
name: [
|
||||||
|
(constant) @name.definition.module
|
||||||
|
(scope_resolution
|
||||||
|
name: (_) @name.definition.module)
|
||||||
|
]) @definition.module
|
||||||
|
)
|
||||||
|
|
||||||
|
; Calls
|
||||||
|
|
||||||
|
(call method: (identifier) @name.reference.call) @reference.call
|
||||||
|
|
||||||
|
(
|
||||||
|
[(identifier) (constant)] @name.reference.call @reference.call
|
||||||
|
(#is-not? local)
|
||||||
|
(#not-match? @name.reference.call "^(lambda|load|require|require_relative|__FILE__|__LINE__)$")
|
||||||
|
)
|
60
pr_agent/static_analysis/queries/tree-sitter-rust-tags.scm
Normal file
60
pr_agent/static_analysis/queries/tree-sitter-rust-tags.scm
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
; ADT definitions
|
||||||
|
|
||||||
|
(struct_item
|
||||||
|
name: (type_identifier) @name.definition.class) @definition.class
|
||||||
|
|
||||||
|
(enum_item
|
||||||
|
name: (type_identifier) @name.definition.class) @definition.class
|
||||||
|
|
||||||
|
(union_item
|
||||||
|
name: (type_identifier) @name.definition.class) @definition.class
|
||||||
|
|
||||||
|
; type aliases
|
||||||
|
|
||||||
|
(type_item
|
||||||
|
name: (type_identifier) @name.definition.class) @definition.class
|
||||||
|
|
||||||
|
; method definitions
|
||||||
|
|
||||||
|
(declaration_list
|
||||||
|
(function_item
|
||||||
|
name: (identifier) @name.definition.method)) @definition.method
|
||||||
|
|
||||||
|
; function definitions
|
||||||
|
|
||||||
|
(function_item
|
||||||
|
name: (identifier) @name.definition.function) @definition.function
|
||||||
|
|
||||||
|
; trait definitions
|
||||||
|
(trait_item
|
||||||
|
name: (type_identifier) @name.definition.interface) @definition.interface
|
||||||
|
|
||||||
|
; module definitions
|
||||||
|
(mod_item
|
||||||
|
name: (identifier) @name.definition.module) @definition.module
|
||||||
|
|
||||||
|
; macro definitions
|
||||||
|
|
||||||
|
(macro_definition
|
||||||
|
name: (identifier) @name.definition.macro) @definition.macro
|
||||||
|
|
||||||
|
; references
|
||||||
|
|
||||||
|
(call_expression
|
||||||
|
function: (identifier) @name.reference.call) @reference.call
|
||||||
|
|
||||||
|
(call_expression
|
||||||
|
function: (field_expression
|
||||||
|
field: (field_identifier) @name.reference.call)) @reference.call
|
||||||
|
|
||||||
|
(macro_invocation
|
||||||
|
macro: (identifier) @name.reference.call) @reference.call
|
||||||
|
|
||||||
|
; implementations
|
||||||
|
|
||||||
|
(impl_item
|
||||||
|
trait: (type_identifier) @name.reference.implementation) @reference.implementation
|
||||||
|
|
||||||
|
(impl_item
|
||||||
|
type: (type_identifier) @name.reference.implementation
|
||||||
|
!trait) @reference.implementation
|
@ -0,0 +1,41 @@
|
|||||||
|
(function_signature
|
||||||
|
name: (identifier) @name.definition.function) @definition.function
|
||||||
|
|
||||||
|
(method_signature
|
||||||
|
name: (property_identifier) @name.definition.method) @definition.method
|
||||||
|
|
||||||
|
(abstract_method_signature
|
||||||
|
name: (property_identifier) @name.definition.method) @definition.method
|
||||||
|
|
||||||
|
(abstract_class_declaration
|
||||||
|
name: (type_identifier) @name.definition.class) @definition.class
|
||||||
|
|
||||||
|
(module
|
||||||
|
name: (identifier) @name.definition.module) @definition.module
|
||||||
|
|
||||||
|
(interface_declaration
|
||||||
|
name: (type_identifier) @name.definition.interface) @definition.interface
|
||||||
|
|
||||||
|
(type_annotation
|
||||||
|
(type_identifier) @name.reference.type) @reference.type
|
||||||
|
|
||||||
|
(new_expression
|
||||||
|
constructor: (identifier) @name.reference.class) @reference.class
|
||||||
|
|
||||||
|
(function_declaration
|
||||||
|
name: (identifier) @name.definition.function) @definition.function
|
||||||
|
|
||||||
|
(method_definition
|
||||||
|
name: (property_identifier) @name.definition.method) @definition.method
|
||||||
|
|
||||||
|
(class_declaration
|
||||||
|
name: (type_identifier) @name.definition.class) @definition.class
|
||||||
|
|
||||||
|
(interface_declaration
|
||||||
|
name: (type_identifier) @name.definition.class) @definition.class
|
||||||
|
|
||||||
|
(type_alias_declaration
|
||||||
|
name: (type_identifier) @name.definition.type) @definition.type
|
||||||
|
|
||||||
|
(enum_declaration
|
||||||
|
name: (identifier) @name.definition.enum) @definition.enum
|
150
pr_agent/static_analysis/src/file_summary.py
Normal file
150
pr_agent/static_analysis/src/file_summary.py
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from grep_ast import TreeContext
|
||||||
|
from grep_ast.parsers import PARSERS
|
||||||
|
# from pygments.lexers import guess_lexer_for_filename
|
||||||
|
# from pygments.token import Token
|
||||||
|
from tree_sitter_languages import get_language, get_parser
|
||||||
|
|
||||||
|
|
||||||
|
def filename_to_lang(filename):
|
||||||
|
file_extension = os.path.splitext(filename)[1]
|
||||||
|
lang = PARSERS.get(file_extension)
|
||||||
|
return lang
|
||||||
|
|
||||||
|
class FileSummary:
|
||||||
|
"""
|
||||||
|
This class is used to summarize the content of a file using tree-sitter queries.
|
||||||
|
Supported languages: C, C++, C#, elisp, elixir, go, java, javascript, ocaml, php, python, ql, ruby, rust, typescript
|
||||||
|
"""
|
||||||
|
def __init__(self, fname_full_path: str, project_base_path, parent_context=True, child_context=False, header_max=0):
|
||||||
|
self.fname_full_path = fname_full_path
|
||||||
|
self.project_base_path = project_base_path
|
||||||
|
self.fname_rel = os.path.relpath(fname_full_path, project_base_path)
|
||||||
|
self.main_queries_path = Path(__file__).parent.parent / 'queries'
|
||||||
|
if not os.path.exists(fname_full_path):
|
||||||
|
print(f"File {fname_full_path} does not exist")
|
||||||
|
with open(fname_full_path, "r") as f:
|
||||||
|
code = f.read()
|
||||||
|
self.code = code.rstrip("\n") + "\n"
|
||||||
|
self.parent_context = parent_context
|
||||||
|
self.child_context = child_context
|
||||||
|
self.header_max = header_max
|
||||||
|
|
||||||
|
def summarize(self):
|
||||||
|
query_results = self.get_query_results()
|
||||||
|
summary_str = self.query_processing(query_results)
|
||||||
|
return summary_str
|
||||||
|
|
||||||
|
def render_file_summary(self, lines_of_interest: list):
|
||||||
|
code = self.code
|
||||||
|
fname_rel = self.fname_rel
|
||||||
|
context = TreeContext(
|
||||||
|
fname_rel,
|
||||||
|
code,
|
||||||
|
color=False,
|
||||||
|
line_number=True, # number the lines (1-indexed)
|
||||||
|
parent_context=self.parent_context,
|
||||||
|
child_context=self.child_context,
|
||||||
|
last_line=False,
|
||||||
|
margin=0,
|
||||||
|
mark_lois=False,
|
||||||
|
loi_pad=0,
|
||||||
|
header_max=self.header_max, # max number of lines to show in a function header
|
||||||
|
show_top_of_file_parent_scope=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
context.lines_of_interest = set()
|
||||||
|
context.add_lines_of_interest(lines_of_interest)
|
||||||
|
context.add_context()
|
||||||
|
res = context.format()
|
||||||
|
return res
|
||||||
|
|
||||||
|
def query_processing(self, query_results: list):
|
||||||
|
if not query_results:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
output = ""
|
||||||
|
def_lines = [q['line'] for q in query_results if q['kind'] == "def"]
|
||||||
|
output += "\n"
|
||||||
|
output += query_results[0]['fname'] + ":\n"
|
||||||
|
output += self.render_file_summary(def_lines)
|
||||||
|
return output
|
||||||
|
|
||||||
|
def get_queries_scheme(self, lang) -> str:
|
||||||
|
try:
|
||||||
|
# Load the relevant queries
|
||||||
|
path = os.path.join(self.main_queries_path, f"tree-sitter-{lang}-tags.scm")
|
||||||
|
with open(path, "r") as f:
|
||||||
|
return f.read()
|
||||||
|
except KeyError:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def get_query_results(self):
|
||||||
|
fname_rel = self.fname_rel
|
||||||
|
code = self.code
|
||||||
|
lang = filename_to_lang(fname_rel)
|
||||||
|
if not lang:
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
language = get_language(lang)
|
||||||
|
parser = get_parser(lang)
|
||||||
|
except Exception as err:
|
||||||
|
print(f"Skipping file {fname_rel}: {err}")
|
||||||
|
return
|
||||||
|
|
||||||
|
query_scheme_str = self.get_queries_scheme(lang)
|
||||||
|
tree = parser.parse(bytes(code, "utf-8"))
|
||||||
|
|
||||||
|
# Run the queries
|
||||||
|
query = language.query(query_scheme_str)
|
||||||
|
captures = list(query.captures(tree.root_node))
|
||||||
|
|
||||||
|
# Parse the results into a list of "def" and "ref" tags
|
||||||
|
visited_set = set()
|
||||||
|
results = []
|
||||||
|
for node, tag in captures:
|
||||||
|
if tag.startswith("name.definition."):
|
||||||
|
kind = "def"
|
||||||
|
elif tag.startswith("name.reference."):
|
||||||
|
kind = "ref"
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
|
visited_set.add(kind)
|
||||||
|
result = dict(
|
||||||
|
fname=fname_rel,
|
||||||
|
name=node.text.decode("utf-8"),
|
||||||
|
kind=kind,
|
||||||
|
line=node.start_point[0],
|
||||||
|
)
|
||||||
|
results.append(result)
|
||||||
|
|
||||||
|
if "ref" in visited_set:
|
||||||
|
return results
|
||||||
|
if "def" not in visited_set:
|
||||||
|
return results
|
||||||
|
|
||||||
|
## currently we are interested only in defs
|
||||||
|
# # We saw defs, without any refs
|
||||||
|
# # Some files only provide defs (cpp, for example)
|
||||||
|
# # Use pygments to backfill refs
|
||||||
|
# try:
|
||||||
|
# lexer = guess_lexer_for_filename(fname, code)
|
||||||
|
# except Exception:
|
||||||
|
# return
|
||||||
|
#
|
||||||
|
# tokens = list(lexer.get_tokens(code))
|
||||||
|
# tokens = [token[1] for token in tokens if token[0] in Token.Name]
|
||||||
|
#
|
||||||
|
# for t in tokens:
|
||||||
|
# result = dict(
|
||||||
|
# fname=fname,
|
||||||
|
# name=t,
|
||||||
|
# kind="ref",
|
||||||
|
# line=-1,
|
||||||
|
# )
|
||||||
|
# results.append(result)
|
||||||
|
return results
|
428
pr_agent/static_analysis/tests/example_files/AES.cpp
Normal file
428
pr_agent/static_analysis/tests/example_files/AES.cpp
Normal file
@ -0,0 +1,428 @@
|
|||||||
|
// Taken from 'https://github.com/dolphin-emu/dolphin'
|
||||||
|
// Copyright 2017 Dolphin Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <bit>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include <mbedtls/aes.h>
|
||||||
|
|
||||||
|
#include "Common/Assert.h"
|
||||||
|
#include "Common/CPUDetect.h"
|
||||||
|
#include "Common/Crypto/AES.h"
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#include <intrin.h>
|
||||||
|
#else
|
||||||
|
#if defined(_M_X86_64)
|
||||||
|
#include <x86intrin.h>
|
||||||
|
#elif defined(_M_ARM_64)
|
||||||
|
#include <arm_acle.h>
|
||||||
|
#include <arm_neon.h>
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define ATTRIBUTE_TARGET(x)
|
||||||
|
#else
|
||||||
|
#define ATTRIBUTE_TARGET(x) [[gnu::target(x)]]
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace Common::AES
|
||||||
|
{
|
||||||
|
// For x64 and arm64, it's very unlikely a user's cpu does not support the accelerated version,
|
||||||
|
// fallback is just in case.
|
||||||
|
template <Mode AesMode>
|
||||||
|
class ContextGeneric final : public Context
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ContextGeneric(const u8* key)
|
||||||
|
{
|
||||||
|
mbedtls_aes_init(&ctx);
|
||||||
|
if constexpr (AesMode == Mode::Encrypt)
|
||||||
|
ASSERT(!mbedtls_aes_setkey_enc(&ctx, key, 128));
|
||||||
|
else
|
||||||
|
ASSERT(!mbedtls_aes_setkey_dec(&ctx, key, 128));
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool Crypt(const u8* iv, u8* iv_out, const u8* buf_in, u8* buf_out,
|
||||||
|
size_t len) const override
|
||||||
|
{
|
||||||
|
std::array<u8, BLOCK_SIZE> iv_tmp{};
|
||||||
|
if (iv)
|
||||||
|
std::memcpy(&iv_tmp[0], iv, BLOCK_SIZE);
|
||||||
|
|
||||||
|
constexpr int mode = (AesMode == Mode::Encrypt) ? MBEDTLS_AES_ENCRYPT : MBEDTLS_AES_DECRYPT;
|
||||||
|
if (mbedtls_aes_crypt_cbc(const_cast<mbedtls_aes_context*>(&ctx), mode, len, &iv_tmp[0], buf_in,
|
||||||
|
buf_out))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (iv_out)
|
||||||
|
std::memcpy(iv_out, &iv_tmp[0], BLOCK_SIZE);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
mbedtls_aes_context ctx{};
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined(_M_X86_64)
|
||||||
|
|
||||||
|
// Note that (for instructions with same data width) the actual instructions emitted vary depending
|
||||||
|
// on compiler and flags. The naming is somewhat confusing, because VAES cpuid flag was added after
|
||||||
|
// VAES(VEX.128):
|
||||||
|
// clang-format off
|
||||||
|
// instructions | cpuid flag | #define
|
||||||
|
// AES(128) | AES | -
|
||||||
|
// VAES(VEX.128) | AES & AVX | __AVX__
|
||||||
|
// VAES(VEX.256) | VAES | -
|
||||||
|
// VAES(EVEX.128) | VAES & AVX512VL | __AVX512VL__
|
||||||
|
// VAES(EVEX.256) | VAES & AVX512VL | __AVX512VL__
|
||||||
|
// VAES(EVEX.512) | VAES & AVX512F | __AVX512F__
|
||||||
|
// clang-format on
|
||||||
|
template <Mode AesMode>
|
||||||
|
class ContextAESNI final : public Context
|
||||||
|
{
|
||||||
|
static inline __m128i Aes128KeygenAssistFinish(__m128i key, __m128i kga)
|
||||||
|
{
|
||||||
|
__m128i tmp = _mm_shuffle_epi32(kga, _MM_SHUFFLE(3, 3, 3, 3));
|
||||||
|
tmp = _mm_xor_si128(tmp, key);
|
||||||
|
|
||||||
|
key = _mm_slli_si128(key, 4);
|
||||||
|
tmp = _mm_xor_si128(tmp, key);
|
||||||
|
key = _mm_slli_si128(key, 4);
|
||||||
|
tmp = _mm_xor_si128(tmp, key);
|
||||||
|
key = _mm_slli_si128(key, 4);
|
||||||
|
tmp = _mm_xor_si128(tmp, key);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t RoundIdx>
|
||||||
|
ATTRIBUTE_TARGET("aes")
|
||||||
|
inline constexpr void StoreRoundKey(__m128i rk)
|
||||||
|
{
|
||||||
|
if constexpr (AesMode == Mode::Encrypt)
|
||||||
|
round_keys[RoundIdx] = rk;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
constexpr size_t idx = NUM_ROUND_KEYS - RoundIdx - 1;
|
||||||
|
if constexpr (idx == 0 || idx == NUM_ROUND_KEYS - 1)
|
||||||
|
round_keys[idx] = rk;
|
||||||
|
else
|
||||||
|
round_keys[idx] = _mm_aesimc_si128(rk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <size_t RoundIdx, int Rcon>
|
||||||
|
ATTRIBUTE_TARGET("aes")
|
||||||
|
inline constexpr __m128i Aes128Keygen(__m128i rk)
|
||||||
|
{
|
||||||
|
rk = Aes128KeygenAssistFinish(rk, _mm_aeskeygenassist_si128(rk, Rcon));
|
||||||
|
StoreRoundKey<RoundIdx>(rk);
|
||||||
|
return rk;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
ContextAESNI(const u8* key)
|
||||||
|
{
|
||||||
|
__m128i rk = _mm_loadu_si128((const __m128i*)key);
|
||||||
|
StoreRoundKey<0>(rk);
|
||||||
|
rk = Aes128Keygen<1, 0x01>(rk);
|
||||||
|
rk = Aes128Keygen<2, 0x02>(rk);
|
||||||
|
rk = Aes128Keygen<3, 0x04>(rk);
|
||||||
|
rk = Aes128Keygen<4, 0x08>(rk);
|
||||||
|
rk = Aes128Keygen<5, 0x10>(rk);
|
||||||
|
rk = Aes128Keygen<6, 0x20>(rk);
|
||||||
|
rk = Aes128Keygen<7, 0x40>(rk);
|
||||||
|
rk = Aes128Keygen<8, 0x80>(rk);
|
||||||
|
rk = Aes128Keygen<9, 0x1b>(rk);
|
||||||
|
Aes128Keygen<10, 0x36>(rk);
|
||||||
|
}
|
||||||
|
|
||||||
|
ATTRIBUTE_TARGET("aes")
|
||||||
|
inline void CryptBlock(__m128i* iv, const u8* buf_in, u8* buf_out) const
|
||||||
|
{
|
||||||
|
__m128i block = _mm_loadu_si128((const __m128i*)buf_in);
|
||||||
|
|
||||||
|
if constexpr (AesMode == Mode::Encrypt)
|
||||||
|
{
|
||||||
|
block = _mm_xor_si128(_mm_xor_si128(block, *iv), round_keys[0]);
|
||||||
|
|
||||||
|
for (size_t i = 1; i < Nr; ++i)
|
||||||
|
block = _mm_aesenc_si128(block, round_keys[i]);
|
||||||
|
block = _mm_aesenclast_si128(block, round_keys[Nr]);
|
||||||
|
|
||||||
|
*iv = block;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
__m128i iv_next = block;
|
||||||
|
|
||||||
|
block = _mm_xor_si128(block, round_keys[0]);
|
||||||
|
|
||||||
|
for (size_t i = 1; i < Nr; ++i)
|
||||||
|
block = _mm_aesdec_si128(block, round_keys[i]);
|
||||||
|
block = _mm_aesdeclast_si128(block, round_keys[Nr]);
|
||||||
|
|
||||||
|
block = _mm_xor_si128(block, *iv);
|
||||||
|
*iv = iv_next;
|
||||||
|
}
|
||||||
|
|
||||||
|
_mm_storeu_si128((__m128i*)buf_out, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Takes advantage of instruction pipelining to parallelize.
|
||||||
|
template <size_t NumBlocks>
|
||||||
|
ATTRIBUTE_TARGET("aes")
|
||||||
|
inline void DecryptPipelined(__m128i* iv, const u8* buf_in, u8* buf_out) const
|
||||||
|
{
|
||||||
|
constexpr size_t Depth = NumBlocks;
|
||||||
|
|
||||||
|
__m128i block[Depth];
|
||||||
|
for (size_t d = 0; d < Depth; d++)
|
||||||
|
block[d] = _mm_loadu_si128(&((const __m128i*)buf_in)[d]);
|
||||||
|
|
||||||
|
__m128i iv_next[1 + Depth];
|
||||||
|
iv_next[0] = *iv;
|
||||||
|
for (size_t d = 0; d < Depth; d++)
|
||||||
|
iv_next[1 + d] = block[d];
|
||||||
|
|
||||||
|
for (size_t d = 0; d < Depth; d++)
|
||||||
|
block[d] = _mm_xor_si128(block[d], round_keys[0]);
|
||||||
|
|
||||||
|
// The main speedup is here
|
||||||
|
for (size_t i = 1; i < Nr; ++i)
|
||||||
|
for (size_t d = 0; d < Depth; d++)
|
||||||
|
block[d] = _mm_aesdec_si128(block[d], round_keys[i]);
|
||||||
|
for (size_t d = 0; d < Depth; d++)
|
||||||
|
block[d] = _mm_aesdeclast_si128(block[d], round_keys[Nr]);
|
||||||
|
|
||||||
|
for (size_t d = 0; d < Depth; d++)
|
||||||
|
block[d] = _mm_xor_si128(block[d], iv_next[d]);
|
||||||
|
*iv = iv_next[1 + Depth - 1];
|
||||||
|
|
||||||
|
for (size_t d = 0; d < Depth; d++)
|
||||||
|
_mm_storeu_si128(&((__m128i*)buf_out)[d], block[d]);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool Crypt(const u8* iv, u8* iv_out, const u8* buf_in, u8* buf_out,
|
||||||
|
size_t len) const override
|
||||||
|
{
|
||||||
|
if (len % BLOCK_SIZE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
__m128i iv_block = iv ? _mm_loadu_si128((const __m128i*)iv) : _mm_setzero_si128();
|
||||||
|
|
||||||
|
if constexpr (AesMode == Mode::Decrypt)
|
||||||
|
{
|
||||||
|
// On amd zen2...(benchmark, not real-world):
|
||||||
|
// With AES(128) instructions, BLOCK_DEPTH results in following speedup vs. non-pipelined: 4:
|
||||||
|
// 18%, 8: 22%, 9: 26%, 10-15: 31%. 16: 8% (register exhaustion). With VAES(VEX.128), 10 gives
|
||||||
|
// 36% speedup vs. its corresponding baseline. VAES(VEX.128) is ~4% faster than AES(128). The
|
||||||
|
// result is similar on zen3.
|
||||||
|
// Zen3 in general is 20% faster than zen2 in aes, and VAES(VEX.256) is 35% faster than
|
||||||
|
// zen3/VAES(VEX.128).
|
||||||
|
// It seems like VAES(VEX.256) should be faster?
|
||||||
|
constexpr size_t BLOCK_DEPTH = 10;
|
||||||
|
constexpr size_t CHUNK_LEN = BLOCK_DEPTH * BLOCK_SIZE;
|
||||||
|
while (len >= CHUNK_LEN)
|
||||||
|
{
|
||||||
|
DecryptPipelined<BLOCK_DEPTH>(&iv_block, buf_in, buf_out);
|
||||||
|
buf_in += CHUNK_LEN;
|
||||||
|
buf_out += CHUNK_LEN;
|
||||||
|
len -= CHUNK_LEN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
len /= BLOCK_SIZE;
|
||||||
|
while (len--)
|
||||||
|
{
|
||||||
|
CryptBlock(&iv_block, buf_in, buf_out);
|
||||||
|
buf_in += BLOCK_SIZE;
|
||||||
|
buf_out += BLOCK_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iv_out)
|
||||||
|
_mm_storeu_si128((__m128i*)iv_out, iv_block);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::array<__m128i, NUM_ROUND_KEYS> round_keys;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_M_ARM_64)
|
||||||
|
|
||||||
|
template <Mode AesMode>
|
||||||
|
class ContextNeon final : public Context
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
template <size_t RoundIdx>
|
||||||
|
inline constexpr void StoreRoundKey(const u32* rk)
|
||||||
|
{
|
||||||
|
const uint8x16_t rk_block = vreinterpretq_u8_u32(vld1q_u32(rk));
|
||||||
|
if constexpr (AesMode == Mode::Encrypt)
|
||||||
|
round_keys[RoundIdx] = rk_block;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
constexpr size_t idx = NUM_ROUND_KEYS - RoundIdx - 1;
|
||||||
|
if constexpr (idx == 0 || idx == NUM_ROUND_KEYS - 1)
|
||||||
|
round_keys[idx] = rk_block;
|
||||||
|
else
|
||||||
|
round_keys[idx] = vaesimcq_u8(rk_block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ContextNeon(const u8* key)
|
||||||
|
{
|
||||||
|
constexpr u8 rcon[]{0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36};
|
||||||
|
std::array<u32, Nb * NUM_ROUND_KEYS> rk{};
|
||||||
|
|
||||||
|
// This uses a nice trick I've seen in wolfssl (not sure original author),
|
||||||
|
// which uses vaeseq_u8 to assist keygen.
|
||||||
|
// vaeseq_u8: op1 = SubBytes(ShiftRows(AddRoundKey(op1, op2)))
|
||||||
|
// given RotWord == ShiftRows for row 1 (rol(x,8))
|
||||||
|
// Probably not super fast (moves to/from vector regs constantly), but it is nice and simple.
|
||||||
|
|
||||||
|
std::memcpy(&rk[0], key, KEY_SIZE);
|
||||||
|
StoreRoundKey<0>(&rk[0]);
|
||||||
|
for (size_t i = 0; i < rk.size() - Nk; i += Nk)
|
||||||
|
{
|
||||||
|
const uint8x16_t enc = vaeseq_u8(vreinterpretq_u8_u32(vmovq_n_u32(rk[i + 3])), vmovq_n_u8(0));
|
||||||
|
const u32 temp = vgetq_lane_u32(vreinterpretq_u32_u8(enc), 0);
|
||||||
|
rk[i + 4] = rk[i + 0] ^ std::rotr(temp, 8) ^ rcon[i / Nk];
|
||||||
|
rk[i + 5] = rk[i + 4] ^ rk[i + 1];
|
||||||
|
rk[i + 6] = rk[i + 5] ^ rk[i + 2];
|
||||||
|
rk[i + 7] = rk[i + 6] ^ rk[i + 3];
|
||||||
|
// clang-format off
|
||||||
|
// Not great
|
||||||
|
const size_t rki = 1 + i / Nk;
|
||||||
|
switch (rki)
|
||||||
|
{
|
||||||
|
case 1: StoreRoundKey< 1>(&rk[Nk * rki]); break;
|
||||||
|
case 2: StoreRoundKey< 2>(&rk[Nk * rki]); break;
|
||||||
|
case 3: StoreRoundKey< 3>(&rk[Nk * rki]); break;
|
||||||
|
case 4: StoreRoundKey< 4>(&rk[Nk * rki]); break;
|
||||||
|
case 5: StoreRoundKey< 5>(&rk[Nk * rki]); break;
|
||||||
|
case 6: StoreRoundKey< 6>(&rk[Nk * rki]); break;
|
||||||
|
case 7: StoreRoundKey< 7>(&rk[Nk * rki]); break;
|
||||||
|
case 8: StoreRoundKey< 8>(&rk[Nk * rki]); break;
|
||||||
|
case 9: StoreRoundKey< 9>(&rk[Nk * rki]); break;
|
||||||
|
case 10: StoreRoundKey<10>(&rk[Nk * rki]); break;
|
||||||
|
}
|
||||||
|
// clang-format on
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void CryptBlock(uint8x16_t* iv, const u8* buf_in, u8* buf_out) const
|
||||||
|
{
|
||||||
|
uint8x16_t block = vld1q_u8(buf_in);
|
||||||
|
|
||||||
|
if constexpr (AesMode == Mode::Encrypt)
|
||||||
|
{
|
||||||
|
block = veorq_u8(block, *iv);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < Nr - 1; ++i)
|
||||||
|
block = vaesmcq_u8(vaeseq_u8(block, round_keys[i]));
|
||||||
|
block = vaeseq_u8(block, round_keys[Nr - 1]);
|
||||||
|
block = veorq_u8(block, round_keys[Nr]);
|
||||||
|
|
||||||
|
*iv = block;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uint8x16_t iv_next = block;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < Nr - 1; ++i)
|
||||||
|
block = vaesimcq_u8(vaesdq_u8(block, round_keys[i]));
|
||||||
|
block = vaesdq_u8(block, round_keys[Nr - 1]);
|
||||||
|
block = veorq_u8(block, round_keys[Nr]);
|
||||||
|
|
||||||
|
block = veorq_u8(block, *iv);
|
||||||
|
*iv = iv_next;
|
||||||
|
}
|
||||||
|
|
||||||
|
vst1q_u8(buf_out, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool Crypt(const u8* iv, u8* iv_out, const u8* buf_in, u8* buf_out,
|
||||||
|
size_t len) const override
|
||||||
|
{
|
||||||
|
if (len % BLOCK_SIZE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
uint8x16_t iv_block = iv ? vld1q_u8(iv) : vmovq_n_u8(0);
|
||||||
|
|
||||||
|
len /= BLOCK_SIZE;
|
||||||
|
while (len--)
|
||||||
|
{
|
||||||
|
CryptBlock(&iv_block, buf_in, buf_out);
|
||||||
|
buf_in += BLOCK_SIZE;
|
||||||
|
buf_out += BLOCK_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iv_out)
|
||||||
|
vst1q_u8(iv_out, iv_block);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::array<uint8x16_t, NUM_ROUND_KEYS> round_keys;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
template <Mode AesMode>
|
||||||
|
std::unique_ptr<Context> CreateContext(const u8* key)
|
||||||
|
{
|
||||||
|
if (cpu_info.bAES)
|
||||||
|
{
|
||||||
|
#if defined(_M_X86_64)
|
||||||
|
#if defined(__AVX__)
|
||||||
|
// If compiler enables AVX, the intrinsics will generate VAES(VEX.128) instructions.
|
||||||
|
// In the future we may want to compile the code twice and explicitly override the compiler
|
||||||
|
// flags. There doesn't seem to be much performance difference between AES(128) and
|
||||||
|
// VAES(VEX.128) at the moment, though.
|
||||||
|
if (cpu_info.bAVX)
|
||||||
|
#endif
|
||||||
|
return std::make_unique<ContextAESNI<AesMode>>(key);
|
||||||
|
#elif defined(_M_ARM_64)
|
||||||
|
return std::make_unique<ContextNeon<AesMode>>(key);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
return std::make_unique<ContextGeneric<AesMode>>(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Context> CreateContextEncrypt(const u8* key)
|
||||||
|
{
|
||||||
|
return CreateContext<Mode::Encrypt>(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<Context> CreateContextDecrypt(const u8* key)
|
||||||
|
{
|
||||||
|
return CreateContext<Mode::Decrypt>(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
// OFB encryption and decryption are the exact same. We don't encrypt though.
|
||||||
|
void CryptOFB(const u8* key, const u8* iv, u8* iv_out, const u8* buf_in, u8* buf_out, size_t size)
|
||||||
|
{
|
||||||
|
mbedtls_aes_context aes_ctx;
|
||||||
|
size_t iv_offset = 0;
|
||||||
|
|
||||||
|
std::array<u8, 16> iv_tmp{};
|
||||||
|
if (iv)
|
||||||
|
std::memcpy(&iv_tmp[0], iv, 16);
|
||||||
|
|
||||||
|
ASSERT(!mbedtls_aes_setkey_enc(&aes_ctx, key, 128));
|
||||||
|
mbedtls_aes_crypt_ofb(&aes_ctx, size, &iv_offset, &iv_tmp[0], buf_in, buf_out);
|
||||||
|
|
||||||
|
if (iv_out)
|
||||||
|
std::memcpy(iv_out, &iv_tmp[0], 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Common::AES
|
586
pr_agent/static_analysis/tests/example_files/calc.java
Normal file
586
pr_agent/static_analysis/tests/example_files/calc.java
Normal file
@ -0,0 +1,586 @@
|
|||||||
|
package com.houarizegai.calculator.ui;
|
||||||
|
|
||||||
|
import com.houarizegai.calculator.theme.properties.Theme;
|
||||||
|
import com.houarizegai.calculator.theme.ThemeLoader;
|
||||||
|
|
||||||
|
import java.awt.Cursor;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.event.ItemEvent;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.awt.Color;
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
import static com.houarizegai.calculator.util.ColorUtil.hex2Color;
|
||||||
|
|
||||||
|
public class CalculatorUI {
|
||||||
|
|
||||||
|
private static final String FONT_NAME = "Comic Sans MS";
|
||||||
|
private static final String DOUBLE_OR_NUMBER_REGEX = "([-]?\\d+[.]\\d*)|(\\d+)|(-\\d+)";
|
||||||
|
private static final String APPLICATION_TITLE = "Calculator";
|
||||||
|
private static final int WINDOW_WIDTH = 410;
|
||||||
|
private static final int WINDOW_HEIGHT = 600;
|
||||||
|
private static final int BUTTON_WIDTH = 80;
|
||||||
|
private static final int BUTTON_HEIGHT = 70;
|
||||||
|
private static final int MARGIN_X = 20;
|
||||||
|
private static final int MARGIN_Y = 60;
|
||||||
|
|
||||||
|
private final JFrame window;
|
||||||
|
private JComboBox<String> comboCalculatorType;
|
||||||
|
private JComboBox<String> comboTheme;
|
||||||
|
private JTextField inputScreen;
|
||||||
|
private JButton btnC;
|
||||||
|
private JButton btnBack;
|
||||||
|
private JButton btnMod;
|
||||||
|
private JButton btnDiv;
|
||||||
|
private JButton btnMul;
|
||||||
|
private JButton btnSub;
|
||||||
|
private JButton btnAdd;
|
||||||
|
private JButton btn0;
|
||||||
|
private JButton btn1;
|
||||||
|
private JButton btn2;
|
||||||
|
private JButton btn3;
|
||||||
|
private JButton btn4;
|
||||||
|
private JButton btn5;
|
||||||
|
private JButton btn6;
|
||||||
|
private JButton btn7;
|
||||||
|
private JButton btn8;
|
||||||
|
private JButton btn9;
|
||||||
|
private JButton btnPoint;
|
||||||
|
private JButton btnEqual;
|
||||||
|
private JButton btnRoot;
|
||||||
|
private JButton btnPower;
|
||||||
|
private JButton btnLog;
|
||||||
|
|
||||||
|
private char selectedOperator = ' ';
|
||||||
|
private boolean go = true; // For calculate with Opt != (=)
|
||||||
|
private boolean addToDisplay = true; // Connect numbers in display
|
||||||
|
private double typedValue = 0;
|
||||||
|
|
||||||
|
private final Map<String, Theme> themesMap;
|
||||||
|
|
||||||
|
public CalculatorUI() {
|
||||||
|
themesMap = ThemeLoader.loadThemes();
|
||||||
|
|
||||||
|
window = new JFrame(APPLICATION_TITLE);
|
||||||
|
window.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||||
|
window.setLocationRelativeTo(null);
|
||||||
|
|
||||||
|
int[] columns = {MARGIN_X, MARGIN_X + 90, MARGIN_X + 90 * 2, MARGIN_X + 90 * 3, MARGIN_X + 90 * 4};
|
||||||
|
int[] rows = {MARGIN_Y, MARGIN_Y + 100, MARGIN_Y + 100 + 80, MARGIN_Y + 100 + 80 * 2, MARGIN_Y + 100 + 80 * 3, MARGIN_Y + 100 + 80 * 4};
|
||||||
|
|
||||||
|
initInputScreen(columns, rows);
|
||||||
|
initButtons(columns, rows);
|
||||||
|
initCalculatorTypeSelector();
|
||||||
|
|
||||||
|
initThemeSelector();
|
||||||
|
|
||||||
|
window.setLayout(null);
|
||||||
|
window.setResizable(false);
|
||||||
|
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
window.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double calculate(double firstNumber, double secondNumber, char operator) {
|
||||||
|
switch (operator) {
|
||||||
|
case '+':
|
||||||
|
return firstNumber + secondNumber;
|
||||||
|
case '-':
|
||||||
|
return firstNumber - secondNumber;
|
||||||
|
case '*':
|
||||||
|
return firstNumber * secondNumber;
|
||||||
|
case '/':
|
||||||
|
return firstNumber / secondNumber;
|
||||||
|
case '%':
|
||||||
|
return firstNumber % secondNumber;
|
||||||
|
case '^':
|
||||||
|
return Math.pow(firstNumber, secondNumber);
|
||||||
|
default:
|
||||||
|
return secondNumber;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initThemeSelector() {
|
||||||
|
comboTheme = createComboBox(themesMap.keySet().toArray(new String[0]), 230, 30, "Theme");
|
||||||
|
comboTheme.addItemListener(event -> {
|
||||||
|
if (event.getStateChange() != ItemEvent.SELECTED)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String selectedTheme = (String) event.getItem();
|
||||||
|
applyTheme(themesMap.get(selectedTheme));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (themesMap.entrySet().iterator().hasNext()) {
|
||||||
|
applyTheme(themesMap.entrySet().iterator().next().getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initInputScreen(int[] columns, int[] rows) {
|
||||||
|
inputScreen = new JTextField("0");
|
||||||
|
inputScreen.setBounds(columns[0], rows[0], 350, 70);
|
||||||
|
inputScreen.setEditable(false);
|
||||||
|
inputScreen.setBackground(Color.WHITE);
|
||||||
|
inputScreen.setFont(new Font(FONT_NAME, Font.PLAIN, 33));
|
||||||
|
window.add(inputScreen);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initCalculatorTypeSelector() {
|
||||||
|
comboCalculatorType = createComboBox(new String[]{"Standard", "Scientific"}, 20, 30, "Calculator type");
|
||||||
|
comboCalculatorType.addItemListener(event -> {
|
||||||
|
if (event.getStateChange() != ItemEvent.SELECTED)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String selectedItem = (String) event.getItem();
|
||||||
|
switch (selectedItem) {
|
||||||
|
case "Standard":
|
||||||
|
window.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||||
|
btnRoot.setVisible(false);
|
||||||
|
btnPower.setVisible(false);
|
||||||
|
btnLog.setVisible(false);
|
||||||
|
break;
|
||||||
|
case "Scientific":
|
||||||
|
window.setSize(WINDOW_WIDTH + 80, WINDOW_HEIGHT);
|
||||||
|
btnRoot.setVisible(true);
|
||||||
|
btnPower.setVisible(true);
|
||||||
|
btnLog.setVisible(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initButtons(int[] columns, int[] rows) {
|
||||||
|
btnC = createButton("C", columns[0], rows[1]);
|
||||||
|
btnC.addActionListener(event -> {
|
||||||
|
inputScreen.setText("0");
|
||||||
|
selectedOperator = ' ';
|
||||||
|
typedValue = 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
btnBack = createButton("<-", columns[1], rows[1]);
|
||||||
|
btnBack.addActionListener(event -> {
|
||||||
|
String str = inputScreen.getText();
|
||||||
|
StringBuilder str2 = new StringBuilder();
|
||||||
|
for (int i = 0; i < (str.length() - 1); i++) {
|
||||||
|
str2.append(str.charAt(i));
|
||||||
|
}
|
||||||
|
if (str2.toString().equals("")) {
|
||||||
|
inputScreen.setText("0");
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(str2.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
btnMod = createButton("%", columns[2], rows[1]);
|
||||||
|
btnMod.addActionListener(event -> {
|
||||||
|
if (!Pattern.matches(DOUBLE_OR_NUMBER_REGEX, inputScreen.getText()) || !go)
|
||||||
|
return;
|
||||||
|
|
||||||
|
typedValue = calculate(typedValue, Double.parseDouble(inputScreen.getText()), selectedOperator);
|
||||||
|
if (Pattern.matches("[-]?[\\d]+[.][0]*", String.valueOf(typedValue))) {
|
||||||
|
inputScreen.setText(String.valueOf((int) typedValue));
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(String.valueOf(typedValue));
|
||||||
|
}
|
||||||
|
selectedOperator = '%';
|
||||||
|
go = false;
|
||||||
|
addToDisplay = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
btnDiv = createButton("/", columns[3], rows[1]);
|
||||||
|
btnDiv.addActionListener(event -> {
|
||||||
|
if (!Pattern.matches(DOUBLE_OR_NUMBER_REGEX, inputScreen.getText()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (go) {
|
||||||
|
typedValue = calculate(typedValue, Double.parseDouble(inputScreen.getText()), selectedOperator);
|
||||||
|
if (Pattern.matches("[-]?[\\d]+[.][0]*", String.valueOf(typedValue))) {
|
||||||
|
inputScreen.setText(String.valueOf((int) typedValue));
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(String.valueOf(typedValue));
|
||||||
|
}
|
||||||
|
selectedOperator = '/';
|
||||||
|
go = false;
|
||||||
|
addToDisplay = false;
|
||||||
|
} else {
|
||||||
|
selectedOperator = '/';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
btn7 = createButton("7", columns[0], rows[2]);
|
||||||
|
btn7.addActionListener(event -> {
|
||||||
|
if (addToDisplay) {
|
||||||
|
if (Pattern.matches("[0]*", inputScreen.getText())) {
|
||||||
|
inputScreen.setText("7");
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(inputScreen.getText() + "7");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inputScreen.setText("7");
|
||||||
|
addToDisplay = true;
|
||||||
|
}
|
||||||
|
go = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
btn8 = createButton("8", columns[1], rows[2]);
|
||||||
|
btn8.addActionListener(event -> {
|
||||||
|
if (addToDisplay) {
|
||||||
|
if (Pattern.matches("[0]*", inputScreen.getText())) {
|
||||||
|
inputScreen.setText("8");
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(inputScreen.getText() + "8");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inputScreen.setText("8");
|
||||||
|
addToDisplay = true;
|
||||||
|
}
|
||||||
|
go = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
btn9 = createButton("9", columns[2], rows[2]);
|
||||||
|
btn9.addActionListener(event -> {
|
||||||
|
if (addToDisplay) {
|
||||||
|
if (Pattern.matches("[0]*", inputScreen.getText())) {
|
||||||
|
inputScreen.setText("9");
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(inputScreen.getText() + "9");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inputScreen.setText("9");
|
||||||
|
addToDisplay = true;
|
||||||
|
}
|
||||||
|
go = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
btnMul = createButton("*", columns[3], rows[2]);
|
||||||
|
btnMul.addActionListener(event -> {
|
||||||
|
if (!Pattern.matches(DOUBLE_OR_NUMBER_REGEX, inputScreen.getText()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (go) {
|
||||||
|
typedValue = calculate(typedValue, Double.parseDouble(inputScreen.getText()), selectedOperator);
|
||||||
|
if (Pattern.matches("[-]?[\\d]+[.][0]*", String.valueOf(typedValue))) {
|
||||||
|
inputScreen.setText(String.valueOf((int) typedValue));
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(String.valueOf(typedValue));
|
||||||
|
}
|
||||||
|
selectedOperator = '*';
|
||||||
|
go = false;
|
||||||
|
addToDisplay = false;
|
||||||
|
} else {
|
||||||
|
selectedOperator = '*';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
btn4 = createButton("4", columns[0], rows[3]);
|
||||||
|
btn4.addActionListener(event -> {
|
||||||
|
if (addToDisplay) {
|
||||||
|
if (Pattern.matches("[0]*", inputScreen.getText())) {
|
||||||
|
inputScreen.setText("4");
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(inputScreen.getText() + "4");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inputScreen.setText("4");
|
||||||
|
addToDisplay = true;
|
||||||
|
}
|
||||||
|
go = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
btn5 = createButton("5", columns[1], rows[3]);
|
||||||
|
btn5.addActionListener(event -> {
|
||||||
|
if (addToDisplay) {
|
||||||
|
if (Pattern.matches("[0]*", inputScreen.getText())) {
|
||||||
|
inputScreen.setText("5");
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(inputScreen.getText() + "5");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inputScreen.setText("5");
|
||||||
|
addToDisplay = true;
|
||||||
|
}
|
||||||
|
go = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
btn6 = createButton("6", columns[2], rows[3]);
|
||||||
|
btn6.addActionListener(event -> {
|
||||||
|
if (addToDisplay) {
|
||||||
|
if (Pattern.matches("[0]*", inputScreen.getText())) {
|
||||||
|
inputScreen.setText("6");
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(inputScreen.getText() + "6");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inputScreen.setText("6");
|
||||||
|
addToDisplay = true;
|
||||||
|
}
|
||||||
|
go = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
btnSub = createButton("-", columns[3], rows[3]);
|
||||||
|
btnSub.addActionListener(event -> {
|
||||||
|
if (!Pattern.matches(DOUBLE_OR_NUMBER_REGEX, inputScreen.getText()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (go) {
|
||||||
|
typedValue = calculate(typedValue, Double.parseDouble(inputScreen.getText()), selectedOperator);
|
||||||
|
if (Pattern.matches("[-]?[\\d]+[.][0]*", String.valueOf(typedValue))) {
|
||||||
|
inputScreen.setText(String.valueOf((int) typedValue));
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(String.valueOf(typedValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedOperator = '-';
|
||||||
|
go = false;
|
||||||
|
addToDisplay = false;
|
||||||
|
} else {
|
||||||
|
selectedOperator = '-';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
btn1 = createButton("1", columns[0], rows[4]);
|
||||||
|
btn1.addActionListener(event -> {
|
||||||
|
if (addToDisplay) {
|
||||||
|
if (Pattern.matches("[0]*", inputScreen.getText())) {
|
||||||
|
inputScreen.setText("1");
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(inputScreen.getText() + "1");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inputScreen.setText("1");
|
||||||
|
addToDisplay = true;
|
||||||
|
}
|
||||||
|
go = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
btn2 = createButton("2", columns[1], rows[4]);
|
||||||
|
btn2.addActionListener(event -> {
|
||||||
|
if (addToDisplay) {
|
||||||
|
if (Pattern.matches("[0]*", inputScreen.getText())) {
|
||||||
|
inputScreen.setText("2");
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(inputScreen.getText() + "2");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inputScreen.setText("2");
|
||||||
|
addToDisplay = true;
|
||||||
|
}
|
||||||
|
go = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
btn3 = createButton("3", columns[2], rows[4]);
|
||||||
|
btn3.addActionListener(event -> {
|
||||||
|
if (addToDisplay) {
|
||||||
|
if (Pattern.matches("[0]*", inputScreen.getText())) {
|
||||||
|
inputScreen.setText("3");
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(inputScreen.getText() + "3");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inputScreen.setText("3");
|
||||||
|
addToDisplay = true;
|
||||||
|
}
|
||||||
|
go = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
btnAdd = createButton("+", columns[3], rows[4]);
|
||||||
|
btnAdd.addActionListener(event -> {
|
||||||
|
if (!Pattern.matches(DOUBLE_OR_NUMBER_REGEX, inputScreen.getText()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (go) {
|
||||||
|
typedValue = calculate(typedValue, Double.parseDouble(inputScreen.getText()), selectedOperator);
|
||||||
|
if (Pattern.matches("[-]?[\\d]+[.][0]*", String.valueOf(typedValue))) {
|
||||||
|
inputScreen.setText(String.valueOf((int) typedValue));
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(String.valueOf(typedValue));
|
||||||
|
}
|
||||||
|
selectedOperator = '+';
|
||||||
|
go = false;
|
||||||
|
addToDisplay = false;
|
||||||
|
} else {
|
||||||
|
selectedOperator = '+';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
btnPoint = createButton(".", columns[0], rows[5]);
|
||||||
|
btnPoint.addActionListener(event -> {
|
||||||
|
if (addToDisplay) {
|
||||||
|
if (!inputScreen.getText().contains(".")) {
|
||||||
|
inputScreen.setText(inputScreen.getText() + ".");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inputScreen.setText("0.");
|
||||||
|
addToDisplay = true;
|
||||||
|
}
|
||||||
|
go = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
btn0 = createButton("0", columns[1], rows[5]);
|
||||||
|
btn0.addActionListener(event -> {
|
||||||
|
if (addToDisplay) {
|
||||||
|
if (Pattern.matches("[0]*", inputScreen.getText())) {
|
||||||
|
inputScreen.setText("0");
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(inputScreen.getText() + "0");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
inputScreen.setText("0");
|
||||||
|
addToDisplay = true;
|
||||||
|
}
|
||||||
|
go = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
btnEqual = createButton("=", columns[2], rows[5]);
|
||||||
|
btnEqual.addActionListener(event -> {
|
||||||
|
if (!Pattern.matches(DOUBLE_OR_NUMBER_REGEX, inputScreen.getText()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (go) {
|
||||||
|
typedValue = calculate(typedValue, Double.parseDouble(inputScreen.getText()), selectedOperator);
|
||||||
|
if (Pattern.matches("[-]?[\\d]+[.][0]*", String.valueOf(typedValue))) {
|
||||||
|
inputScreen.setText(String.valueOf((int) typedValue));
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(String.valueOf(typedValue));
|
||||||
|
}
|
||||||
|
selectedOperator = '=';
|
||||||
|
addToDisplay = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
btnEqual.setSize(2 * BUTTON_WIDTH + 10, BUTTON_HEIGHT);
|
||||||
|
|
||||||
|
btnRoot = createButton("√", columns[4], rows[1]);
|
||||||
|
btnRoot.addActionListener(event -> {
|
||||||
|
if (!Pattern.matches(DOUBLE_OR_NUMBER_REGEX, inputScreen.getText()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (go) {
|
||||||
|
typedValue = Math.sqrt(Double.parseDouble(inputScreen.getText()));
|
||||||
|
if (Pattern.matches("[-]?[\\d]+[.][0]*", String.valueOf(typedValue))) {
|
||||||
|
inputScreen.setText(String.valueOf((int) typedValue));
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(String.valueOf(typedValue));
|
||||||
|
}
|
||||||
|
selectedOperator = '√';
|
||||||
|
addToDisplay = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
btnRoot.setVisible(false);
|
||||||
|
|
||||||
|
btnPower = createButton("pow", columns[4], rows[2]);
|
||||||
|
btnPower.addActionListener(event -> {
|
||||||
|
if (!Pattern.matches(DOUBLE_OR_NUMBER_REGEX, inputScreen.getText()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (go) {
|
||||||
|
typedValue = calculate(typedValue, Double.parseDouble(inputScreen.getText()), selectedOperator);
|
||||||
|
if (Pattern.matches("[-]?[\\d]+[.][0]*", String.valueOf(typedValue))) {
|
||||||
|
inputScreen.setText(String.valueOf((int) typedValue));
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(String.valueOf(typedValue));
|
||||||
|
}
|
||||||
|
selectedOperator = '^';
|
||||||
|
go = false;
|
||||||
|
addToDisplay = false;
|
||||||
|
} else {
|
||||||
|
selectedOperator = '^';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
btnPower.setFont(new Font("Comic Sans MS", Font.PLAIN, 24));
|
||||||
|
btnPower.setVisible(false);
|
||||||
|
|
||||||
|
btnLog = createButton("ln", columns[4], rows[3]);
|
||||||
|
btnLog.addActionListener(event -> {
|
||||||
|
if (!Pattern.matches(DOUBLE_OR_NUMBER_REGEX, inputScreen.getText()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (go) {
|
||||||
|
typedValue = Math.log(Double.parseDouble(inputScreen.getText()));
|
||||||
|
if (Pattern.matches("[-]?[\\d]+[.][0]*", String.valueOf(typedValue))) {
|
||||||
|
inputScreen.setText(String.valueOf((int) typedValue));
|
||||||
|
} else {
|
||||||
|
inputScreen.setText(String.valueOf(typedValue));
|
||||||
|
}
|
||||||
|
selectedOperator = 'l';
|
||||||
|
addToDisplay = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
btnLog.setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private JComboBox<String> createComboBox(String[] items, int x, int y, String toolTip) {
|
||||||
|
JComboBox<String> combo = new JComboBox<>(items);
|
||||||
|
combo.setBounds(x, y, 140, 25);
|
||||||
|
combo.setToolTipText(toolTip);
|
||||||
|
combo.setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||||
|
window.add(combo);
|
||||||
|
|
||||||
|
return combo;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JButton createButton(String label, int x, int y) {
|
||||||
|
JButton btn = new JButton(label);
|
||||||
|
btn.setBounds(x, y, BUTTON_WIDTH, BUTTON_HEIGHT);
|
||||||
|
btn.setFont(new Font("Comic Sans MS", Font.PLAIN, 28));
|
||||||
|
btn.setCursor(new Cursor(Cursor.HAND_CURSOR));
|
||||||
|
btn.setFocusable(false);
|
||||||
|
window.add(btn);
|
||||||
|
|
||||||
|
return btn;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyTheme(Theme theme) {
|
||||||
|
window.getContentPane().setBackground(hex2Color(theme.getApplicationBackground()));
|
||||||
|
|
||||||
|
comboCalculatorType.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
comboTheme.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
inputScreen.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btn0.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btn1.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btn2.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btn3.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btn4.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btn5.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btn6.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btn7.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btn8.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btn9.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btnPoint.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btnC.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btnBack.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btnMod.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btnDiv.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btnMul.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btnSub.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btnAdd.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btnRoot.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btnLog.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btnPower.setForeground(hex2Color(theme.getTextColor()));
|
||||||
|
btnEqual.setForeground(hex2Color(theme.getBtnEqualTextColor()));
|
||||||
|
|
||||||
|
comboCalculatorType.setBackground(hex2Color(theme.getApplicationBackground()));
|
||||||
|
comboTheme.setBackground(hex2Color(theme.getApplicationBackground()));
|
||||||
|
inputScreen.setBackground(hex2Color(theme.getApplicationBackground()));
|
||||||
|
btn0.setBackground(hex2Color(theme.getNumbersBackground()));
|
||||||
|
btn1.setBackground(hex2Color(theme.getNumbersBackground()));
|
||||||
|
btn2.setBackground(hex2Color(theme.getNumbersBackground()));
|
||||||
|
btn3.setBackground(hex2Color(theme.getNumbersBackground()));
|
||||||
|
btn4.setBackground(hex2Color(theme.getNumbersBackground()));
|
||||||
|
btn5.setBackground(hex2Color(theme.getNumbersBackground()));
|
||||||
|
btn6.setBackground(hex2Color(theme.getNumbersBackground()));
|
||||||
|
btn7.setBackground(hex2Color(theme.getNumbersBackground()));
|
||||||
|
btn8.setBackground(hex2Color(theme.getNumbersBackground()));
|
||||||
|
btn9.setBackground(hex2Color(theme.getNumbersBackground()));
|
||||||
|
btnPoint.setBackground(hex2Color(theme.getNumbersBackground()));
|
||||||
|
btnC.setBackground(hex2Color(theme.getOperatorBackground()));
|
||||||
|
btnBack.setBackground(hex2Color(theme.getOperatorBackground()));
|
||||||
|
btnMod.setBackground(hex2Color(theme.getOperatorBackground()));
|
||||||
|
btnDiv.setBackground(hex2Color(theme.getOperatorBackground()));
|
||||||
|
btnMul.setBackground(hex2Color(theme.getOperatorBackground()));
|
||||||
|
btnSub.setBackground(hex2Color(theme.getOperatorBackground()));
|
||||||
|
btnAdd.setBackground(hex2Color(theme.getOperatorBackground()));
|
||||||
|
btnRoot.setBackground(hex2Color(theme.getOperatorBackground()));
|
||||||
|
btnLog.setBackground(hex2Color(theme.getOperatorBackground()));
|
||||||
|
btnPower.setBackground(hex2Color(theme.getOperatorBackground()));
|
||||||
|
btnEqual.setBackground(hex2Color(theme.getBtnEqualBackground()));
|
||||||
|
}
|
||||||
|
}
|
138
pr_agent/static_analysis/tests/example_files/match.ts
Normal file
138
pr_agent/static_analysis/tests/example_files/match.ts
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
// @ts-ignore
|
||||||
|
import { Pattern } from './types/Pattern'; // @ts-ignore
|
||||||
|
import { Match } from './types/Match'; // @ts-ignore
|
||||||
|
import * as symbols from './internals/symbols'; // @ts-ignore
|
||||||
|
import { matchPattern } from './internals/helpers'; // @ts-ignore
|
||||||
|
|
||||||
|
type MatchState<output> =
|
||||||
|
| { matched: true; value: output }
|
||||||
|
| { matched: false; value: undefined };
|
||||||
|
|
||||||
|
const unmatched: MatchState<never> = {
|
||||||
|
matched: false,
|
||||||
|
value: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `match` creates a **pattern matching expression**.
|
||||||
|
* * Use `.with(pattern, handler)` to pattern match on the input.
|
||||||
|
* * Use `.exhaustive()` or `.otherwise(() => defaultValue)` to end the expression and get the result.
|
||||||
|
*
|
||||||
|
* [Read the documentation for `match` on GitHub](https://github.com/gvergnaud/ts-pattern#match)
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* declare let input: "A" | "B";
|
||||||
|
*
|
||||||
|
* return match(input)
|
||||||
|
* .with("A", () => "It's an A!")
|
||||||
|
* .with("B", () => "It's a B!")
|
||||||
|
* .exhaustive();
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export function match<const input, output = symbols.unset>(
|
||||||
|
value: input
|
||||||
|
): Match<input, output> {
|
||||||
|
return new MatchExpression(value, unmatched) as any;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents a match expression. It follows the
|
||||||
|
* builder pattern, we chain methods to add features to the expression
|
||||||
|
* until we call `.exhaustive`, `.otherwise` or the unsafe `.run`
|
||||||
|
* method to execute it.
|
||||||
|
*
|
||||||
|
* The types of this class aren't public, the public type definition
|
||||||
|
* can be found in src/types/Match.ts.
|
||||||
|
*/
|
||||||
|
class MatchExpression<input, output> {
|
||||||
|
constructor(private input: input, private state: MatchState<output>) {}
|
||||||
|
|
||||||
|
with(...args: any[]): MatchExpression<input, output> {
|
||||||
|
if (this.state.matched) return this;
|
||||||
|
|
||||||
|
const handler: (selection: unknown, value: input) => output =
|
||||||
|
args[args.length - 1];
|
||||||
|
|
||||||
|
const patterns: Pattern<input>[] = [args[0]];
|
||||||
|
let predicate: ((value: input) => unknown) | undefined = undefined;
|
||||||
|
|
||||||
|
if (args.length === 3 && typeof args[1] === 'function') {
|
||||||
|
// case with guard as second argument
|
||||||
|
patterns.push(args[0]);
|
||||||
|
predicate = args[1];
|
||||||
|
} else if (args.length > 2) {
|
||||||
|
// case with several patterns
|
||||||
|
patterns.push(...args.slice(1, args.length - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
let hasSelections = false;
|
||||||
|
let selected: Record<string, unknown> = {};
|
||||||
|
const select = (key: string, value: unknown) => {
|
||||||
|
hasSelections = true;
|
||||||
|
selected[key] = value;
|
||||||
|
};
|
||||||
|
|
||||||
|
const matched =
|
||||||
|
patterns.some((pattern) => matchPattern(pattern, this.input, select)) &&
|
||||||
|
(predicate ? Boolean(predicate(this.input)) : true);
|
||||||
|
|
||||||
|
const selections = hasSelections
|
||||||
|
? symbols.anonymousSelectKey in selected
|
||||||
|
? selected[symbols.anonymousSelectKey]
|
||||||
|
: selected
|
||||||
|
: this.input;
|
||||||
|
|
||||||
|
const state = matched
|
||||||
|
? {
|
||||||
|
matched: true as const,
|
||||||
|
value: handler(selections, this.input),
|
||||||
|
}
|
||||||
|
: unmatched;
|
||||||
|
|
||||||
|
return new MatchExpression(this.input, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
when(
|
||||||
|
predicate: (value: input) => unknown,
|
||||||
|
handler: (selection: input, value: input) => output
|
||||||
|
): MatchExpression<input, output> {
|
||||||
|
if (this.state.matched) return this;
|
||||||
|
|
||||||
|
const matched = Boolean(predicate(this.input));
|
||||||
|
|
||||||
|
return new MatchExpression<input, output>(
|
||||||
|
this.input,
|
||||||
|
matched
|
||||||
|
? { matched: true, value: handler(this.input, this.input) }
|
||||||
|
: unmatched
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
otherwise(handler: (value: input) => output): output {
|
||||||
|
if (this.state.matched) return this.state.value;
|
||||||
|
return handler(this.input);
|
||||||
|
}
|
||||||
|
|
||||||
|
exhaustive(): output {
|
||||||
|
return this.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
run(): output {
|
||||||
|
if (this.state.matched) return this.state.value;
|
||||||
|
|
||||||
|
let displayedValue;
|
||||||
|
try {
|
||||||
|
displayedValue = JSON.stringify(this.input);
|
||||||
|
} catch (e) {
|
||||||
|
displayedValue = this.input;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(
|
||||||
|
`Pattern matching error: no pattern matches value ${displayedValue}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
returnType() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user