Compare commits

...

1782 Commits

Author SHA1 Message Date
Tal
0bf8c1e647 Merge pull request #1025 from Codium-ai/tr/refresh
refresh message
2024-07-05 17:12:55 +03:00
be18152446 refresh 2024-07-05 17:11:13 +03:00
7fc41409d4 refresh 2024-07-05 16:51:35 +03:00
Tal
78bcb72205 Update configuration_options.md 2024-07-04 18:42:23 +03:00
Tal
e35f83bdb6 Merge pull request #1022 from Codium-ai/tr/claude
sonnet-3.5
2024-07-04 12:27:34 +03:00
Tal
20d9d8ad07 Update pr_agent/algo/ai_handlers/litellm_ai_handler.py
Co-authored-by: codiumai-pr-agent-pro[bot] <151058649+codiumai-pr-agent-pro[bot]@users.noreply.github.com>
2024-07-04 12:26:23 +03:00
f3c80891f8 sonnet-3.5 2024-07-04 12:23:36 +03:00
Tal
12973c2c99 Merge pull request #1021 from Codium-ai/tr/margins
increase margins
2024-07-04 12:13:22 +03:00
Tal
1f5c3a4c0f Merge pull request #1020 from Codium-ai/tr/fallbacks
Tr/fallbacks
2024-07-04 12:12:39 +03:00
422b4082b5 No key issues to review 2024-07-03 20:58:25 +03:00
2235a19345 increase margins 2024-07-03 20:53:15 +03:00
e30c70d2ca keys fallback 2024-07-03 20:29:17 +03:00
f7a6e93b6c Merge pull request #1019 from Codium-ai/hl/persistent_suggestions_comment
persistent suggestions
2024-07-03 17:10:21 +03:00
23e6abcdce new line 2024-07-03 17:09:50 +03:00
0bac03496a keys fallback 2024-07-03 17:06:27 +03:00
a228ea8109 fix capitalize 2024-07-03 17:04:01 +03:00
0c3940b6a7 persistent release notes 2024-07-03 16:38:13 +03:00
Tal
b05e15e9ec Merge pull request #1016 from Codium-ai/tr/review_redesign
tests
2024-07-03 08:52:16 +03:00
bea68084b3 ValueError 2024-07-03 08:51:08 +03:00
57abf4ac62 tests 2024-07-03 08:47:59 +03:00
Tal
f0efe4a707 Merge pull request #1011 from Codium-ai/tr/review_redesign
Tr/review redesign
2024-07-03 08:38:27 +03:00
040503039e prompt 2024-07-03 08:37:04 +03:00
3e265682a7 extend additional files 2024-07-03 08:32:37 +03:00
d7c0f87ea5 table 2024-07-03 08:19:58 +03:00
92d040c80f Merge remote-tracking branch 'origin/main' into tr/review_redesign 2024-07-03 07:54:26 +03:00
Tal
96ededd12a Merge pull request #1014 from Codium-ai/tr/description
Tr/description
2024-06-30 20:32:28 +03:00
8d87b41cf2 extend additional files 2024-06-30 20:28:32 +03:00
f058c09a68 extend additional files 2024-06-30 20:20:50 +03:00
f2cb70ea67 extend additional files 2024-06-30 18:38:06 +03:00
3e6263e1cc async calls 2024-06-30 17:33:48 +03:00
3373fb404a review_v2 2024-06-29 21:57:20 +03:00
df02cc1437 Merge remote-tracking branch 'origin/main' into tr/review_redesign
# Conflicts:
#	pr_agent/tools/pr_reviewer.py
2024-06-29 21:55:49 +03:00
Tal
6a5f43f8ce Merge pull request #1005 from KennyDizi/main
Centralize PR Review Title Definition
2024-06-29 21:53:20 +03:00
ebbf9c25b3 review_v2 2024-06-29 21:42:12 +03:00
0dc7bdabd2 review_v2 2024-06-29 21:22:25 +03:00
defe200817 review_v2 2024-06-29 13:08:34 +03:00
bf5673912d APITimeoutError 2024-06-29 11:30:15 +03:00
Tal
089a76c897 Merge pull request #1009 from Codium-ai/tr/fix
fixes
2024-06-28 08:11:08 +03:00
4c444f5c9a fixes 2024-06-28 08:09:52 +03:00
e5aae0d14f fixes 2024-06-28 08:04:35 +03:00
15f854336a s 2024-06-27 09:07:19 +03:00
Tal
056eb3a954 Merge pull request #1004 from Codium-ai/tr/large_pr
Tr/large pr
2024-06-27 08:37:02 +03:00
11abce3ede s 2024-06-27 08:36:40 +03:00
556dc68add s 2024-06-27 08:32:14 +03:00
Tal
b1f728e6b0 Merge pull request #1006 from Codium-ai/tr/readme_updates
s
2024-06-27 08:30:19 +03:00
ca18f85294 s 2024-06-27 08:27:49 +03:00
382da3a5b6 Use descriptive name for the ReviewHeaderTitle enum to reflect its specific purpose related to PR headers 2024-06-27 07:17:26 +07:00
406dcd7b7b Improve code readability by adding a newline after enum definitions 2024-06-27 07:16:54 +07:00
b20f364b15 Change the data structure for prefixes to a list to preserve order 2024-06-27 07:16:26 +07:00
692904bb71 Use ReviewHeaderTitle in lieu of PrReviewTitle 2024-06-27 07:11:57 +07:00
ba963149ac Fix extract PrReviewTitle member value 2024-06-27 07:10:57 +07:00
7348d4144b Rename PrReviewTitle enum 2024-06-27 07:05:03 +07:00
d0315164be Apply PrReviewTitles enum for test file 2024-06-27 07:04:02 +07:00
41607b10ef Apply PrReviewTitles enum for pr review file 2024-06-27 07:03:43 +07:00
2d21df61c7 Apply PrReviewTitles enum for github provider file 2024-06-27 07:03:25 +07:00
c185b7c610 Apply PrReviewTitles enum for algo utils file 2024-06-27 07:03:08 +07:00
3d60954167 Add PrReviewTitles enum 2024-06-27 06:59:49 +07:00
a57896aa94 s 2024-06-26 21:05:00 +03:00
73f0eebb69 s 2024-06-26 20:44:30 +03:00
b1d07be728 s 2024-06-26 20:33:45 +03:00
0f920bcc5b s 2024-06-26 20:11:20 +03:00
55a82382ef Merge remote-tracking branch 'origin/main' 2024-06-26 16:20:16 +03:00
6c2a14d557 fix: correct indentation in PR description preparation logic 2024-06-26 16:20:05 +03:00
Tal
4ab747dbfd Merge pull request #1000 from yamitzky/main
feat: Support Anthropic Calude 3.5 Sonnet on Vertex AI
2024-06-25 16:38:38 +03:00
b814e4a26d feat: Support Anthropic Calude 3.5 Sonnet on Vertex AI 2024-06-25 17:32:17 +09:00
Tal
609fa266cf Merge pull request #998 from R-Mathis/main
Add gemini support for pr-agent
2024-06-24 20:25:26 +03:00
69f6997739 remove extra space 2024-06-24 14:01:33 +02:00
8cc436cbd6 add gemini support for pr agent 2024-06-24 13:48:56 +02:00
384dfc2292 add text bison support for pr agent 2024-06-24 13:28:37 +02:00
40737c3932 add gemini support for pr agent 2024-06-24 12:08:16 +02:00
c46434ac5e add gemini support for pr agent 2024-06-24 12:03:34 +02:00
255c2d8e94 add gemini support for pr ageny 2024-06-24 11:35:41 +02:00
74bb07e9c4 fix: correct indentation in PR description preparation logic 2024-06-23 21:17:34 +03:00
a4db59fadc Merge remote-tracking branch 'origin/main' 2024-06-23 16:53:53 +03:00
2990aac955 docs: update custom labels configuration and usage instructions in describe tool 2024-06-23 16:53:45 +03:00
Tal
afe037e976 Merge pull request #995 from Codium-ai/tr/prompt_bug_fix
fix: update prompt key from `suggestion_content` to `suggestion_summary` in code suggestions
2024-06-23 11:40:03 +03:00
666fcb6264 fix: update prompt key from suggestion_content to suggestion_summary in code suggestions 2024-06-23 11:33:33 +03:00
3f3e9909fe fix: initialize git_provider as an empty dictionary in GitHub App server 2024-06-23 10:03:52 +03:00
Tal
685c443d87 Merge pull request #990 from s1moe2/claude-sonnet
feat: claude 3.5 sonnet support
2024-06-22 08:16:39 +03:00
Tal
c4361ccb01 Merge pull request #989 from Codium-ai/mrT23-patch-7
Update requirements.txt
2024-06-22 08:16:20 +03:00
a3d4d6d86f feat: claude 3.5 sonnet support 2024-06-21 09:30:52 +01:00
Tal
b12554ee84 Update requirements.txt 2024-06-20 18:11:43 +03:00
Tal
29bc0890ab Update requirements.txt 2024-06-20 18:09:39 +03:00
Tal
5fd7ca7d02 Update requirements.txt 2024-06-20 18:01:26 +03:00
Tal
41ffa8df51 Update requirements.txt 2024-06-20 17:45:47 +03:00
47b12d8bbc Update usage guide to clarify ignore settings and provide example usage 2024-06-19 13:59:04 +03:00
Tal
ded8dc3689 Merge pull request #986 from Codium-ai/tr/is_auto
Add `is_auto_command` config check to conditionally publish output an…
2024-06-19 11:57:19 +03:00
9034e18772 Add is_auto_command config check to conditionally publish output and update GitHub App to set this flag 2024-06-19 11:51:10 +03:00
833bb29808 Add context-aware git provider retrieval and refactor related functions 2024-06-19 11:20:00 +03:00
Tal
bdf1be921d Merge pull request #984 from Codium-ai/tr/cache_git_provider
Tr/cache git provider
2024-06-19 11:02:11 +03:00
0c1331f77e Add context-aware git provider retrieval and refactor related functions 2024-06-19 09:49:47 +03:00
164999d83d Add context-aware git provider retrieval and refactor related functions 2024-06-19 09:46:48 +03:00
a710f3ff43 Add context-aware git provider retrieval and refactor related functions 2024-06-19 09:41:53 +03:00
025a14014a Add context-aware git provider retrieval and refactor related functions 2024-06-19 09:36:37 +03:00
5968db67b9 Merge remote-tracking branch 'origin/main' 2024-06-19 08:30:55 +03:00
3affe011fe Update Bitbucket app commands to include suggestions score threshold in documentation and configuration 2024-06-19 08:30:45 +03:00
Tal
c4a653f70a Merge pull request #983 from Codium-ai/ok/gunicorn
Support running GitHub App using gunicorn, adjust Dockerfile accordingly
2024-06-18 22:42:00 +03:00
663604daa5 Support running GitHub App using gunicorn, adjust Dockerfile accordingly 2024-06-18 20:15:48 +03:00
Tal
deda06866d Merge pull request #971 from brianteeman/typos-1
Fix typos/Spelling
2024-06-18 18:00:42 +03:00
e33f2e4c67 Improve wording and clarity in self-review section of improve.md 2024-06-18 17:48:03 +03:00
00b6a67e1e mkdocs 2024-06-18 10:06:58 +03:00
024ef7eea3 mkdocs 2024-06-18 09:53:49 +03:00
3fee687a34 mkdocs 2024-06-18 09:47:25 +03:00
Tal
b2c0c4d654 Merge pull request #981 from Codium-ai/tr/self_review
mkdocs
2024-06-18 09:42:59 +03:00
6b56ea4289 mkdocs 2024-06-18 09:40:05 +03:00
Tal
2a68a90474 Merge pull request #980 from Codium-ai/tr/self_review
mkdocs
2024-06-18 09:32:44 +03:00
de9b21d7bd mkdocs 2024-06-18 09:29:32 +03:00
Tal
612c6ed135 Merge pull request #978 from Codium-ai/tr/self_review
Add self-review checkbox functionality to improve tool and update doc…
2024-06-17 20:30:28 +03:00
6ed65eb82b Add self-review checkbox functionality to improve tool and update documentation 2024-06-17 20:30:14 +03:00
bc09330a44 Add self-review checkbox functionality to improve tool and update documentation 2024-06-17 20:26:09 +03:00
7bd1e5211c Update pr_agent/settings/pr_reviewer_prompts.toml
Co-authored-by: codiumai-pr-agent-pro[bot] <151058649+codiumai-pr-agent-pro[bot]@users.noreply.github.com>
2024-06-17 09:22:38 +01:00
Tal
8d44804f84 Merge pull request #975 from brianteeman/identify_image_in_comment
identify_image_in_comment
2024-06-17 08:41:35 +03:00
Tal
a4320b6b0d Merge pull request #976 from brianteeman/get_changlog_file
get_changlog_file
2024-06-17 08:39:59 +03:00
Tal
73ec67b14e Merge pull request #974 from brianteeman/repetition_penalty
repetition_penalty
2024-06-17 08:39:16 +03:00
Tal
790dcc552e Merge pull request #972 from brianteeman/overall_success
Overall_success
2024-06-17 08:34:59 +03:00
8463aaac0a get_changlog_file
Correct the spelling

Fix spelling errors now will prevent issues going forward where people have to misspell something on purpose
2024-06-16 17:35:52 +01:00
195f8a03ab identify_image_in_comment
Correct the spelling

Fix spelling errors now will prevent issues going forward where people have to misspell something on purpose
2024-06-16 17:33:23 +01:00
5268a84bcc repetition_penalty
Correct the spelling of this variable.

Fix spelling errors now will prevent issues going forward where people have to misspell something on purpose
2024-06-16 17:28:30 +01:00
e53badbac4 Overall_success
Correct the spelling of this variable.

Fix spelling errors now will prevent issues going forward where people have to misspell something on purpose
2024-06-16 17:12:11 +01:00
a9a27b5a8f Fix typos/Spelling
This simple PR fixes typos and spelling errors in code comments and documentation. It has no functional changes but does at least make the instruction more readable and match the code.
2024-06-16 17:06:30 +01:00
4db428456d Refactor filter_bad_extensions and is_valid_file functions to improve code readability and reusability 2024-06-15 20:10:46 +03:00
925fab474c key_issues_to_review 2024-06-15 19:58:09 +03:00
Tal
a1fb9aac29 Merge pull request #967 from yamitzky/main
Fix ModuleNotFoundError of Vertex AI
2024-06-15 19:51:23 +03:00
Tal
774bba4ed2 Merge pull request #964 from evalphobia/feature/vertexai-calude3
Support models: Anthropic Claude 3 on Vertex AI
2024-06-15 19:49:49 +03:00
Tal
dd8a7200f7 Merge pull request #966 from Codium-ai/tr/ignore
Tr/ignore
2024-06-15 19:48:42 +03:00
33d8b51abd Fix problem of vertex ai 2024-06-13 22:17:12 +09:00
e083841d96 Add file ignore functionality and update documentation for ignore patterns 2024-06-13 13:18:15 +03:00
1070f9583f Add file ignore functionality and update documentation for ignore patterns 2024-06-13 13:07:24 +03:00
bedcc2433c Add file ignore functionality and update documentation for ignore patterns 2024-06-13 13:00:39 +03:00
8ff85a9daf Fix markdown formatting in utils.py by removing extra newlines 2024-06-13 12:45:57 +03:00
58bc54b193 Add file ignore functionality and update documentation for ignore patterns 2024-06-13 12:27:10 +03:00
aa56c0097d Add file ignore functionality and update documentation for ignore patterns 2024-06-13 12:20:21 +03:00
20f6af803c Add file ignore functionality and update documentation for ignore patterns 2024-06-13 12:09:52 +03:00
2076454798 Add file ignore functionality and update documentation for ignore patterns 2024-06-13 12:01:50 +03:00
e367df352b Add file ignore functionality and update documentation for ignore patterns 2024-06-13 11:41:13 +03:00
Tal
a32a12a851 Merge pull request #965 from Codium-ai/tr/reviewer
Tr/reviewer
2024-06-13 09:34:28 +03:00
3a897935ae Merge remote-tracking branch 'origin/main' into tr/reviewer 2024-06-13 09:30:09 +03:00
55b52ad6b2 Add exception handling to process_can_be_split function and update pr_reviewer_prompts.toml formatting 2024-06-13 09:28:51 +03:00
b0f9b96c75 Support models: Anthropic Calude 3 on Vertex AI 2024-06-13 14:34:14 +09:00
Tal
aac7aeabd1 Update PR review prompts and terminology for clarity and consistency (#954)
* Update PR review prompts and terminology for clarity and consistency
2024-06-10 08:44:11 +03:00
306fd3d064 Update PR review prompts and terminology for clarity and consistency 2024-06-10 08:13:48 +03:00
Tal
f1d5587220 Merge pull request #955 from Codium-ai/ok/github_background
Github: work in background
2024-06-09 20:55:02 +03:00
07f21a5511 Github: work in background 2024-06-09 18:14:42 +03:00
1106dccc4f Update PR review prompts and terminology for clarity and consistency 2024-06-09 14:34:51 +03:00
e5f269040e Update PR review prompts and terminology for clarity and consistency 2024-06-09 14:32:50 +03:00
9c8bc6c86a Update PR review prompts and terminology for clarity and consistency 2024-06-09 14:29:32 +03:00
Tal
f4c9d23084 Merge pull request #950 from ryanzll/main
update LangChainOpenAIHandler for langchain version 0.2 and read openai_api_base
2024-06-09 10:15:53 +03:00
25fdf16894 Update PR help message links to new documentation URLs 2024-06-07 08:12:06 +03:00
Tal
12b0df4608 committable checbox (#951)
* Add "apply suggestions" feature to README, improve.md, and configuration.toml
2024-06-06 18:04:40 +03:00
529346b8e0 Merge branch 'main' of https://github.com/ryanzll/pr-agent 2024-06-06 22:28:11 +08:00
b28f66aaa0 1. update LangChainOpenAIHandler to support langchain version 0.2
2. read openai_api_base from settings for llms that compatible with openai
2024-06-06 22:27:01 +08:00
Tal
2e535e42ee Merge pull request #947 from Codium-ai/tr/gitlab_commits
gitlab push_commands
2024-06-05 20:32:11 +03:00
9c6a363a51 gitlab push_commands 2024-06-05 20:31:35 +03:00
75a27d64b4 gitlab push_commands 2024-06-05 20:26:45 +03:00
Tal
4549cb3948 Merge pull request #946 from Codium-ai/tr/gitlab_commits
gitlab push_commands will work
2024-06-05 11:25:57 +03:00
d046c2a939 gitlab push_commands will work 2024-06-05 11:25:10 +03:00
Tal
aed4ed41cc Merge pull request #944 from Codium-ai/tr/gitlab_commits
handle_push_trigger for gitlab
2024-06-04 20:17:27 +03:00
4d96d11ba5 enterprise 2024-06-04 20:15:22 +03:00
faf4576f03 enterprise 2024-06-04 17:08:24 +03:00
0b7dcf03a5 Improve error handling in get_mr_url_from_commit_sha function in gitlab_webhook.py 2024-06-04 16:47:20 +03:00
8e12787fc8 Clear secret provider configuration in configuration.toml 2024-06-04 16:42:54 +03:00
213ced7e18 Add PR evaluation prompt and link to fine-tuning benchmark documentation 2024-06-04 16:37:35 +03:00
Tal
6d6fb67306 Merge pull request #942 from barnett-yuxiang/main
Update Python code formatting, configuration loading, and local model additions
2024-06-04 15:38:20 +03:00
fac8a80c24 Update introduction.md 2024-06-04 17:15:20 +08:00
c53c6aee7f fix wrong provider name 2024-06-04 15:09:30 +08:00
b980168e75 Update pr_description.py 2024-06-04 11:19:18 +08:00
86d901d5a6 Update __init__.py 2024-06-04 11:17:04 +08:00
b1444eb180 format github_action_runner.py 2024-06-04 11:10:13 +08:00
d3a7041f0d update alog/__init__.py 2024-06-04 00:00:22 +08:00
b4f0ad948f Update Python code formatting, configuration loading, and local model additions
1. Code Formatting:
   - Standardized Python code formatting across multiple files to align with PEP 8 guidelines. This includes adjustments to whitespace, line breaks, and inline comments.

2. Configuration Loader Enhancements:
   - Enhanced the `get_settings` function in `config_loader.py` to provide more robust handling of settings retrieval. Added detailed documentation to improve code maintainability and clarity.

3. Model Addition in __init__.py:
   - Added a new model "ollama/llama3" with a token limit to the MAX_TOKENS dictionary in `__init__.py` to support new AI capabilities and configurations.
2024-06-03 23:58:31 +08:00
ab31d2f1f8 Merge pull request #941 from Codium-ai/ok/gitlab_fix
Ok/gitlab fix
2024-06-03 14:16:38 +03:00
2b0dfc6298 Merge remote-tracking branch 'origin/main' into ok/gitlab_fix 2024-06-03 14:15:46 +03:00
76ff49d446 Refactor GitLab webhook initialization to move app setup outside of start function 2024-06-03 12:38:41 +03:00
413547f404 Refactor GitLab webhook handling for async processing and improved logging 2024-06-03 12:36:24 +03:00
Tal
f8feaa0be7 Merge pull request #940 from Codium-ai/tr/benchmark
Add PR evaluation prompt and link to fine-tuning benchmark documentation
2024-06-03 11:39:08 +03:00
09190efb65 Add PR evaluation prompt and link to fine-tuning benchmark documentation 2024-06-03 11:35:39 +03:00
Tal
2746bd4754 Merge pull request #939 from Codium-ai/tr/benchmark
Disable final update message when auto_describe is enabled in GitHub …
2024-06-03 08:37:37 +03:00
4f13007267 Disable final update message when auto_describe is enabled in GitHub Action Runner 2024-06-03 08:15:36 +03:00
Tal
962bb1c23d Update index.md 2024-06-02 11:35:33 +03:00
Tal
e9804c9f0d Merge pull request #938 from Codium-ai/tr/benchmark
Add documentation for PR-Agent code fine-tuning benchmark and update …
2024-06-02 11:32:16 +03:00
f3aa9c02cc Add documentation for PR-Agent code fine-tuning benchmark and update mkdocs.yml 2024-06-02 11:30:56 +03:00
416b150d66 Add documentation for PR-Agent code fine-tuning benchmark and update mkdocs.yml 2024-06-02 11:28:48 +03:00
Tal
83f3cc5033 Merge pull request #933 from MarkRx/bugfix/server-logging-context
Fix some server implementations not properly logging context
2024-06-02 08:29:43 +03:00
Tal
1e1636911f Merge pull request #937 from KennyDizi/main
Optimize document table format
2024-06-01 10:53:47 +03:00
40658cfb7c Removed duplicaiton line 2024-06-01 08:14:25 +07:00
85f6353d15 Optimize for fine-tuning impact table 2024-06-01 08:11:34 +07:00
b9aeb8e443 Fix all markdownlint violations 2024-06-01 08:09:41 +07:00
ea7a84901d Simplify model performance table 2024-06-01 08:05:37 +07:00
Tal
37f6e18953 Merge pull request #932 from MarkRx/feature/valid-file-filter-log
Bitbucket server filter out globally ignored files before attempting diff
2024-05-31 16:33:01 +03:00
Tal
62c6211998 Merge pull request #936 from Codium-ai/mrT23-patch-5
Update README.md
2024-05-31 16:25:58 +03:00
Tal
dc6ae9fa7e Update README.md 2024-05-31 16:25:00 +03:00
Tal
c6e6cbb50e Merge pull request #935 from Codium-ai/tr/benchmark
Add documentation for PR-Agent code fine-tuning benchmark and update …
2024-05-31 16:12:35 +03:00
731c8de4ea Add documentation for PR-Agent code fine-tuning benchmark and update mkdocs.yml 2024-05-31 16:12:25 +03:00
4971071b1f Merge branch 'main' into feature/valid-file-filter-log 2024-05-31 09:10:50 -04:00
c341446015 Add documentation for PR-Agent code fine-tuning benchmark and update mkdocs.yml 2024-05-31 16:09:34 +03:00
Tal
ea9d410c84 Merge pull request #928 from MarkRx/bugfix/bb-server-fixes
Bitbucket Server Provider Fixes
2024-05-31 11:12:41 +03:00
d9a7dae6c4 Better error handling on backgrounp task thread 2024-05-30 20:22:58 -04:00
c9c14c10b0 Fix some server implementations not properly logging context 2024-05-30 20:16:21 -04:00
bd2f2b3a87 Improve bb server error logging 2024-05-30 17:31:46 -04:00
c11ee8643e Bitbucket server filter out globally ignored files before attempting diff 2024-05-30 11:34:39 -04:00
Tal
04d55a6309 Merge pull request #931 from Codium-ai/tr/logs_filter
Add logging for skipping non-code files in GitHub provider
2024-05-30 17:08:58 +03:00
e6c5236156 Add logging for skipping non-code files in GitHub provider 2024-05-30 17:05:30 +03:00
ee90f38501 BB Server fixes. Fix ID not being retrieved, inline comments, url generation, and pr review not working 2024-05-30 10:05:00 -04:00
6e6f54933e Add large_patch_policy configuration and implement patch clipping logic 2024-05-29 14:00:04 +03:00
911c1268fc Add large_patch_policy configuration and implement patch clipping logic 2024-05-29 13:52:44 +03:00
17f46bb53b Add large_patch_policy configuration and implement patch clipping logic 2024-05-29 13:42:44 +03:00
Tal
806ba3f9d8 Merge pull request #926 from eltociear/patch-2
docs: update additional_configurations.md
2024-05-28 08:50:33 +03:00
2a69116767 docs: update additional_configurations.md
Huggingface -> Hugging Face
2024-05-28 12:52:35 +09:00
Tal
b7225c1d10 Update README.md 2024-05-23 16:53:00 +03:00
Tal
ca5efbc52f Merge pull request #918 from Codium-ai/tr/readme2
protections
2024-05-22 21:51:09 +03:00
da44bd7d5e extended_patch 2024-05-22 21:50:00 +03:00
83ff9a0b9b final_update_message 2024-05-22 21:49:33 +03:00
4cd9626217 grammar 2024-05-22 21:47:49 +03:00
Tal
ca9f96a1e3 Merge pull request #916 from Codium-ai/tr/readme2
Chrome Extension readme
2024-05-22 14:41:47 +03:00
811965d841 grammar 2024-05-22 14:40:31 +03:00
39fe6f69d0 Expand and enhance documentation for PR-Agent Chrome Extension, adding detailed feature descriptions and updated images 2024-05-22 14:37:15 +03:00
Tal
66dc9349bd Update README.md 2024-05-21 11:05:33 +03:00
Tal
63340eb75e Cover-Agent 2024-05-21 11:04:37 +03:00
Tal
fab5b6f871 Merge pull request #913 from Codium-ai/tr/final_update
Update default setting of `final_update_message` to false in describe…
2024-05-20 14:30:52 +03:00
71770f3c04 Update default setting of final_update_message to false in describe.md and configuration.toml 2024-05-20 14:25:51 +03:00
Tal
a13cb14e9f Update pyproject.toml 2024-05-20 09:28:05 +03:00
Tal
e5bbb701d3 Update README.md 2024-05-19 13:03:30 +03:00
Tal
7779038e2a Merge pull request #912 from Codium-ai/tr/show_config
Tr/show config
2024-05-19 12:37:58 +03:00
c3dca2ef5a Refactor model selection logic for PR tools and update turbo model to gpt-4o 2024-05-19 12:37:31 +03:00
985b4f05cf Refactor model selection logic for PR tools and update turbo model to gpt-4o 2024-05-19 12:37:06 +03:00
8921d9eb0e Refactor model selection logic for PR tools and update turbo model to gpt-4o 2024-05-19 12:35:19 +03:00
2880e48860 Refactor model selection logic for PR tools and update turbo model to gpt-4o 2024-05-19 12:29:06 +03:00
9b56c83c1d APP_NAME 2024-05-19 12:18:22 +03:00
Tal
2369b8da69 Merge pull request #911 from Codium-ai/tr/show_config
Update configuration_options.md to include tip on showing relevant co…
2024-05-19 08:22:07 +03:00
dcd188193b Update configuration_options.md to include tip on showing relevant configurations 2024-05-19 08:20:15 +03:00
Tal
89819b302b Merge pull request #910 from Codium-ai/tr/show_config
Tr/show config
2024-05-19 08:06:20 +03:00
3432d377c7 Update configuration_options.md to include tip on showing relevant configurations 2024-05-18 13:14:16 +03:00
ea4ee1adbc Add show_relevant_configurations function and integrate it across tools to output relevant configurations if enabled 2024-05-18 13:09:50 +03:00
Tal
f9af9e4a91 Update pr_code_suggestions_prompts.toml 2024-05-16 21:59:00 +03:00
Tal
3b3e885b76 Merge pull request #906 from Codium-ai/tr/self_reflect
Tr/self reflect
2024-05-16 21:57:32 +03:00
46e934772c Rename "Custom Suggestions" feature to "Custom Prompt" across documentation, README, and tool references 2024-05-16 21:55:02 +03:00
cc08394e51 Refine field descriptions in pr_code_suggestions_prompts.toml and comment out default scoring error log in pr_code_suggestions.py 2024-05-16 21:49:06 +03:00
Tal
2b4eac2123 Merge pull request #905 from Codium-ai/tr/self_reflect
Add roadmap section to Chrome Extension documentation with visual pre…
2024-05-16 10:57:02 +03:00
570f7d6dcf Add roadmap section to Chrome Extension documentation with visual preview 2024-05-16 10:55:51 +03:00
Tal
188d092524 Merge pull request #904 from Codium-ai/tr/self_reflect
Add documentation for PR-Agent Chrome Extension and update mkdocs.yml…
2024-05-16 09:18:34 +03:00
8599c0fed4 Add documentation for PR-Agent Chrome Extension and update mkdocs.yml to include new section 2024-05-16 09:17:26 +03:00
0ab19b84b2 Add documentation for PR-Agent Chrome Extension and update mkdocs.yml to include new section 2024-05-16 09:12:55 +03:00
Tal
fec583e45e Merge pull request #903 from Codium-ai/mrT23-patch-3
Update README.md
2024-05-15 10:37:53 +03:00
Tal
589b865db5 Update README.md 2024-05-15 10:31:57 +03:00
Tal
be701aa868 Merge pull request #902 from Codium-ai/tr/self_reflect
Refactor Azure DevOps provider to use PR iterations for change detect…
2024-05-15 09:22:14 +03:00
4231a84e7a Refactor Azure DevOps provider to use PR iterations for change detection, improving accuracy of diff file identification 2024-05-15 09:15:12 +03:00
e56320540b Refactor Azure DevOps provider to use PR iterations for change detection, improving accuracy of diff file identification 2024-05-15 09:05:01 +03:00
e4565f7106 Refactor Azure DevOps provider to use PR iterations for change detection, improving accuracy of diff file identification 2024-05-14 21:43:14 +03:00
Tal
b4458ffede Merge pull request #901 from KennyDizi/main
Add new GPT-4o models and update tiktoken to 0.7.0
2024-05-14 09:25:24 +03:00
36ad8935ad Add gpt-4o models 2024-05-14 08:24:34 +07:00
9dd2520dbd Update tiktoken to 0.7.0 2024-05-14 08:21:41 +07:00
Tal
e6708fcb7b Merge pull request #898 from Codium-ai/tr/self_reflect
Tr/self reflect
2024-05-13 18:22:44 +03:00
05876afc02 Refactor pr_code_suggestions logic and update prompts for clarity and consistency 2024-05-13 18:21:31 +03:00
f3eb74d718 Refactor pr_code_suggestions logic and update prompts for clarity and consistency 2024-05-13 18:18:17 +03:00
b0aac4ec5d Refactor pr_code_suggestions logic and update prompts for clarity and consistency 2024-05-13 18:13:37 +03:00
95c7b3f55c Refactor pr_code_suggestions logic and update prompts for clarity and consistency 2024-05-13 18:03:13 +03:00
Tal
efd906ccf1 Update .pr_agent.toml 2024-05-13 17:52:09 +03:00
Tal
5fed21ce37 Update README.md 2024-05-13 09:44:59 +03:00
Tal
853cfb3fc9 Merge pull request #897 from Codium-ai/tr/self_reflect
Tr/self reflect
2024-05-13 09:28:58 +03:00
6c0837491c Update README.md to include info on filtering suggestions by score threshold 2024-05-13 09:21:55 +03:00
fbacc7c765 artifact 2024-05-13 09:19:08 +03:00
Tal
e69b798aa1 Merge pull request #895 from Codium-ai/tr/self_reflect
self-reflection documentation
2024-05-12 16:23:07 +03:00
61ba015a55 artifact 2024-05-12 16:22:40 +03:00
4f6490b17c Integrate self-reflection feature in PR-Agent, enhancing code suggestions with scoring and sorting, and update documentation accordingly 2024-05-12 16:17:47 +03:00
Tal
9dfc263e2e Merge pull request #894 from Codium-ai/tr/self_reflect
Tr/self reflect
2024-05-12 16:01:08 +03:00
d348cffbae Enhance error handling and logging in pr_code_suggestions with default scores and contextualized self_reflection 2024-05-12 15:52:59 +03:00
c04ab933cd s 2024-05-12 15:04:36 +03:00
a55fa753b9 s 2024-05-12 14:54:35 +03:00
8e0435d9a0 s 2024-05-12 14:40:25 +03:00
39c0733d6f s 2024-05-12 14:00:30 +03:00
a588e9f2bb s 2024-05-12 13:55:12 +03:00
7627e651ea s 2024-05-12 13:50:10 +03:00
1ebc20b761 self_reflect 2024-05-12 13:49:28 +03:00
Tal
38058ea714 Merge pull request #893 from Codium-ai/tr/readme3
Tr/readme3
2024-05-08 15:43:32 +03:00
c92c26448f s 2024-05-08 15:42:00 +03:00
38051f79b7 s 2024-05-08 14:38:28 +03:00
738eb055ff s 2024-05-08 14:28:38 +03:00
Tal
5d8d178a60 Merge pull request #892 from Codium-ai/mrT23-patch-3
Update configuration_options.md
2024-05-08 13:55:27 +03:00
Tal
e8f4a45774 Update configuration_options.md 2024-05-08 13:54:31 +03:00
Tal
aa60c7d701 Merge pull request #890 from Codium-ai/tr/branding
privacy
2024-05-05 16:15:04 +03:00
4645cd7cf9 privacy 2024-05-05 16:13:28 +03:00
edb230c993 privacy 2024-05-05 16:11:03 +03:00
7bb1917be7 privacy 2024-05-05 16:09:07 +03:00
Tal
d360fb72cb Merge pull request #889 from Codium-ai/tr/branding
privacy policy for chrome extension
2024-05-05 16:03:00 +03:00
253f77f4d9 privacy 2024-05-05 16:01:07 +03:00
Tal
cac450098a Merge pull request #887 from Codium-ai/tr/branding
Tr/branding
2024-05-05 14:00:17 +03:00
097637d7c0 toolbar emojis in pr-agent feedbacks 2024-05-05 13:48:45 +03:00
e4157d2efc toolbar emojis in pr-agent feedbacks 2024-05-05 13:36:34 +03:00
34ad5f2aa2 toolbar emojis in pr-agent feedbacks 2024-05-05 13:33:54 +03:00
Tal
3c76230f61 Update README.md 2024-05-03 14:52:19 +03:00
Tal
92cde2ef99 Update README.md 2024-05-03 08:32:39 +03:00
0b10f88b84 toolbar 2024-05-02 21:08:12 +03:00
Tal
3dbe1bbc35 Merge pull request #880 from tacascer/new-35-models
chore: update GPT3.5 models
2024-04-24 08:52:12 +03:00
2e34436589 chore: update GPT3.5 models 2024-04-22 20:25:32 -04:00
Tal
fae6cab2a7 Merge pull request #877 from randy-tsukemen/support-groq-llama3
Add Groq Llama3 support
2024-04-22 11:41:12 +03:00
Tal
19f239ae3d Merge pull request #876 from randy-tsukemen/fix-duplication
Fix duplicate assignment of replicate_key in LiteLLMAIHandler
2024-04-21 10:55:01 +03:00
d457fa2b9f Add Groq API key configuration to .secrets_template.toml 2024-04-21 15:22:40 +09:00
d430604dfe Add Groq Llama3 model configuration instructions to usage guide 2024-04-21 15:22:19 +09:00
0a53f09a7f Add GROQ.KEY support in LiteLLMAIHandler 2024-04-21 15:21:45 +09:00
7a9e73702d Fix duplicate assignment of replicate_key in LiteLLMAIHandler 2024-04-21 14:47:25 +09:00
Tal
e429c5d012 Merge pull request #873 from Codium-ai/tr/readme
docs: Add option to disable automatic CI feedback in configuration
2024-04-18 16:33:21 +03:00
1c8aeb2b64 docs: Add option to disable automatic CI feedback in configuration 2024-04-18 16:31:41 +03:00
Tal
4d6126d2c0 Merge pull request #872 from Codium-ai/tr/readme
## Example usage
2024-04-18 10:11:39 +03:00
a9d30c1d10 Remember 2024-04-18 10:11:19 +03:00
ea4d4ab618 ## Example usage 2024-04-18 10:04:38 +03:00
Tal
3088c58d5f Merge pull request #871 from Codium-ai/tr/readme
Tr/readme
2024-04-18 09:27:51 +03:00
0f99db65a9 docs 2024-04-18 09:10:14 +03:00
f913f02ea6 docs 2024-04-18 08:53:43 +03:00
7563af08a0 docs 2024-04-18 08:44:08 +03:00
ad96326832 not 2024-04-18 07:53:37 +03:00
Tal
003d5728e0 Merge pull request #870 from Codium-ai/tr/readme
Replace `summarize_mode` with `commitable_code_suggestions_mode` in p…
2024-04-18 07:32:32 +03:00
8242b10d8e Replace summarize_mode with commitable_code_suggestions_mode in pr_code_suggestions_prompts.toml to enhance PR suggestion mechanism 2024-04-18 07:31:33 +03:00
Tal
1c296127bd Merge pull request #865 from Codium-ai/tr/readme
Tr/readme
2024-04-17 21:06:32 +03:00
2f4e40860d Replace keep_original_user_title with generate_ai_title for PR description customization and update documentation accordingly 2024-04-17 16:29:12 +03:00
b076c33351 commitable_code_suggestions 2024-04-17 15:32:45 +03:00
e2e0bea8fd num_code_suggestions 2024-04-17 09:13:53 +03:00
e878dcb6b1 Example usage 2024-04-17 09:12:49 +03:00
Tal
b8bcaf86f2 Merge pull request #864 from Codium-ai/tr/readme
Example usage
2024-04-17 09:05:18 +03:00
6c78f4fd88 Example usage 2024-04-17 09:02:54 +03:00
Tal
a134a8bf6d Merge pull request #863 from Codium-ai/add-repo-url-to-docs
Add repo url to docs
2024-04-15 20:41:41 +03:00
32fd03bd55 Add repository URL to MkDocs configuration 2024-04-15 13:42:36 +03:00
d5262f24ca add name + github icon 2024-04-15 13:37:50 +03:00
fe231929ae Update mkdocs.yml to include site description and rename site 2024-04-15 13:33:22 +03:00
1481796d6a Add GitHub repository URL to MkDocs configuration 2024-04-15 13:32:05 +03:00
Tal
9274cd730d Merge pull request #862 from Codium-ai/tr/image
ask
2024-04-15 10:14:21 +03:00
93d153bae1 ask 2024-04-15 10:12:19 +03:00
Tal
50736447fb Merge pull request #860 from Codium-ai/tr/image
ask
2024-04-14 14:48:43 +03:00
8168ce0c8e ask 2024-04-14 14:45:15 +03:00
Tal
a8d2fca4a3 Merge pull request #859 from Codium-ai/tr/image
Tr/image
2024-04-14 14:14:06 +03:00
44eb0b4f23 ask 2024-04-14 14:12:48 +03:00
506e3007c4 ask 2024-04-14 14:11:04 +03:00
92ef2b4464 ask 2024-04-14 14:09:58 +03:00
86e64501df ask 2024-04-14 12:43:26 +03:00
f0230fce79 gpt-4-turbo-2024-04-09 2024-04-14 12:37:54 +03:00
4683a29819 s 2024-04-14 12:34:14 +03:00
8f0f08006f s 2024-04-14 12:00:19 +03:00
a4680ded93 protections 2024-04-12 20:32:47 +03:00
Tal
654f88b98a Merge pull request #858 from pkvach/handle-missing-openai-key
Handle OPENAI_KEY not set error in github_action_runner.py
2024-04-12 18:30:15 +03:00
4c83bf695d Handle OPENAI_KEY not set error in github_action_runner.py
Fixes https://github.com/Codium-ai/pr-agent/issues/855
2024-04-12 10:50:00 +03:00
Tal
af8ca7d1a4 Merge pull request #853 from idubnori/feature/gha-outputs-1
feat: set review data to github actions output
2024-04-11 16:34:49 +03:00
9e4ffd824c Merge branch 'main' into feature/gha-outputs-1 2024-04-10 23:27:44 +09:00
aef1c6ecde docs: add feature spec and config 2024-04-10 23:04:29 +09:00
5e5ead98de test: rename & add error case 2024-04-10 22:36:15 +09:00
ae633b3cea refine: github_action_output 2024-04-10 22:30:16 +09:00
97dcb34d77 clean: rename to github_action_output 2024-04-10 22:16:09 +09:00
Tal
f0c5aec0e4 Merge pull request #854 from riya-amemiya/riya-amemiya/add_model
add support for gpt-4-turbo model
2024-04-10 09:20:53 +03:00
108b1afa0e add new models 2024-04-10 14:44:38 +09:00
Tal
4a69ebe816 Merge pull request #851 from phuongvietnamlab/hotfix/is_valid_file
Failed to review PR: name 'is_valid_file' is not defined
2024-04-10 08:21:43 +03:00
3412095d81 chore: change default to true, if use in github actions 2024-04-10 09:18:21 +09:00
45176ab893 test: add config not set case 2024-04-10 09:17:29 +09:00
75c4befadf feat: set review data to github actions output 2024-04-10 01:02:05 +09:00
0257b619ff Failed to review PR: name 'is_valid_file' is not defined 2024-04-09 15:47:54 +07:00
Tal
7e664184be Merge pull request #848 from Codium-ai/tr/readme
Tr/readme
2024-04-08 15:50:19 +03:00
8a5b01b465 empty calc_pr_statistics 2024-04-08 14:49:00 +03:00
84d8f78d0c publish_output 2024-04-08 14:00:41 +03:00
Tal
c1c11e6c77 Merge pull request #846 from Codium-ai/tr/readme
readme
2024-04-08 09:14:54 +03:00
a543d7ed1a readme 2024-04-08 09:12:50 +03:00
Tal
236d7c44e2 Merge pull request #845 from Codium-ai/change-docs-readme
Update docs readme
2024-04-08 09:06:23 +03:00
09f76f45ef Update docs readme 2024-04-08 08:18:33 +03:00
Tal
61388f6d28 Merge pull request #844 from Codium-ai/tr/readme
readme
2024-04-07 17:05:09 +03:00
a5a68c2a73 readme 2024-04-07 17:02:37 +03:00
2be0e9108e readme 2024-04-07 17:00:40 +03:00
aa2121a48d readme 2024-04-07 16:28:30 +03:00
Tal
4841f0db7c Merge pull request #843 from network-charles/network-charles-patch-1
Fix Broken URL in README.md
2024-04-07 13:03:10 +03:00
dc14b87657 Update README.md 2024-04-07 10:06:05 +01:00
Tal
7b4d833e06 Merge pull request #842 from Codium-ai/tr/readme
readme
2024-04-07 11:53:25 +03:00
68f29a41ef readme 2024-04-07 11:52:42 +03:00
d6b037a63a readme 2024-04-07 11:51:06 +03:00
45eefaa4f0 readme 2024-04-07 11:04:23 +03:00
f3b4695617 readme 2024-04-07 10:43:56 +03:00
Tal
dbcbe52d3e Merge pull request #841 from Codium-ai/tr/readme
readme
2024-04-07 09:41:21 +03:00
60fd1c67fa readme 2024-04-07 09:35:41 +03:00
d9efc441df readme 2024-04-07 09:28:22 +03:00
Tal
cb13740166 Merge pull request #840 from Codium-ai/tr/readme
readme
2024-04-07 09:11:19 +03:00
4dc160bc16 readme 2024-04-07 09:08:40 +03:00
Tal
d9b4481701 Merge pull request #839 from Codium-ai/mrT23-patch-1
Update additional_configurations.md
2024-04-05 17:24:45 +03:00
Tal
bbd302360f Update additional_configurations.md 2024-04-05 17:22:54 +03:00
877aeffbb3 Update describe.md 2024-04-03 14:59:53 +03:00
d7b19af117 Update README.md 2024-04-03 14:53:56 +03:00
Tal
7bc4f3a1c1 Merge pull request #838 from Codium-ai/tr/single_encoder
TokenEncoder
2024-04-03 08:49:49 +03:00
9c3673209d TokenEncoder 2024-04-03 08:42:50 +03:00
Tal
a13c6e964b Merge pull request #837 from Codium-ai/tr/persistent_describe
feat: add persistent comment option for PR descriptions
2024-04-02 17:59:17 +03:00
9614f619e8 feat: add persistent comment option for PR descriptions 2024-04-02 17:54:37 +03:00
3ebb72e3f1 feat: add persistent comment option for PR descriptions 2024-04-02 17:52:34 +03:00
Tal
dfe8301dcd Merge pull request #836 from gregoryboue/main
feat: allows ollama usage
2024-04-02 16:30:54 +03:00
501b059575 feat: allows ollama usage
Fix https://github.com/Codium-ai/pr-agent/issues/657
2024-04-02 11:01:45 +02:00
Tal
27cdd419e5 Update index.md 2024-04-01 18:56:36 +03:00
Tal
3d86430f18 Update automations_and_usage.md 2024-04-01 18:46:08 +03:00
b7237c113b Merge pull request #834 from Codium-ai/analytics
analytics
2024-04-01 10:19:17 +03:00
a53ba4596e fix custom analytics 2024-04-01 10:03:36 +03:00
b86b37e6a2 analytics 2024-04-01 09:54:59 +03:00
Tal
4391ac4d4d Merge pull request #833 from Codium-ai/tr/help
docs: Add "Improve Component" tool documentation and update related g…
2024-03-31 12:18:20 +03:00
ce47adf986 C# 2024-03-31 12:15:29 +03:00
8bda365636 docs: Add "Improve Component" tool documentation and update related guides 2024-03-31 12:13:25 +03:00
Tal
30bb2f3fc9 Merge pull request #832 from Codium-ai/tr/help
refine help
2024-03-31 11:44:29 +03:00
c3b3651769 refine help 2024-03-31 11:43:00 +03:00
Tal
949808d0d2 Merge pull request #831 from Codium-ai/tr/readme4
docs: Refine project description and reorganize documentation links i…
2024-03-29 13:43:48 +03:00
7e84acc63c docs: Refine project description and reorganize documentation links in README 2024-03-29 13:34:23 +03:00
aae6869964 docs: Update PR-Agent usage guide 2024-03-28 09:37:29 +02:00
79bdb9a69f bugfix: validate output publishing with progress condition in pr_code_suggestions 2024-03-27 19:56:27 +02:00
Tal
a86913aa7f Merge pull request #828 from idubnori/work/fix-827
Improve trigger condition in github actions
2024-03-27 19:07:53 +02:00
020a29ebb8 docs: optimize condition of github actions 2024-03-27 20:53:46 +09:00
Tal
a8bee89ae9 Update custom.css 2024-03-27 13:00:16 +02:00
Tal
d0dc2af918 Merge pull request #829 from Codium-ai/mrT23-patch-7
Update github.md
2024-03-27 12:42:07 +02:00
Tal
82d9c77489 Update github.md 2024-03-27 12:40:47 +02:00
Tal
c42f2d17e7 Merge pull request #825 from Codium-ai/improve-docs-images
Refactor markdown image syntax and enhance documentation presentation
2024-03-27 12:36:30 +02:00
Tal
cd4deefbf8 Merge pull request #826 from s1moe2/fix/issue-824
fix: missing requirements.txt on lambda dockerfile
2024-03-27 12:32:23 +02:00
493f73f1ce chore: add logging the reason not execute 2024-03-27 12:03:27 +09:00
fa889fbb06 docs: add pull request event types 2024-03-27 12:00:24 +09:00
0241fe5c13 fix: missing git binary on lambda dockerfile 2024-03-26 23:58:07 +00:00
d250cb46f4 fix: missing requirements.txt on lambda dockerfile 2024-03-26 22:28:19 +00:00
c97702982c fix image 2024-03-26 23:09:37 +02:00
2f823fb4e1 update deprecated plugin 2024-03-26 23:06:07 +02:00
736c8a6953 Refactor markdown image syntax and enhance documentation presentation 2024-03-26 23:00:57 +02:00
Tal
26c4a98fc8 Merge pull request #820 from riya-amemiya/riya-amemiya/change_gpt-4-turbo_model
add support for gpt-4-turbo-preview model
2024-03-26 10:46:51 +02:00
a7494746df revert default model 2024-03-26 16:21:30 +09:00
Tal
182e485741 Merge pull request #821 from Codium-ai/tr/installation_id
logs
2024-03-26 08:12:43 +02:00
1491bcba96 logs 2024-03-26 08:09:33 +02:00
d064a352ad feat(pr_agent): add support for gpt-4-turbo-preview model and update default settings 2024-03-26 14:47:05 +09:00
9c284e64cf dont log pr-agent bot 2024-03-25 12:27:45 +02:00
903d74b2f7 ignore_bot_pr = true 2024-03-25 11:42:24 +02:00
Tal
4651ced0f6 Merge pull request #817 from Codium-ai/tr/shorter_help
ignore bot
2024-03-25 09:17:07 +02:00
3cdadb3ad1 always ignore bot 2024-03-25 09:04:07 +02:00
Tal
cff6f2b597 Merge pull request #816 from Codium-ai/tr/shorter_help
Tr/shorter help
2024-03-25 08:55:33 +02:00
695f0706a8 Refactor help text for clarity and update configuration links in help.py; standardize variable naming in cli.py 2024-03-25 08:53:13 +02:00
07f5025b03 Refactor help text for clarity and update configuration links in help.py; standardize variable naming in cli.py 2024-03-25 08:51:59 +02:00
Tal
1701eb5b07 Merge pull request #815 from Codium-ai/tr/pypi
adjustments to pypi
2024-03-23 16:20:30 +02:00
ee4798acca adjustments to pypi 2024-03-23 16:16:32 +02:00
Tal
a355fb5d20 Merge pull request #814 from Codium-ai/tr/pypi
Tr/pypi
2024-03-23 11:20:04 +02:00
8e39394bcf adjustments to pypi 2024-03-23 11:16:21 +02:00
cfea8caf1c adjustments to pypi 2024-03-23 11:13:20 +02:00
9a46690121 adjustments to pypi 2024-03-23 09:55:08 +02:00
2fccadc469 adjustments to pypi 2024-03-22 21:43:41 +02:00
887d640ba5 Merge remote-tracking branch 'origin/main' into tr/pypi 2024-03-22 21:36:45 +02:00
0816370b1a adjustments to pypi 2024-03-22 21:36:22 +02:00
Tal
b4b2c7c620 Merge pull request #800 from koid/feature/ignore-bot-pr-on-github-app
Added `ignore_bot_pr` option
2024-03-21 18:42:45 +02:00
Tal
6323ff2ca2 Merge pull request #811 from veryyet/main
chore: fix some typos
2024-03-21 18:07:41 +02:00
92fbf21bd3 chore: fix some typos
Signed-off-by: veryyet <zhengxingru@outlook.com>
2024-03-21 14:41:29 +08:00
Tal
83ab5f7c1e Merge pull request #809 from Codium-ai/mrT23-patch-7
Update build-and-test.yaml
2024-03-21 08:21:21 +02:00
cae0b96054 use sender_type on bot check 2024-03-21 12:06:46 +09:00
4f2bbf936e Merge pull request #810 from Codium-ai/hl/docs_patch1
Small update to docs
2024-03-20 13:48:30 +02:00
61b2a1a053 update default 2024-03-20 11:11:06 +02:00
31bb72d65d add enable help text to documentation 2024-03-20 11:09:23 +02:00
Tal
a969d10381 Update build-and-test.yaml 2024-03-20 09:07:52 +02:00
29a2412de6 name 2024-03-20 08:36:46 +02:00
Tal
11502c5938 Merge pull request #807 from Codium-ai/tr/persistent_improve
Add persistent improve
2024-03-20 08:16:59 +02:00
b70225294c Update 'improve' tool documentation and functionality: Add persistent comment option, adjust default values, and enhance comment handling in pr_code_suggestions.py 2024-03-20 08:14:08 +02:00
Tal
f121652e4d Update improve.md 2024-03-19 17:29:21 +02:00
cf15f768fc Review vs. Improve tools comparison 2024-03-19 16:33:43 +02:00
Tal
795f619805 Merge pull request #806 from Codium-ai/tr/readme22
Review vs. Improve tools comparison
2024-03-19 16:19:04 +02:00
a39ff5d2dd Review vs. Improve tools comparison 2024-03-19 16:16:22 +02:00
Tal
158370e66c Update build-and-test.yaml 2024-03-19 14:36:16 +02:00
Tal
8ab27cf3b5 Merge pull request #805 from Codium-ai/hl/change_incremental_review_screenshot
Update review.md
2024-03-19 14:35:39 +02:00
7254211ed3 Update review.md 2024-03-19 13:38:54 +02:00
Tal
60fc6679c8 Merge pull request #804 from Codium-ai/mrT23-patch-7
Update build-and-test.yaml
2024-03-19 12:09:34 +02:00
Tal
2a76e77ba2 Update build-and-test.yaml 2024-03-19 12:02:38 +02:00
Tal
7ffdac98b3 Merge pull request #803 from Codium-ai/tr/readme22
Refactor improve.md: Improve image formatting, restructure content, a…
2024-03-19 10:00:51 +02:00
0aea45ec9c type 2024-03-19 10:00:04 +02:00
1db58fd028 Refactor improve.md: Improve image formatting, restructure content, and enhance descriptions 2024-03-19 09:56:10 +02:00
Tal
728997fd0e Merge pull request #802 from Codium-ai/tr/fixes4
Refactor review.md: Improve image formatting, restructure content, an…
2024-03-19 09:30:06 +02:00
Tal
be76a4132e Merge branch 'main' into tr/fixes4 2024-03-19 09:29:09 +02:00
ae09040543 Refactor review.md: Improve image formatting, restructure content, and enhance descriptions 2024-03-19 09:27:17 +02:00
Tal
431ed1babd Merge pull request #801 from Codium-ai/tr/fixes4
Update describe.md: Improve image formatting, restructure content, an…
2024-03-19 09:05:56 +02:00
edb59744ec Update describe.md: Improve image formatting, restructure content, and enhance descriptions 2024-03-19 09:03:50 +02:00
d9bf931a58 Update describe.md: Improve image formatting, restructure content, and enhance descriptions 2024-03-19 08:59:49 +02:00
b71523f13e use endswith 2024-03-18 16:14:58 +09:00
80a793a257 ignore bot pr option on github app mode 2024-03-18 16:14:54 +09:00
Tal
dd83b196b4 Merge pull request #781 from koid/feature/support-bedrock-claude3
added support for bedrock/claude3
2024-03-18 08:03:29 +02:00
Tal
eff6468651 Merge pull request #798 from Codium-ai/change-v-emoji
Replace checkmark emojis with tick emojis in documentation
2024-03-17 13:26:08 +02:00
Tal
b124dbffa6 Merge pull request #799 from Codium-ai/tr/split
Added docs for pr-agent-pro
2024-03-17 13:25:23 +02:00
008ee0dbc2 Replace checkmark emojis with tick emojis in documentation 2024-03-17 13:17:01 +02:00
1db03ccc36 Refactor PR-Agent Pro installation documentation and update navigation links 2024-03-17 13:15:21 +02:00
8ccb998b82 Refactor PR-Agent Pro installation documentation and update navigation links 2024-03-17 13:11:08 +02:00
Tal
8fea771502 Merge pull request #796 from Codium-ai/tr/split
Initialize current_labels to empty list if no labels exist in pr_revi…
2024-03-17 11:40:36 +02:00
b6dd57375f Initialize current_labels to empty list if no labels exist in pr_reviewer.py 2024-03-17 11:39:10 +02:00
Tal
11fed1e22d Merge pull request #756 from Codium-ai/tr/split
can PR be split feature
2024-03-17 01:03:06 -07:00
ac2c062190 readme 2024-03-17 10:01:30 +02:00
498b4cb34e readme 2024-03-17 09:59:55 +02:00
6d39773a17 prompt 2024-03-17 09:44:50 +02:00
99a676d792 Merge remote-tracking branch 'origin/main' into tr/split 2024-03-17 09:00:04 +02:00
Tal
1e504fc9c6 Merge pull request #795 from Codium-ai/tr/fixes4
Enhance AI handler logging and add main PR language attribute to AI h…
2024-03-16 04:53:24 -07:00
669e076938 Enhance AI handler logging and add main PR language attribute to AI handler in various tools 2024-03-16 13:52:02 +02:00
74345284bd Enhance AI handler logging and add main PR language attribute to AI handler in various tools 2024-03-16 13:47:44 +02:00
de0f3d3b0e Merge pull request #793 from Codium-ai/logo-and-title-sizing
add corect size logo to the header and adjust title spacing
2024-03-15 13:20:37 +02:00
44386573eb ad dcorect size logo to the header and adjust title spacing 2024-03-15 12:04:07 +01:00
Tal
e555610b82 Merge pull request #792 from Codium-ai/tr/fixes4
Refactor code in pr_code_suggestions.py
2024-03-15 03:47:34 -07:00
1593d8932b Refactor code in pr_code_suggestions.py and remove 'use_repo_settings_file' from azure.md and automations_and_usage.md 2024-03-15 12:37:50 +02:00
Tal
4425607a7e Merge pull request #786 from Codium-ai/add-google-analytics
Added Google Analytics to mkdocs configuration
2024-03-14 08:22:57 -07:00
b472149714 Replace hardcoded Google Analytics ID with environment variable in mkdocs.yml 2024-03-14 16:13:08 +02:00
50d0af0372 Added Google Analytics to mkdocs configuration 2024-03-14 13:56:10 +02:00
3bae515e39 add claude-3-haiku 2024-03-14 16:58:44 +09:00
0cdd3bf436 update docs 2024-03-13 14:23:57 +09:00
33d2d78bbc update docs 2024-03-13 11:36:13 +09:00
f94a0fd704 add Claude3Config 2024-03-13 11:24:51 +09:00
1ed2cd064a add config litellm.drop_params 2024-03-13 11:20:02 +09:00
d62796ac68 update max_tokens 2024-03-13 11:14:04 +09:00
3f66a1f0c9 update litellm 2024-03-13 11:10:19 +09:00
78cabf28a4 Update label comparison logic in pr_reviewer.py and pr_description.py to consider unordered lists 2024-03-12 18:25:42 +02:00
8b29c3a2be typo 2024-03-12 18:18:08 +02:00
Tal
53cc929d8a Merge pull request #780 from Codium-ai/tr/links
update links
2024-03-12 08:51:44 -07:00
785fbe04ae update links 2024-03-12 17:42:19 +02:00
Tal
d201403036 Merge pull request #779 from Codium-ai/tr/describe_keep_labels
Update get_pr_labels method to support label updates
2024-03-12 08:18:24 -07:00
Tal
b8a1378d1c Merge pull request #776 from Codium-ai/fix-docs-footer
Update footer title and improve responsive design in footer.html
2024-03-12 08:14:13 -07:00
31a8f5302a Update get_pr_labels method to support label updates and prevent unnecessary label republishing 2024-03-12 17:02:45 +02:00
5f98a0c539 Update footer title and improve responsive design in footer.html 2024-03-12 10:22:48 +02:00
8fb75c16af doc update 2024-03-11 20:08:16 +02:00
c1c89577f7 Merge remote-tracking branch 'origin/main' 2024-03-11 11:58:44 +02:00
d83643083f fixed numbers 2024-03-11 11:58:35 +02:00
42cd85b420 Merge pull request #769 from Codium-ai/hl/incremental_review_update
fix
2024-03-11 11:33:48 +02:00
476d64bc18 fix 2024-03-11 11:30:05 +02:00
72cbf36e6c Merge pull request #768 from Codium-ai/hl/incremental_review_update
Hl/incremental review handle edge cases
2024-03-11 10:49:29 +02:00
ad240f7640 small fix 2024-03-11 10:13:41 +02:00
5c20fffee9 fix when no previous review where found, reivew -i should run as regular review 2024-03-11 09:59:16 +02:00
84dadb0469 rename + check github 2024-03-11 09:42:10 +02:00
b4776d5e00 Merge remote-tracking branch 'origin/main' 2024-03-11 09:38:01 +02:00
86dc87831b remove is_temporary 2024-03-11 09:37:51 +02:00
Tal
351e1b94a8 Merge pull request #767 from Codium-ai/tr/readme2
readme
2024-03-11 00:15:23 -07:00
4739fd3d37 readme 2024-03-11 09:13:35 +02:00
Tal
75800a745c Merge pull request #764 from Codium-ai/hl/incremental_review_update
Hl/incremental review update
2024-03-11 00:03:16 -07:00
Tal
256d1a3369 Merge pull request #751 from danstis/fix/ado-spaces
Fix URL encoding in Azure DevOps webhook handler
2024-03-10 23:57:59 -07:00
Tal
0efa4c1319 Merge pull request #765 from Codium-ai/tr/fixes5
Enhance logging and refactor code in gitlab_webhook.py
2024-03-10 23:57:33 -07:00
33a911da4c log 2024-03-11 08:56:48 +02:00
a27ad0feb6 log 2024-03-11 08:55:07 +02:00
6c5697b07c Enhance logging and refactor code in gitlab_webhook.py, update logger level in bitbucket_app.py and github_polling.py, remove redundant section in github.md 2024-03-11 08:50:19 +02:00
5453507097 small fix 2024-03-10 17:19:27 +02:00
003c49052e skip incremental review if no file changed since last review 2024-03-10 17:15:25 +02:00
c876f271a4 contains several themes 2024-03-10 17:13:40 +02:00
4810b8549b docs 2024-03-10 16:59:37 +02:00
10a96d61ca Merge remote-tracking branch 'origin/main' into tr/split
# Conflicts:
#	pr_agent/settings/pr_reviewer_prompts.toml
2024-03-10 16:57:25 +02:00
8324e9a38d can_be_split 2024-03-10 16:56:32 +02:00
Tal
5f529c9adf Update index.md 2024-03-10 16:16:25 +02:00
Tal
fd1fdc90dd Merge pull request #763 from Codium-ai/tr/readme_links
Update README.md with relevant links
2024-03-10 07:04:49 -07:00
6d52bcc636 Update README.md with relevant links 2024-03-10 16:02:24 +02:00
ff2346eacc update markdown 2024-03-10 14:18:29 +02:00
Tal
1cf6d1dfe1 Merge pull request #762 from Codium-ai/hl/add_manual_similar_docs
Update similar_code.md
2024-03-10 04:04:37 -07:00
1dc933b123 Update similar_code.md 2024-03-10 12:58:52 +02:00
Tal
6181f5290f Update README.md 2024-03-10 12:35:53 +02:00
Tal
fc400147d9 Merge pull request #761 from Codium-ai/tr/readme_links
Update README.md with new documentation portal links
2024-03-10 03:35:12 -07:00
498334ac5d Update README.md with relevant links 2024-03-10 12:34:17 +02:00
c8f93b1d47 Update README.md with new documentation portal links 2024-03-10 12:24:55 +02:00
Tal
1597b888e3 Merge pull request #760 from Codium-ai/tr/readme_links
Tr/readme links
2024-03-10 03:23:15 -07:00
212e7f6fb9 Update README.md with new documentation portal links 2024-03-10 12:22:30 +02:00
869978b977 Update README.md with new documentation portal links 2024-03-10 12:19:28 +02:00
Tal
a7e6690771 Merge pull request #757 from Codium-ai/add-docs-portal
Add docs portal
2024-03-10 01:45:37 -08:00
Tal
d1a2f596c7 Merge pull request #759 from Codium-ai/tr/fix_prompts
fixed bug in inline_code_suggestions in review
2024-03-09 21:53:26 -08:00
b4e9c55d8d fixed bug in inline_code_suggestions in review 2024-03-10 07:50:12 +02:00
Tal
def78ea723 Merge pull request #758 from Codium-ai/tr/fix_prompts
Fix missing colons in class definitions in pr_reviewer_prompts.toml
2024-03-09 21:40:49 -08:00
bb341a6568 Fix missing colons in class definitions in pr_reviewer_prompts.toml 2024-03-10 07:39:10 +02:00
2943204b9b Create CNAME 2024-03-09 21:07:49 +02:00
1be2039caa fix broken links 2024-03-09 21:01:38 +02:00
e4a26d2a0a fix broken links 2024-03-09 20:47:07 +02:00
4c0a98f865 Added local icon + logo 2024-03-09 20:29:25 +02:00
53dbd6f0b2 add favicon 2024-03-09 19:56:50 +02:00
9ff6c4ad86 Merge branch 'main' into add-docs-portal 2024-03-09 12:23:46 +02:00
c1d48c42e6 Updated logo reference in mkdocs.yml 2024-03-09 12:15:43 +02:00
73624148a5 Fix URL encoding in Azure DevOps webhook handler 2024-03-08 04:39:57 +00:00
c7315c53fc Merge pull request #748 from Codium-ai/ok/refactor_update_changelog
Refactor update changelog
2024-03-07 13:07:36 +02:00
05b0c4ff70 add cache to gitignore 2024-03-07 11:14:24 +02:00
228cabf610 remove cache 2024-03-07 11:13:30 +02:00
Tal
51b4cd05c3 Update CI_FEEDBACK.md 2024-03-07 10:01:40 +02:00
1ff0afabae Refactor update changelog 2024-03-07 00:48:33 +02:00
ff2b4864b4 Update README.md 2024-03-06 22:25:21 +02:00
992865dc70 Update docs-ci.yaml 2024-03-06 22:24:55 +02:00
afef57bb87 Update README.md 2024-03-06 22:22:37 +02:00
f9bef46d76 Update docs-ci.yaml 2024-03-06 22:22:11 +02:00
a602359f24 Add GitHub Actions workflow for docs deployment and remove outdated markdown files 2024-03-06 22:20:20 +02:00
852359e6ea Add documentation portal with MKDocs 2024-03-06 21:52:11 +02:00
fbbd65873e Merge pull request #747 from Codium-ai/tr/claude3
Refactor litellm_ai_handler.py and update requirements.txt
2024-03-06 12:31:18 +02:00
0690f2bbfd Refactor litellm_ai_handler.py and update requirements.txt
- Replace retry library with tenacity for better exception handling
- Add verbosity level checks for logging prompts and AI responses
- Add support for HuggingFace API base and repetition penalty in chat completion
- Update requirements.txt with tenacity library
2024-03-06 12:13:54 +02:00
Tal
8083a6e74a Merge pull request #746 from Codium-ai/tr/claude3
Tr/claude3
2024-03-06 01:08:41 -08:00
26fb2a4164 Add support for Anthropic Claude-3 model in configuration and update Usage.md 2024-03-06 08:20:08 +02:00
1c856a7d41 upgrade litellm 2024-03-06 08:06:59 +02:00
2f6f1d5879 Add command execution functionality to Bitbucket app and update configuration settings 2024-03-06 07:53:13 +02:00
Tal
3016d5d1ed Update REVIEW.md 2024-03-05 20:51:17 +02:00
Tal
f777b6e765 Merge pull request #744 from Codium-ai/tr/final_update_message
Add 'final_update_message' option to control publishing of update messages
2024-03-05 10:12:23 -08:00
c7eb70d00d protections 2024-03-05 20:11:39 +02:00
d77db93f80 protections 2024-03-05 18:34:18 +02:00
359a15c84e Add 'final_update_message' option to control publishing of update message in persistent comments 2024-03-05 17:33:29 +02:00
acefbff62b Add 'final_update_message' option to control publishing of update message in persistent comments 2024-03-05 17:29:17 +02:00
Tal
7e993558e0 Merge pull request #735 from Codium-ai/tr/fixes3
Add unique_strings function and remove duplicate issues in utils.py
2024-03-04 07:37:13 -08:00
a1355fa12a Merge pull request #736 from Codium-ai/ok/azure_openai_doc_fix
Doc update
2024-03-04 17:04:11 +02:00
273f361e31 Update section title in Usage.md from 'Usage Types' to 'Automation and Usage' 2024-03-04 15:28:21 +02:00
96bccb3156 Doc update 2024-03-04 14:28:32 +02:00
da39149c61 Add unique_strings function and remove duplicate issues in utils.py; Update pr_reviewer_prompts.toml template 2024-03-04 11:07:39 +02:00
Tal
234a4f352d Merge pull request #734 from Codium-ai/tr/fixes3
Update suggestion content in pr_code_suggestions_prompts.toml
2024-03-03 22:18:57 -08:00
eed23a7aaa Add truncation and summarization features to PR code suggestions 2024-03-04 08:16:05 +02:00
248c6b13be Update suggestion content in pr_code_suggestions_prompts.toml 2024-03-04 07:56:44 +02:00
Tal
7e07347b99 Merge pull request #733 from Codium-ai/tr/fixes3
readme updates
2024-03-03 05:10:08 -08:00
aa9dbf7111 updated readme 2024-03-03 15:04:59 +02:00
Tal
0709d5f663 Merge pull request #730 from Codium-ai/tr/issue_header
Enhance markdown formatting fo issues
2024-03-03 04:06:04 -08:00
c372c71514 prompt 2024-03-03 14:04:09 +02:00
b3fd05c465 try-except 2024-03-03 13:58:10 +02:00
Tal
68fab0bab9 Merge pull request #732 from Codium-ai/tr/remove_outdated_option
Remove functionality and references to 'remove_previous_review_comment'
2024-03-03 01:27:16 -08:00
f1bd67b7e9 Remove functionality and references to 'remove_previous_review_comment' option 2024-03-03 11:24:30 +02:00
Tal
5500d35856 Update Usage.md 2024-03-03 08:21:04 +02:00
5880221d00 Update logger setup to include debug level in github_app.py 2024-03-02 23:32:26 +02:00
Tal
c031653f68 Update README.md 2024-03-02 22:27:33 +02:00
Tal
5949a794c2 Update README.md 2024-03-02 22:26:24 +02:00
Tal
49dda61642 Update README.md 2024-03-02 22:25:55 +02:00
Tal
488caf2a90 Update Usage.md 2024-03-02 20:46:47 +02:00
Tal
9a0288250d Merge pull request #729 from Codium-ai/tr/wiki
wiki
2024-03-02 10:24:27 -08:00
917bdd5cb8 Refactor Usage.md for improved readability and organization 2024-03-02 20:23:10 +02:00
aabe96c7ff Refactor Usage.md for improved readability and organization 2024-03-02 20:20:08 +02:00
db796416d9 wiki 2024-03-02 20:16:29 +02:00
35315c070f major 2024-03-01 13:18:53 +02:00
7d081aa1d1 fix tests 2024-03-01 13:09:47 +02:00
e589dcb489 Enhance markdown formatting and update prompt descriptions in pr_reviewer_prompts.toml 2024-03-01 13:02:50 +02:00
Tal
60bd57538a Merge pull request #728 from Codium-ai/mrT23-patch-5
Update IMPROVE.md
2024-02-29 07:22:43 -08:00
Tal
a6cdd72966 Update IMPROVE.md 2024-02-29 17:20:15 +02:00
a86a3f52f0 a minor bugfix 2024-02-29 16:03:00 +02:00
Tal
2340f95488 Merge pull request #727 from Codium-ai/tr/repo_log
log event
2024-02-28 22:10:26 -08:00
dd4dc4b761 log event 2024-02-29 08:09:25 +02:00
Tal
6a51a646ee Merge pull request #725 from Codium-ai/tr/repo_log
get_log_context
2024-02-28 11:26:53 -08:00
8d498cd70c git_org 2024-02-28 16:14:13 +02:00
d5e72c2183 get_log_context 2024-02-28 16:10:57 +02:00
b09b936b15 get_log_context 2024-02-28 16:05:52 +02:00
Tal
6f22e5f557 Merge pull request #714 from Codium-ai/tr/improve_tweaks
improve tweaks
2024-02-28 05:57:38 -08:00
dbe772e708 capitalize 2024-02-28 13:59:04 +02:00
9c7ac125e1 Tweak analytics log message to add api_url 2024-02-28 12:05:01 +02:00
a8c5ac10b6 Merge remote-tracking branch 'origin/main' into tr/improve_tweaks 2024-02-28 11:09:48 +02:00
Tal
d54c5574a1 Merge pull request #723 from Codium-ai/tr/fixes2
some fixes
2024-02-27 23:27:54 -08:00
047c370683 Update README.md and add gfm markdown support check in pr_help_message.py 2024-02-28 09:20:14 +02:00
07f507c442 remove_initial_comment 2024-02-28 09:08:48 +02:00
39538c5356 cleaning 2024-02-28 09:01:39 +02:00
0c654b3b64 handle unsupported platforms for update changelog 2024-02-28 08:41:25 +02:00
Tal
92d3627de0 Update IMPROVE.md 2024-02-27 23:10:44 +02:00
4316d00941 log_context 2024-02-26 21:12:28 +02:00
edc9d8944e Refactor handle_closed_pr function to check for merged PRs 2024-02-26 20:56:43 +02:00
910c56c851 Merge pull request #721 from Codium-ai/ok/identity_provider
Identity provider
2024-02-26 20:23:09 +02:00
ab29cf2b30 Identity provider 2024-02-26 20:21:20 +02:00
Tal
540433b82c Merge pull request #720 from Codium-ai/tr/pr_statistics
Add functionality to calculate and log PR statistics on closure
2024-02-26 10:10:07 -08:00
60a37158b1 Add functionality to calculate and log PR statistics on closure 2024-02-26 20:09:01 +02:00
4921c26432 Add functionality to calculate and log PR statistics on closure 2024-02-26 20:02:11 +02:00
Tal
34fe2721fb Merge pull request #719 from Codium-ai/ok/identity_provider
Ok/identity provider
2024-02-26 09:34:06 -08:00
8bdc90c0f7 Identity provider 2024-02-26 19:00:21 +02:00
77831c793d Identity provider 2024-02-26 18:31:12 +02:00
Tal
5a2b5d97a0 Merge pull request #717 from Codium-ai/tr/logs_message
Add documentation for 'ignore_pr_titles' parameter in Usage.md
2024-02-26 06:43:22 -08:00
86c7c495f2 Add documentation for 'ignore_pr_titles' parameter in Usage.md 2024-02-26 16:29:40 +02:00
4b8fe84f88 Merge pull request #716 from Codium-ai/ok/analytics_support
Add analytics logging
2024-02-26 16:25:32 +02:00
8843f7bc8b Add analytics logging 2024-02-26 16:15:23 +02:00
Tal
64feef585a Merge pull request #715 from Codium-ai/tr/logs_message
small log improvement
2024-02-26 05:19:49 -08:00
ffe4512b7d small log improvement 2024-02-26 15:16:59 +02:00
a5cb35418e remove 'review_requested' (can trigger rate limit, and doesnt make sense algorighmically) 2024-02-26 14:20:50 +02:00
8594c93186 improve tweaks 2024-02-26 12:05:29 +02:00
Tal
116dd75a14 Merge pull request #712 from Codium-ai/tr/review_tweaks
Tr/review tweaks
2024-02-26 01:19:36 -08:00
85cdf05ca8 review formatting 2024-02-26 09:36:16 +02:00
7c9a389abf review formatting 2024-02-26 09:27:13 +02:00
18472492bc s 2024-02-26 09:14:12 +02:00
Tal
9002dccf6b Update IMPROVE.md 2024-02-25 19:10:56 +02:00
Tal
3ad53a34cd Update REVIEW.md 2024-02-25 17:33:24 +02:00
Tal
29714f9bd7 Merge pull request #710 from Codium-ai/tr/direct_link_bug
Refactor link generation in github_provider.py to use get_pr_url method
2024-02-25 07:28:47 -08:00
Tal
f921b5e9b9 Merge pull request #711 from Codium-ai/mrT23-patch-4
Update REVIEW.md
2024-02-25 07:23:04 -08:00
5f9969f30c base_url 2024-02-25 17:22:35 +02:00
Tal
0430f68d39 Update REVIEW.md 2024-02-25 17:17:55 +02:00
Tal
7f7045fd8a Update REVIEW.md 2024-02-25 17:16:10 +02:00
2dfddd8cea Fix a bug 2024-02-25 17:13:35 +02:00
bc88e0492f Fix a bug 2024-02-25 17:12:40 +02:00
a15d4f7a94 base_url 2024-02-25 16:55:20 +02:00
4258ce165b Refactor link generation in github_provider.py to use get_pr_url method 2024-02-25 16:33:19 +02:00
Tal
39e2b02933 Merge pull request #709 from Codium-ai/tr/adjustment
adjustment
2024-02-25 06:27:37 -08:00
1275cf0123 adjustment 2024-02-25 16:23:44 +02:00
5ab69af5a7 Merge pull request #695 from Codium-ai/ok/analytics
Add support for analytics file
2024-02-25 11:17:09 +02:00
Tal
118c9addaa Merge pull request #708 from Codium-ai/tr/logs
Refactor logging
2024-02-25 00:47:49 -08:00
dad3d3429f artifact 2024-02-25 10:45:15 +02:00
984a2888ae Refactor logging statements for better readability and debugging 2024-02-25 10:04:04 +02:00
8252b98bf5 Refactor logging statements for better readability and debugging 2024-02-25 10:01:53 +02:00
34e421f79b Refactor logging statements for better readability and debugging 2024-02-25 09:58:58 +02:00
877796b539 Refactor logging statements for better readability and debugging 2024-02-25 09:46:07 +02:00
Tal
df3a463668 Merge pull request #707 from KennyDizi/main
Introduced collapsible file list threshold as a constant
2024-02-24 06:29:44 -08:00
3bcf085f61 Fix context 2024-02-24 17:00:58 +07:00
f3a712683a Use constant in stead of hard code number for collapsible file list threadhold 2024-02-24 16:53:18 +07:00
Tal
51ce484bab Update github_app.py 2024-02-24 09:40:15 +02:00
Tal
214f65902c Merge pull request #701 from Codium-ai/ok/github_app_startup
Change github app startup logic to support gunicorj
2024-02-23 11:14:28 -08:00
4d8c38e5e1 Change github app startup logic to support gunicorj 2024-02-23 18:29:35 +02:00
2242f73661 Merge remote-tracking branch 'origin/ok/github_app_startup' into ok/github_app_startup 2024-02-23 18:29:09 +02:00
2f3171e422 Change github app startup logic to support gunicorj 2024-02-23 18:28:58 +02:00
90599f53d4 Change github app startup logic to support gunicorj 2024-02-23 18:27:34 +02:00
b878f64793 add analytics support 2024-02-23 17:30:20 +02:00
4242e157ab Merge remote-tracking branch 'origin/main' into ok/analytics 2024-02-23 17:16:43 +02:00
Tal
6df2a6769e Update DESCRIBE.md 2024-02-22 22:03:39 +02:00
Tal
dadb760aae Merge pull request #696 from Codium-ai/tr/app_refactor
Refactor GitHup App
2024-02-22 09:28:44 -08:00
85492f20fa 'debug' for request body 2024-02-22 18:13:42 +02:00
8b76eb1014 fixed bugs with incremental review 2024-02-22 18:03:00 +02:00
adc5709b29 Refactor github_app.py to improve handling of PR events and comments 2024-02-22 17:34:51 +02:00
b884920ef2 Refactor github_app.py to improve handling of PR events and comments 2024-02-22 17:26:47 +02:00
4ebac16ff7 Add support for analytics file 2024-02-22 13:21:56 +02:00
ee59d34e39 Merge pull request #694 from Codium-ai/ok/title_regex
Adds an option to ignore PR opens by regex matching
2024-02-22 12:26:57 +02:00
e3dba12fea Adds an option to ignore PR opens by regex matching 2024-02-22 12:14:04 +02:00
Tal
42bcda1eb8 Merge pull request #687 from Codium-ai/tr/ado
Update README.md to include Azure DevOps in supported platforms
2024-02-21 11:10:51 -08:00
1b214114ec Update README.md to include Azure DevOps in supported platforms 2024-02-21 21:06:47 +02:00
Tal
764aa8d679 Merge pull request #686 from Codium-ai/tr/reduce_number_of_calls
Tr/reduce number of calls
2024-02-21 08:26:10 -08:00
4d0f691b64 repo_settings 2024-02-21 18:23:34 +02:00
048d90623f Ignore comment not starting with a slash 2024-02-21 17:59:58 +02:00
Tal
7c87c9d3a5 Merge pull request #685 from Codium-ai/tr/reduce_number_of_calls
repo_settings
2024-02-21 07:20:21 -08:00
8ffdaf00c1 repo_settings 2024-02-21 17:18:54 +02:00
Tal
a94b5c6682 Merge pull request #684 from Codium-ai/tr/reduce_number_of_calls
Tr/reduce number of calls
2024-02-21 07:05:00 -08:00
fc7b267c9a self.diff_files 2024-02-21 17:00:11 +02:00
e291bd352e protections 2024-02-21 16:46:57 +02:00
f08ce53de3 Optimize PR commit retrieval and caching in GitHub provider and utils 2024-02-21 16:33:32 +02:00
Tal
34797fe809 Merge pull request #683 from Codium-ai/tr/fixes
Tr/fixes
2024-02-21 01:11:40 -08:00
f3c1c61c2e readme 2024-02-21 11:11:03 +02:00
0f1614bedc readme 2024-02-21 11:10:03 +02:00
a41a427b58 readme 2024-02-21 11:08:08 +02:00
b1dfd905c4 text 2024-02-21 09:40:39 +02:00
dd5386e07e try-except 2024-02-21 09:27:40 +02:00
275f0d6a05 Update GitLab configuration and documentation for webhook setup 2024-02-21 09:20:28 +02:00
0e3417b4ab webhook 2024-02-21 08:55:59 +02:00
Tal
d0a86ab684 Merge pull request #682 from jfouchard/patch-2
Add a note about change the target for Gitlab install
2024-02-20 06:58:21 -08:00
1348a67cd2 Add more detail to the pr-agent url 2024-02-20 08:33:34 -05:00
7b98db20d5 Add a note about change the target for Gitlab install
This is just a minor documentation update about changing the target when building the Docker image for Gitlab.  While it's obvious in retrospect, if you jump straight to the Gitlab section of the document how this is supposed to work.  If you follow the directions exactly you run into [this issue](https://github.com/Codium-ai/pr-agent/issues/456)
2024-02-20 08:24:43 -05:00
Tal
a4467a5773 Merge pull request #679 from Codium-ai/tr/fixes
Refactor reaction handling in GitHub provider and update help text
2024-02-19 22:11:48 -08:00
4a0b12c036 Refactor reaction handling in GitHub provider and update help text in PR tools 2024-02-20 08:06:33 +02:00
Tal
6eca495801 Merge pull request #666 from yochail/yochail/support_azure_devops_managed_identity
Add Az Devops managed identity support
2024-02-19 21:44:23 -08:00
Tal
5c8160444a Merge pull request #678 from Codium-ai/tr/help_invoke
Tr/help invoke
2024-02-19 11:48:13 -08:00
82ba285395 finalize 2024-02-19 21:44:00 +02:00
2be0339a27 help improved 2024-02-19 21:42:13 +02:00
Tal
3e7f83ffdb Merge pull request #677 from Codium-ai/tr/help_invoke
help improved
2024-02-19 11:21:31 -08:00
8d6c6a35db help improved 2024-02-19 21:10:20 +02:00
34e89e45bd help improved 2024-02-19 21:07:24 +02:00
Tal
c3ff5c46a6 Merge pull request #676 from Codium-ai/tr/bitbucket_review_suggestions
bitbucket code suggestions
2024-02-19 09:55:14 -08:00
345f923569 bitbucket code suggestions 2024-02-19 19:52:49 +02:00
0f815876e5 bitbucket code suggestions 2024-02-19 19:46:57 +02:00
d47a840179 bitbucket code suggestions 2024-02-19 19:43:31 +02:00
3770704db7 reset commit 2024-02-19 08:35:45 -05:00
Tal
9cc147dda0 Merge pull request #675 from Codium-ai/hl/notification_readme
Update Usage.md
2024-02-19 04:10:34 -08:00
787b82d888 Update Usage.md 2024-02-19 14:07:46 +02:00
Tal
20483d63b7 Merge pull request #674 from Codium-ai/tr/help_command
Refactor PR help message and update related documentation
2024-02-18 22:35:32 -08:00
36aa22bd18 Refactor PR help message and update related documentation 2024-02-19 08:30:45 +02:00
Tal
d9775e6b8c Merge pull request #673 from Codium-ai/tr/help_command
Added PRHelpMessage to command execution in pr_agent.py
2024-02-18 03:16:36 -08:00
28e8707c1b Added PRHelpMessage to command execution in pr_agent.py 2024-02-18 13:16:07 +02:00
687ece1e86 Added PRHelpMessage to command execution in pr_agent.py 2024-02-18 13:09:17 +02:00
0515b80247 Added PRHelpMessage to command execution in pr_agent.py 2024-02-18 13:08:05 +02:00
ed5856493c Added PRHelpMessage to command execution in pr_agent.py 2024-02-18 13:06:57 +02:00
e9382b18b6 Added PRHelpMessage to command execution in pr_agent.py 2024-02-18 12:01:16 +02:00
Tal
a70e5c9e1f Update README.md 2024-02-18 09:57:34 +02:00
Tal
9991fde864 Merge pull request #669 from Codium-ai/tr/readme_18_2
readme
2024-02-17 22:27:51 -08:00
163132dd6d quotes 2024-02-18 08:25:30 +02:00
8b27559510 table 2024-02-18 08:22:59 +02:00
688cb374f6 lint 2024-02-18 08:19:01 +02:00
e821ba2a5b readme 2024-02-18 08:16:47 +02:00
d371bff0ba readme 2024-02-18 08:14:21 +02:00
Tal
7b15101051 Merge pull request #661 from Codium-ai/hl/ask_line
Hl/ask line
2024-02-17 22:08:55 -08:00
5918943959 readme 2024-02-18 08:07:12 +02:00
Tal
cd8a40c7a6 Merge pull request #665 from Codium-ai/tr/checks_readme
Update README and documentation with new CI Feedback tool
2024-02-17 22:04:59 -08:00
Tal
2b12042a85 Merge pull request #667 from Codium-ai/tr_ado
azure webhook
2024-02-17 22:01:57 -08:00
9e3b79b21b readme 2024-02-18 07:59:53 +02:00
c6cb0524b4 rstrip 2024-02-18 07:56:14 +02:00
481a4fe7a1 revert 2024-02-17 19:43:34 +02:00
de4af313ba azure dev ops 2024-02-17 19:40:06 +02:00
b402bd5591 revert azuredevops_provider.py change 2024-02-17 08:36:26 -05:00
cb3ebd9169 Update README and documentation with new CI Feedback tool 2024-02-16 20:40:45 +02:00
c98e736e3b added github action support 2024-02-16 14:49:01 +02:00
40fbd55da4 added github action support 2024-02-16 12:58:55 +02:00
3eef0a4ebd fix line selection, don't support line deletions 2024-02-15 22:21:58 +02:00
6712c0a7f8 remove unnecessary call 2024-02-15 21:43:25 +02:00
cfe794947d Gitlab /ask line works 2024-02-15 21:35:51 +02:00
24dd57e5b7 clean 2024-02-15 17:14:06 +02:00
8ed98c8a4f Add Documentation 2024-02-15 15:20:15 +02:00
fff52e9e26 Add ask line feature 2024-02-15 14:25:22 +02:00
4947c6b841 Merge pull request #660 from Codium-ai/ok/add_command_to_log
Add logging context to command execution in pr_agent.py
2024-02-15 12:27:25 +02:00
433b8d24b8 Add logging context to command execution in pr_agent.py 2024-02-15 12:13:56 +02:00
bd88c66717 Merge remote-tracking branch 'origin/main' 2024-02-15 08:45:25 +02:00
d2ad8b1dbd Refactor publish_persistent_comment method to include name parameter 2024-02-15 08:45:17 +02:00
1053fa84f6 rename azure_devops_server var 2024-02-13 22:27:07 -05:00
b833d63468 PR comment: change name to azure_devops_server 2024-02-13 22:25:52 -05:00
Tal
70b83bac78 Merge pull request #659 from Codium-ai/tr/bitbucket_review
no html bitbucket
2024-02-13 08:40:57 -08:00
54a989d30f no html bitbucket 2024-02-13 18:37:48 +02:00
480a890741 no html bitbucket 2024-02-13 18:33:22 +02:00
2f327c26e8 auto approve 2024-02-13 11:21:59 +02:00
9ff62dce08 Add legacy url support 2024-02-12 18:40:06 -05:00
e8c2ec034d Update azuredevops_server_webhook.py
fix returned HTTP status
2024-02-12 18:38:08 -05:00
bbd0d62c85 fix auto_describe key 2024-02-11 18:10:22 -05:00
8fa058ff7f add azure devops pat to secret template config 2024-02-11 18:06:56 -05:00
34378384da add get endpoint for container status 2024-02-11 17:59:02 -05:00
95344c7083 fix basic auth 2024-02-11 17:42:06 -05:00
bc38fad4db add support for auto events 2024-02-11 17:23:56 -05:00
076d8e7187 fix PR code suggestions 2024-02-11 17:17:25 -05:00
22d0c275d7 fix PR comments 2024-02-11 17:13:59 -05:00
a168defd28 clean readme 2024-02-11 17:09:09 -05:00
b7a522ed69 add docker file 2024-02-11 17:05:44 -05:00
86d4a31eef add docs 2024-02-11 17:02:14 -05:00
9a54be5414 add webhook support 2024-02-11 16:52:49 -05:00
Tal
d0958022a0 Merge pull request #649 from rajyan/patch-2
filter events to align with pr-agent's setting
2024-02-11 10:54:42 -08:00
Tal
ec2aab805d Merge pull request #650 from yochail/yocail/support_azure_inline_comment
Support Azure Inline Comment
2024-02-11 10:54:10 -08:00
47060ddcac fix PR comments
- added line position
- added try-catch per comment
2024-02-11 12:40:36 -05:00
Tal
60d6fecd37 Merge pull request #653 from Codium-ai/hl/loading_improve
add loading comment to /improve
2024-02-11 07:28:57 -08:00
Tal
bdbb101183 Merge pull request #655 from Codium-ai/ok/disclaimer
Add AI disclaimer fields to configuration.toml
2024-02-11 07:28:47 -08:00
8a677e07a2 Fix a typo 2024-02-11 16:39:38 +02:00
3f42bb6793 Add AI disclaimer fields to configuration.toml 2024-02-11 16:22:26 +02:00
3420c6cf79 update label to https://github.com/Codium-ai/pr-agent/pull/654 2024-02-11 23:21:58 +09:00
Tal
159e2f7dd6 Merge pull request #654 from rajyan/rajyan-patch-2
add pull_request event triggers for github action
2024-02-11 06:08:48 -08:00
67fde2c17e add pull_request event triggers for github action
https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
2024-02-11 21:21:20 +09:00
0e08520c0c match pr-pro 2024-02-11 13:21:59 +02:00
6c500413f1 default behavior for bitbucket 2024-02-11 13:14:47 +02:00
73d2b1565d Implement edit comment 2024-02-11 12:31:30 +02:00
a40643bbba add return response 2024-02-11 12:20:06 +02:00
d93a24bbf7 add loading comment to /improve 2024-02-11 12:14:25 +02:00
Tal
79dac3f419 Merge pull request #651 from Codium-ai/tr/br_inside_code
insert_br_after_x_chars can already handle code
2024-02-11 01:47:12 -08:00
c75413fac5 count_chars_without_html 2024-02-11 11:37:11 +02:00
4e386153ea insert_br_after_x_chars can already handle code 2024-02-11 11:32:16 +02:00
8800bad658 revamped 2024-02-11 11:00:12 +02:00
cfb576d1ae revamped 2024-02-11 10:58:13 +02:00
7c9b65ba65 prompts 2024-02-11 08:05:09 +02:00
ba854c228b Update azuredevops_provider.py 2024-02-10 22:36:01 -05:00
d8ea2731ea add support for azure inline commnets 2024-02-11 03:27:47 +00:00
078e87139a possible_issues 2024-02-09 21:34:07 +02:00
bf11033349 possible_issues 2024-02-09 21:27:22 +02:00
01fbebfc5e relevant tests 2024-02-09 12:50:51 +02:00
Tal
b660badd09 Merge pull request #646 from Codium-ai/hl/pr_review_table
Hl/pr review table
2024-02-09 01:49:59 -08:00
796e203c01 rstrip() 2024-02-09 11:45:12 +02:00
6837e43114 help 2024-02-09 11:30:28 +02:00
555151602f rstrip() 2024-02-09 11:26:43 +02:00
f74b35fb6f Merge remote-tracking branch 'origin/main' into hl/pr_review_table 2024-02-09 11:05:13 +02:00
f8e1bd3d4c get_pr_url 2024-02-09 11:02:23 +02:00
e01025706a filter events to align with pr-agent's setting 2024-02-09 17:45:29 +09:00
5af9e8e749 fix 2024-02-08 23:53:29 +02:00
24c575737c fix2 2024-02-08 23:05:56 +02:00
4175e8c467 fix test2 2024-02-08 20:49:42 +02:00
77e7463395 fix tests 2024-02-08 20:14:25 +02:00
2e1462580f s 2024-02-08 19:02:56 +02:00
fa077dc516 formatting 2024-02-08 18:55:58 +02:00
a3f4c44632 PR Review 2024-02-08 15:25:43 +02:00
4447110118 small fix 2024-02-08 14:35:39 +02:00
c2088b7752 Merge commit 'e4f177908b620e46740b03966fda9243473d979e' into hl/pr_review_table 2024-02-08 14:26:29 +02:00
ddb89a7474 New PR Reviewer with Table view 2024-02-08 14:26:14 +02:00
Tal
e4f177908b Merge pull request #644 from Codium-ai/tr/parallel_calls
Tr/parallel calls
2024-02-07 10:29:00 -08:00
b077873c3d parallel_calls 2024-02-07 08:00:16 +02:00
a7ce2b11b4 parallel_calls 2024-02-07 08:00:01 +02:00
Tal
ef1b0ce3e3 Merge pull request #643 from Codium-ai/hl/docs_add_table_trigger
DOCS: add table to files changes action
2024-02-06 21:32:25 -08:00
Tal
ea3a34be08 Update DESCRIBE.md 2024-02-07 07:31:21 +02:00
9a26ed7c43 Update DESCRIBE.md 2024-02-06 21:19:47 +02:00
5d81f31ccc Update DESCRIBE.md 2024-02-06 21:18:56 +02:00
Tal
92d2f484d2 Merge pull request #642 from Codium-ai/tr/readme
readme cleaning
2024-02-06 08:04:55 -08:00
91e77787c0 readme cleaning 2024-02-06 18:03:14 +02:00
Tal
034c654bac Update .pr_agent.toml 2024-02-06 17:47:14 +02:00
Tal
94e2f00c06 Merge pull request #641 from Codium-ai/tr/auto_approve
auto approval feature
2024-02-06 07:18:43 -08:00
2bc398f74e readme 2024-02-06 16:48:29 +02:00
1c9bd3e9a8 get_pr_url 2024-02-06 09:26:00 +02:00
8a04a4f481 auto approval 2024-02-06 09:12:52 +02:00
3e96812c5d Merge remote-tracking branch 'origin/main' into tr/auto_approve 2024-02-06 09:10:00 +02:00
b190b1879e auto approval 2024-02-06 09:09:07 +02:00
Tal
9d3e6620c1 Merge pull request #640 from Codium-ai/tr/publish_output
publish_output fix
2024-02-05 21:47:23 -08:00
Tal
4636c8a1fa Merge pull request #634 from Codium-ai/tr/secret_provider
protections for 'get_secret_provider'
2024-02-05 21:46:17 -08:00
3773303bfd publish_output fix 2024-02-06 07:44:20 +02:00
Tal
a126ef64fc Merge pull request #639 from Codium-ai/tr/describe_bullets
Tr/describe bullets
2024-02-05 05:55:25 -08:00
c1c7b3b6da fixed code 2024-02-05 13:00:57 +02:00
2b6e8c3f09 minor change 2024-02-05 12:39:03 +02:00
Tal
d4e78118fe Merge pull request #638 from Codium-ai/tr/describe_bullets
insert_br_after_x_chars
2024-02-05 02:06:13 -08:00
cce3c70369 - patch_extra_lines = 1
- describe is with turbo model (for larger context)
2024-02-05 12:03:30 +02:00
32e8ba331a insert_br_after_x_chars 2024-02-05 10:12:47 +02:00
3f2a7869dd insert_br_after_x_chars 2024-02-05 09:22:26 +02:00
2ee329674f insert_br_after_x_chars 2024-02-05 09:20:36 +02:00
e104bd7a3f large patch protection 2024-02-04 16:27:57 +02:00
3e128869dc large patch protection 2024-02-04 16:10:53 +02:00
cf2ed9d483 Merge remote-tracking branch 'origin/main' 2024-02-04 14:25:57 +02:00
e1b0e4a40a minor prompt changes 2024-02-04 14:24:55 +02:00
Tal
1013f7586b Merge pull request #637 from Codium-ai/tr/pr-actions
pr-actions
2024-02-02 04:21:33 -08:00
023f2eb77c pr-actions 2024-02-02 14:17:45 +02:00
Tal
cb8ff2b318 Merge pull request #636 from Codium-ai/tr/model_turbo
moving the 'improve' command to turbo mode, with auto_extended=true
2024-02-01 06:57:42 -08:00
d04d8b616a moving the 'improve' command to turbo mode, with auto_extended=true 2024-02-01 09:46:04 +02:00
Tal
2816cd2c4b Update README.md 2024-02-01 09:06:01 +02:00
2112defa51 lancedb bump 2024-02-01 08:44:23 +02:00
9579be028d protections for 'get_secret_provider' 2024-02-01 08:31:11 +02:00
Tal
7168326911 Update TOOLS_GUIDE.md 2024-01-30 08:22:29 +02:00
Tal
e1ae51e7a0 Update TOOLS_GUIDE.md 2024-01-30 08:21:43 +02:00
Tal
c69962479a Merge pull request #630 from Codium-ai/tr/language
Enhancements in Patch Formatting and Code Suggestions Handling
2024-01-29 12:11:23 -08:00
15c8fe94bb feat: Improve patch formatting and handle empty data in pr_code_suggestions.py 2024-01-29 22:00:11 +02:00
0d86779799 feat: Improve patch formatting and handle empty data in pr_code_suggestions.py 2024-01-29 21:52:54 +02:00
6565556e01 feat: Add 'language' field to CodeSuggestion, FileDescription, and ReviewerPrompt models in settings files 2024-01-29 20:51:24 +02:00
Tal
6998089549 Update README.md 2024-01-29 20:21:23 +02:00
8d36e2e2f7 feat: Add new configuration options in pr_test section and update TEST.md documentation 2024-01-29 20:17:39 +02:00
Tal
93f1854c68 Merge pull request #629 from Codium-ai/tr/tests
s
2024-01-29 01:43:46 -08:00
40a7ef9132 s 2024-01-29 11:42:32 +02:00
042eab1641 s 2024-01-29 11:39:50 +02:00
567b400f97 Revert "s1"
This reverts commit 412159bba5.
2024-01-29 11:30:58 +02:00
412159bba5 s1 2024-01-29 11:28:58 +02:00
Tal
e6f548920b Merge branch 'main' into tr/tests 2024-01-29 01:23:27 -08:00
f1fe2563f4 s 2024-01-29 11:22:46 +02:00
467e2ae68e s 2024-01-29 11:19:37 +02:00
78bb54bd8f s 2024-01-29 11:11:30 +02:00
Tal
2bebfba4b6 Update README.md 2024-01-28 20:39:45 +02:00
Tal
815073e04f Merge pull request #628 from Codium-ai/tr/tests
tests readme
2024-01-28 10:32:27 -08:00
5f1722ed4a s 2024-01-28 20:30:40 +02:00
47af04d158 s 2024-01-28 20:26:58 +02:00
Tal
335654b02a Update Usage.md 2024-01-27 21:38:25 +02:00
Tal
68e17ed2be Merge pull request #627 from Codium-ai/tr/updates2
Tr/updates2
2024-01-27 11:33:33 -08:00
ecb46435b3 s 2024-01-27 21:29:19 +02:00
98ce0a7036 s 2024-01-27 21:25:43 +02:00
76f44b13f8 docs: Update GitHub app configurations section in Usage.md 2024-01-27 21:20:10 +02:00
06dede29f2 feat: Update configuration and handling of GitHub Action settings 2024-01-27 21:15:23 +02:00
Tal
dbf5ebcb8d Merge pull request #622 from eltociear/fix-filename
docs: fix file name
2024-01-25 02:09:27 -08:00
Tal
d6a45663f1 Merge pull request #624 from Codium-ai/hl/small_fixes
small fixes
2024-01-25 02:09:04 -08:00
07eaa59e78 small fixes 2024-01-25 11:07:43 +02:00
1e2d4e9830 docs: fix file name 2024-01-25 15:03:58 +09:00
Tal
cc03f7f615 Merge pull request #620 from Codium-ai/tr/updates
Configuration updates
2024-01-24 09:59:43 -08:00
Tal
040da2fbb1 Merge pull request #612 from Codium-ai/mrT23-patch-1
Update README.md
2024-01-24 09:59:25 -08:00
Tal
a83a492b22 Merge branch 'main' into mrT23-patch-1 2024-01-24 09:58:23 -08:00
e056cd5988 type 2024-01-24 19:55:33 +02:00
4077c5556d enable_review_labels_effort set to true by default 2024-01-24 19:49:43 +02:00
d8465ea9f9 removed include_improved_code 2024-01-24 19:47:30 +02:00
f4037e0dfa feat: Add LanceDB support for similar_issue tool and refactor SOC2 compliance feature name 2024-01-24 19:40:58 +02:00
9986f5307c Merge pull request #618 from Codium-ai/hl/describe_usage_guide
Enhance Documentation for "Inline File Walkthrough" Feature
2024-01-24 10:15:21 +02:00
60c0371854 highlight options 2024-01-23 18:13:08 +02:00
139bbfc67a update docs and usage guide 2024-01-23 17:58:55 +02:00
b33b8c12cd Merge pull request #616 from Codium-ai/hl/walkthrough_title_ui_improvements
update default config for inline_file_summary to false
2024-01-22 10:37:02 +02:00
968684b461 update default config for inline_file_summary to false 2024-01-22 10:25:34 +02:00
Tal
4a5cff4995 Update CUSTOM_SUGGESTIONS.md 2024-01-21 17:58:01 +02:00
599c6773f3 Merge pull request #613 from Codium-ai/hl/walkthrough_title_ui_improvements
Add changes title of files and improve table style and alignments
2024-01-21 17:52:44 +02:00
Tal
7178ddac10 Update CUSTOM_SUGGESTIONS.md 2024-01-21 17:31:33 +02:00
Tal
5dedc381a6 Merge pull request #615 from Codium-ai/mrT23-patch-2
Update README.md
2024-01-21 07:30:14 -08:00
Tal
cba14ada2c Update README.md 2024-01-21 17:29:29 +02:00
Tal
f81fe0a12d Merge pull request #614 from Codium-ai/tr/custom_suggestions
feat: Add custom suggestions tool to README.md
2024-01-21 07:19:22 -08:00
78d886459a feat: Add custom suggestions tool to README.md 2024-01-21 17:15:34 +02:00
27aafb06cb feat: Add custom suggestions tool to README.md 2024-01-21 17:10:23 +02:00
329f7fa9d6 feat: Add custom suggestions tool to README.md 2024-01-21 17:06:25 +02:00
e79919b5c6 update describe screenshot to the new describe 2024-01-21 14:09:17 +02:00
8d513e078a Add changes title of files and improve table style and alignments 2024-01-21 13:43:37 +02:00
Tal
69f7923552 Update README.md 2024-01-20 13:02:07 +02:00
Tal
2430a1a608 Merge pull request #594 from Codium-ai/tr/fallback_bad_review_comment
Enhanced Comment Verification and Fallback Mechanism for Inline Comment Publishing
2024-01-20 02:04:06 -08:00
e54388d807 s 2024-01-20 11:59:45 +02:00
d942bdb8bd s 2024-01-20 11:56:17 +02:00
Tal
84d87aa870 Merge pull request #607 from Codium-ai/tr/edge_cases
feat: Improve error handling and code readability in pr_agent tools
2024-01-18 07:09:07 -08:00
39891e4ab1 feat: Improve error handling and code readability in pr_agent tools 2024-01-18 17:01:25 +02:00
d7858efbbe Merge pull request #581 from Codium-ai/sm/azure_devops
Enhancement of AzureDevopsProvider with new functionalities and refactoring
2024-01-18 16:28:28 +02:00
Tal
b3365b8d6c Merge pull request #605 from Codium-ai/tr/edge_cases
No suggestions found
2024-01-18 06:18:43 -08:00
fc5b00f4d3 s 2024-01-18 16:11:44 +02:00
Tal
5150e66723 Merge pull request #603 from Codium-ai/mrT23-patch-1
Update README.md
2024-01-17 22:21:44 -08:00
Tal
4dad1af77b Update README.md 2024-01-18 08:20:09 +02:00
Tal
02129b40cf Merge pull request #601 from Codium-ai/hl/diffview_file_summary
Readme Inline file summary 💎
2024-01-17 06:37:53 -08:00
3fb6d17338 width 2024-01-17 16:36:26 +02:00
3be7bfce79 feat: Add repository labels retrieval function in gitlab_provider.py
docs: Update links and add Inline file summary to TOC in DESCRIBE.md
2024-01-17 16:33:48 +02:00
472646ddfd Readme 2024-01-17 16:27:07 +02:00
eb4a1c515e Merge pull request #600 from Codium-ai/tr/improve_usage_guide
readme updates
2024-01-17 15:55:42 +02:00
e4af0b22ad s 2024-01-17 15:51:42 +02:00
a3e59a418e Merge remote-tracking branch 'origin/main' into tr/improve_usage_guide 2024-01-17 15:46:05 +02:00
4e833c0c28 s 2024-01-17 15:43:01 +02:00
Tal
0b811d97a7 Merge pull request #598 from Codium-ai/tr/improve_usage_guide
Enhancements to the 'improve' tool and updates to the related documentation
2024-01-17 03:13:33 -08:00
8f510dc553 s 2024-01-17 11:47:59 +02:00
2132771f46 s 2024-01-17 11:29:50 +02:00
e66bd7caa7 fallback to commitable 2024-01-17 11:18:30 +02:00
17ce2f0ed0 improve usage guide 2024-01-17 10:09:44 +02:00
7298548f82 improve usage guide 2024-01-17 10:06:27 +02:00
298c41a100 improve usage guide 2024-01-17 10:03:48 +02:00
58163e5129 improve usage guide 2024-01-17 09:50:48 +02:00
Tal
fae3bf6309 Merge pull request #590 from EduardDurech/patch-2
Fixed Run from source instructions for Python
2024-01-16 22:53:36 -08:00
06f0235577 Merge pull request #597 from Codium-ai/hl/improve_ui_table
Hl/improve UI table
2024-01-16 09:46:34 +02:00
d7e0aad527 small fixes 2024-01-16 09:41:31 +02:00
31576b77ff improve backticks 2024-01-15 19:07:41 +02:00
ea39e8684f works 2024-01-15 16:42:50 +02:00
afefc15b9c improve doce suggestions UI with difflib 2024-01-15 15:56:48 +02:00
5e17ccaf86 add colaplsable 2024-01-15 15:17:57 +02:00
9b1eb86d75 first iteration of improved UI for /improve --extended 2024-01-15 15:10:54 +02:00
9f5c2e5f17 feat: Refactor comment verification in github_provider.py 2024-01-14 11:55:07 +02:00
7377f4e4b2 feat: Refactor comment verification in github_provider.py 2024-01-14 11:49:51 +02:00
d6f4c1638d feat: Refactor comment verification in github_provider.py 2024-01-14 10:49:05 +02:00
a58c385b0f Fixed Rust warning tip as behaviour is inconsistent 2024-01-14 04:16:32 +01:00
7a3830d228 Fixed Run from source instructions for Python
Previously only installed dependencies but not pr_agent

+ Fixed link to OpenAI API Key and added for GitHub access token
2024-01-13 06:29:07 +01:00
Tal
e7251ada3f Merge pull request #588 from barnett-yuxiang/ignore-ds-store
Ignore .DS_Store files
2024-01-10 07:25:49 -08:00
aca3fcb571 Ignore .DS_Store files
This commit updates the .gitignore file to ignore .DS_Store files, which are created by macOS. These files are not relevant to the project and should not be included in version control.

Signed-off-by: Kamakura.Yx <barnett.yuxiang@gmail.com>
2024-01-10 23:13:57 +08:00
b9951fce62 Typo when parsing the suggestion part 2024-01-10 11:59:45 +02:00
Tal
609836bd6a Merge pull request #587 from Codium-ai/tr/abbrevations
Enhancement: Improve PR-Agent Tool with Custom Labels, Extra Instructions, and Summarize Mode
2024-01-09 23:39:04 -08:00
09ee0b64ba feat: Refactor instructions and fields in pr_code_suggestions_prompts.toml 2024-01-10 09:37:05 +02:00
Tal
fb4746fd09 Merge pull request #584 from samanhappy/link
Fix link formatting for relevant_line
2024-01-09 23:22:55 -08:00
729b5d11c9 feat: Refactor instructions and fields in pr_code_suggestions_prompts.toml 2024-01-09 22:56:25 +02:00
fc502a6fd5 feat: Refactor instructions and fields in pr_code_suggestions_prompts.toml 2024-01-09 22:49:26 +02:00
2b607dbd9a feat: Refactor instructions and fields in pr_code_suggestions_prompts.toml 2024-01-09 22:32:09 +02:00
9c6aabb0bb feat: Add custom labels and extra instructions sections to help.py, summarize mode to pr_code_suggestions.py, and summarize mode condition to pr_code_suggestions_prompts.toml 2024-01-09 22:09:48 +02:00
Tal
da3ac656ee Merge pull request #586 from Codium-ai/tr/ask_usage
ask helper
2024-01-09 06:55:30 -08:00
a42e57d09b ask helper 2024-01-09 16:36:39 +02:00
e56c443fd6 ask helper 2024-01-09 16:34:27 +02:00
abc05e7711 ask helper 2024-01-09 16:25:23 +02:00
Tal
a77d539866 Merge pull request #585 from samanhappy/url
Enhancement: Update GitLab link generation to support self-managed GitLab server and different projects
2024-01-09 06:12:05 -08:00
19c14b940e Try fixing invalid inline comments 2024-01-09 09:54:29 +02:00
36f1cfb51f Enhancement: Update GitLab link generation to support self-managed GitLab server and different projects 2024-01-09 15:11:27 +08:00
0f2a4654a7 Fix link formatting for relevant_line 2024-01-09 14:56:18 +08:00
28c5ad1d8b nit 2024-01-08 13:06:03 +02:00
2bb5ae8c0d Remove redundant condition (status 422 already means the same) 2024-01-08 13:05:10 +02:00
b0bffdec84 Refactor and add configuration toggle 2024-01-08 12:00:20 +02:00
Tal
11b96b1c1a Merge pull request #583 from Codium-ai/tr/unique_titles
feat: Remove bot help text from github_polling.py
2024-01-08 01:51:43 -08:00
e0f4bc7ded feat: Remove bot help text from github_polling.py 2024-01-08 11:45:01 +02:00
Tal
62d83f6753 Merge pull request #582 from Codium-ai/tr/unique_titles
Enhance PR description headers with bold formatting and include original user description
2024-01-08 01:28:56 -08:00
e9a2a0a96f s 2024-01-08 10:37:51 +02:00
46a38473e4 Merge remote-tracking branch 'origin/main' into tr/unique_titles 2024-01-08 10:30:58 +02:00
c9e55be275 s 2024-01-08 10:30:47 +02:00
Tal
f714592dec Merge pull request #579 from Codium-ai/tr/user_description
Enhancements to Logging, Help Messages, and PR Descriptions and Reviews
2024-01-07 23:46:25 -08:00
8bb2eb48af s 2024-01-08 09:43:34 +02:00
9cfb8ce475 s 2024-01-08 09:39:19 +02:00
67cb133c52 s 2024-01-08 09:28:44 +02:00
9c054bb80f s 2024-01-08 09:18:46 +02:00
b776e5069c feat: Refactor AzureDevopsProvider class in azuredevops_provider.py
- Reorder class methods and constructor for better readability
- Add error logging for failed operations
- Implement get_pr_description_full method
- Update get_pr_description method to always return full description
- Modify _parse_pr_url method to return workspace_slug, repo_slug, and pr_number
- Make _get_azure_devops_client a static method
- Add error handling in get_pr_id method
2024-01-08 09:15:34 +02:00
c8bca487e5 feat: Implement methods in AzureDevopsProvider for publishing code suggestions, labels, and removing comments 2024-01-08 08:59:12 +02:00
Tal
78fa61eac6 Merge branch 'main' into tr/user_description 2024-01-07 22:55:18 -08:00
Tal
582cbd623f Merge pull request #580 from Codium-ai/tr/add_logs
feat: Add debug logs to git_provider and pr_description modules
2024-01-07 09:58:20 -08:00
3ea08a6cf5 feat: Add debug logs to git_provider and pr_description modules 2024-01-07 19:57:49 +02:00
3154ebbf9f feat: Add debug logs to git_provider and pr_description modules 2024-01-07 19:56:05 +02:00
Tal
8fe608884d Merge pull request #578 from Codium-ai/ok/atlassian_version
feat: Update atlassian-python-api version in requirements.txt
2024-01-07 09:17:56 -08:00
60e79f0134 feat: Update atlassian-python-api version in requirements.txt 2024-01-07 18:08:11 +02:00
a6bbd04efb s 2024-01-07 17:02:18 +02:00
578d15c6fc usage guide 2024-01-07 16:38:08 +02:00
22d17985a1 Less noisy fallback for publish_code_suggestions in case of invalid comments
As a first option, `publish_code_suggestions` will try to post all review comments in a single GitHub review. This is preferred because it will group all comments together in the GitHub UI under the same review, and will trigger just one notification for any viewers of the PR.

If just one of the comments is malformed, the entire API request will fail and none of the comments will be posted to the PR. In the current implementation, the fallback mechanism is to just post each comment separately with `try/except` and skip the invalid comments. This works, but potentially creates a lot of noise in the PR as each comment is posted as in a separate review, creating multiple notifications.

This suggested fallback is based on a similar idea, but without creating multiple review notifications. The it works is by iterating over the potential comments, and starting a PENDING review for the current comment. The review is not submitted and does not trigger a notification, but it is verified against the GitHub API, and so we can verify if the comment is valid. After checking all comments we then submit a single review with all the verified comments which is guaranteed to succeed.

The end result is having the exact same comments posted to the PR as with the current fallback method, but the downside is having twice as many API calls (for each comment we have 1 extra API call to delete the pending review).
2024-01-07 16:00:44 +02:00
Tal
faba5a224a Merge pull request #575 from Codium-ai/tr/user_description
docs: Enhance 'improve' tool documentation and update 'DESCRIBE.md' w…
2024-01-07 01:30:44 -08:00
19f85f08b0 docs: Enhance 'improve' tool documentation and update 'DESCRIBE.md' with hyperlink 2024-01-07 11:29:07 +02:00
8512e9dffb docs: Enhance 'improve' tool documentation and update 'DESCRIBE.md' with hyperlink 2024-01-07 11:26:24 +02:00
7c0be8ca44 docs: Enhance 'improve' tool documentation and update 'DESCRIBE.md' with hyperlink 2024-01-07 11:22:53 +02:00
d9872d7031 docs: Enhance 'improve' tool documentation and update 'DESCRIBE.md' with hyperlink 2024-01-07 11:19:47 +02:00
Tal
be4b9c4991 Merge pull request #574 from Codium-ai/tr/user_description
Enhance and reorganize documentation for review and describe tools
2024-01-07 00:01:30 -08:00
94172104f0 docs: Reorganize and enhance documentation for review and describe tools 2024-01-07 09:56:09 +02:00
8ec790d4f7 Merge remote-tracking branch 'origin/main' into tr/user_description
# Conflicts:
#	docs/DESCRIBE.md
2024-01-07 09:49:43 +02:00
640972b00a docs: Reorganize and enhance documentation for review and describe tools 2024-01-07 09:48:17 +02:00
7810ba7d76 docs: Reorganize and enhance documentation for review and describe tools 2024-01-07 09:40:24 +02:00
d91f1fce09 docs: Reorganize and enhance documentation for review and describe tools 2024-01-07 09:36:03 +02:00
edcb666fbc docs: Reorganize and enhance documentation for review and describe tools 2024-01-07 09:28:06 +02:00
Tal
6d359fe1d8 Update DESCRIBE.md 2024-01-06 21:46:11 +02:00
Tal
19e38595f3 Merge pull request #573 from Codium-ai/tr/user_description
feat: Update adaptive collapsible file list logic in pr_description.py
2024-01-06 11:08:55 -08:00
355ef8c476 feat: Update adaptive collapsible file list logic in pr_description.py 2024-01-06 10:36:36 +02:00
Tal
f08d225360 Merge pull request #572 from Codium-ai/tr/user_description
describe docs
2024-01-06 00:15:36 -08:00
22b7dd9f2d s 2024-01-06 10:15:04 +02:00
a85a328791 s 2024-01-06 10:08:29 +02:00
82d10f24f0 s 2024-01-06 10:04:48 +02:00
Tal
c9717f1d73 Update README.md 2024-01-05 23:29:59 +02:00
Tal
82b58d5b09 Update README.md 2024-01-05 21:37:45 +02:00
Tal
b6d41d6a91 Merge pull request #571 from Codium-ai/tr/user_description
Enhance Documentation and Configuration of 'describe' Tool
2024-01-05 11:30:41 -08:00
ac74fa8431 docs 2024-01-05 21:28:54 +02:00
42704d5781 Merge remote-tracking branch 'origin/main' into tr/user_description 2024-01-05 17:03:30 +02:00
3628786a61 feat: Clarify PRType label member usage in pr_description_prompts.toml 2024-01-05 17:03:14 +02:00
Tal
c69ede0138 Update REVIEW.md 2024-01-05 11:10:55 +02:00
Tal
4349156e97 Merge pull request #570 from wesvetter/patch-1
📚 Minor update to REVIEW.md for inclusive language
2024-01-04 22:48:36 -08:00
9f88105f72 📚 Minor update to REVIEW.md for inclusive language
Replaces "his [judgement]" with "their".
2024-01-04 10:32:53 -08:00
Tal
fe6b2065fb Merge pull request #569 from zmeir/zmeir/enhance/auto_improve_extended_simple
Add toggle to automatically enable `/improve --extended`
2024-01-04 09:06:08 -08:00
c2b0891c0b Simpler auto-extended toggle and keep the default as false 2024-01-04 18:53:45 +02:00
Tal
782f1ca1bd Merge pull request #568 from Codium-ai/tr/user_description
Enhancement: Improved Extraction and Placement of User Descriptions in PRs
2024-01-04 08:35:34 -08:00
6d18a0c843 feat: Improve user description extraction in git_provider.py 2024-01-04 18:34:00 +02:00
Tal
e6093cd768 Merge pull request #567 from zmeir/zmeir/enhance/support_azure_in_langchain_ai_handler
Add support for Azure OpenAI in LangChainOpenAIHandler
2024-01-04 08:22:01 -08:00
Tal
aea0c4d45f Merge pull request #566 from zmeir/zmeir/fix/config_command_missing_arg
Fix failing `/config` command
2024-01-04 08:14:29 -08:00
1c2bb2ef3d feat: Update user description extraction and placement in PR description 2024-01-04 18:05:28 +02:00
7762bf59bf feat: Update user description extraction and placement in PR description 2024-01-04 18:01:55 +02:00
3e29848cd0 Merge remote-tracking branch 'origin/main' into tr/user_description
# Conflicts:
#	pr_agent/git_providers/git_provider.py
2024-01-04 17:49:10 +02:00
c3b5aaf8cc feat: Update user description extraction and placement in PR description 2024-01-04 17:46:24 +02:00
ba3f22d81e Move logging to a central location for all AI Handlers 2024-01-04 16:22:22 +02:00
ac7aaa0cd3 Add support for Azure OpenAI in LangChainOpenAIHandler 2024-01-04 16:22:22 +02:00
1ade09eaa3 Fix failing /config command
All commands need the `ai_handler` argument. The PRConfig class was missing it in the `__init__` method and so it failed with this error:

```
File "/home/vcap/app/pr_agent/agent/pr_agent.py", line 76, in handle_request
    await command2class[action](pr_url, ai_handler=self.ai_handler, args=args).run()
TypeError: PRConfig.__init__() got an unexpected keyword argument 'ai_handler'
```
2024-01-04 14:49:34 +02:00
Tal
b7af45166a Merge pull request #561 from zmeir/zmeir/fix/get_user_description
Fix `get_user_description`
2024-01-04 00:40:08 -08:00
Tal
92f89e6ca0 Merge pull request #565 from Codium-ai/tr/remove_old_walkthrough
Remove old 'enable_file_walkthrough' mode
2024-01-04 00:36:05 -08:00
ed78bfd946 use_collapsible_file_list 2024-01-04 10:27:07 +02:00
4204d78d7e feat: Remove file walkthrough feature from PR agent 2024-01-04 09:59:44 +02:00
3c2ed8bbf1 feat: Remove file walkthrough feature from PR agent 2024-01-04 09:42:15 +02:00
8d2da74380 Find user description in a case-insensitive way 2024-01-04 09:41:55 +02:00
39c1866121 Revert title() to capitalize() 2024-01-04 09:41:24 +02:00
Tal
1bba0162f8 Merge pull request #563 from zmeir/zmeir/enhance/refine_add_docs_prompt
Refine the prompt for `add_docs` command
2024-01-03 23:14:27 -08:00
Tal
c07ea5ea32 Merge pull request #560 from zmeir/zmeir/fix/drop_python3.9
Drop support for python 3.9
2024-01-03 23:09:54 -08:00
2f9fbbf0ac Prevent reducing the number of suggestions if already low enough 2024-01-03 16:43:39 +02:00
0189e12fb1 Automatically enable improve extended mode for large PRs 2024-01-03 16:43:38 +02:00
58f93e0615 Drop support for python 3.9
The `bitbucket_server_provider.py` uses structural pattern matching that was introduced in python 3.10, and so trying to run any command with python 3.9 will fail (because we import all the providers right at the top of `pr_agent.git_providers`)
2024-01-03 12:30:09 +02:00
967494ce17 Refine the prompt for add_docs command
I found that without it, python docstrings are sometimes suggested above the function signature, instead of below.
2024-01-03 12:27:23 +02:00
560d30dbb1 Fix get_user_description
The headers changed from "PR Type"/"PR Description"/etc to "Type"/"Description"/etc
2024-01-03 12:20:51 +02:00
Tal
c31ce3de35 Merge pull request #559 from pzarfos/fix/prompt-spelling
feat: Fix typo
2024-01-02 21:41:34 -08:00
0bd2f045a3 feat: Fix typo 2024-01-02 08:11:31 -05:00
Tal
0b4a98b3aa Merge pull request #558 from Codium-ai/tr/soc2_ticket
feat: Add SOC2 compliance review feature to PR agent 💎
2024-01-01 22:02:22 -08:00
7dfc306e7c feat: Add SOC2 compliance review feature to PR agent 2024-01-01 20:15:36 +02:00
Tal
be88624e2a Merge pull request #556 from Codium-ai/mrT23-patch-1
Update Usage.md
2023-12-31 07:35:40 -08:00
Tal
ac9a46d4c4 Update Usage.md 2023-12-31 17:34:13 +02:00
3e1349ed1f Merge pull request #554 from xens/patch-1
fix: missing flag in INSTALL.md
2023-12-28 10:29:14 -08:00
0d89e6e760 fix: missing flag in INSTALL.md
Fixing a missing flag on the Docker cli to declare a variable.
2023-12-28 17:24:08 +01:00
a9c8fb6a73 Merge pull request #552 from KennyDizi/main
Add `enable_help_text` setting and update PR review preparation method
2023-12-26 21:45:21 -08:00
fce52a66ff feat: Update enable_help_text flag explaination 2023-12-27 10:22:43 +07:00
dff31ff8f5 feat: Fix typo 2023-12-27 10:17:56 +07:00
37b040b50a Use 'and' in lieu of '&' operator 2023-12-27 10:17:08 +07:00
31168cd7de Get PR review enable help text from setting 2023-12-27 10:12:41 +07:00
db6ca434ac Update Usage.md 2023-12-26 17:15:48 +02:00
958bfe1000 Merge pull request #551 from Codium-ai/tr/global_configuration
global configuration
2023-12-26 07:08:52 -08:00
815862e428 markdown 2023-12-26 17:06:29 +02:00
b1ce29e27a global configuration 2023-12-26 16:45:39 +02:00
f7c2b3128f Merge pull request #550 from Codium-ai/tr/gfm_markdown
feat: Refactor help text addition in pr_reviewer.py and update tool n…
2023-12-25 23:30:36 -08:00
a6764c9058 feat: Update help text addition condition in pr_reviewer.py 2023-12-26 09:25:15 +02:00
a854e1a408 feat: Refactor help text addition in pr_reviewer.py and update tool names in README.md 2023-12-26 09:18:38 +02:00
ba3a8b24f0 Merge pull request #548 from PrashantDixit0/main
LanceDB Integration
2023-12-25 06:39:11 -08:00
26cb85c4f5 default pinecone 2023-12-25 14:50:15 +05:30
1d435ef3fa removed comments 2023-12-25 00:45:24 +05:30
1632696c2f Merge branch 'main' of github.com:PrashantDixit0/pr-agent 2023-12-25 00:41:28 +05:30
d8d954bb0f lancedb integration 2023-12-25 00:38:24 +05:30
08e9a91021 Merge pull request #547 from Codium-ai/tr/readme_update
Readme for PR-Agent-Pro
2023-12-24 06:30:04 -08:00
648c22ed1e tools update 2023-12-24 16:22:45 +02:00
49592ba2d7 docs: Refine markdown formatting in Analyze.md and README.md 2023-12-24 16:21:41 +02:00
0c4d451d9a readme 2023-12-24 16:18:20 +02:00
e698c7e2f3 Merge pull request #546 from Codium-ai/tr/backticks_review
Single-label for suggestions
2023-12-24 03:35:49 -08:00
663632e2d9 fixed bug 2023-12-24 10:27:48 +02:00
5fd3fdfae1 feat: Add loop to populate suggestion_list in pr_code_suggestions.py 2023-12-24 10:08:36 +02:00
47b267a73d prompt 2023-12-24 09:52:59 +02:00
5c49ff216a feat: Update inline comment creation in git providers and improve code suggestion handling
- Update `create_inline_comment` method in various git providers to include `absolute_position` parameter
- Remove `create_inline_comment` method from providers that do not support inline comments
- Enhance `find_line_number_of_relevant_line_in_file` function to handle absolute position
- Modify `pr_code_suggestions.py` to handle improved code inclusion in suggestions
- Add `include_improved_code` configuration option in `configuration.toml` and update documentation accordingly
2023-12-24 09:44:08 +02:00
5dc2595dcf feat: Refactor code suggestion handling and update YAML schema in pr_code_suggestions.py and pr_code_suggestions_prompts.toml
- Update key names in pr_code_suggestions.py to use snake_case for consistency
- Implement removal of invalid suggestions where existing code is equal to improved code
- Update YAML parsing in _prepare_pr_code_suggestions method to include keys_fix_yaml parameter
- Refactor push_inline_code_suggestions method to use updated key names
- Update _prepare_prediction_extended method to use new key names
- Refactor _prepare_markdown method to include suggestion label and use updated key names
- Update instructions and YAML schema in pr_code_suggestions_prompts.toml to reflect changes in pr_code_suggestions.py
- Remove redundant removal of invalid suggestions in rank_suggestions method
2023-12-24 08:30:35 +02:00
664b1c9d17 Merge pull request #545 from Codium-ai/tr/backticks_review
feat: Improve suggestion formatting in markdown text generation
2023-12-23 10:41:17 -08:00
ba7781ba00 feat: Update instruction formatting in pr_code_suggestions_prompts.toml and pr_reviewer_prompts.toml 2023-12-23 20:40:30 +02:00
42be96a99b feat: Improve suggestion formatting in markdown text generation 2023-12-23 20:32:03 +02:00
64a2c55d48 Merge pull request #542 from Codium-ai/tr/title_last
Enhancement: Update PR description prompts and reorder keys in PR description data
2023-12-21 03:55:17 -08:00
eca8078071 feat: Reorder keys in PR description data and update PRDescription model in toml file 2023-12-21 08:51:57 +02:00
9995ccd4c7 feat: Update PR description prompts in toml file to include semantic file types and custom labels options 2023-12-21 08:31:54 +02:00
851c001aa5 Merge pull request #541 from Codium-ai/tr/changes
feat: Enhance YAML parsing with additional fallbacks and key customiz…
2023-12-20 22:26:15 -08:00
2b23700aec feat: Enhance YAML parsing with additional fallbacks and key customization in load_yaml and try_fix_yaml functions 2023-12-21 08:24:07 +02:00
553dad0bee feat: Enhance YAML parsing with additional fallbacks and key customization in load_yaml and try_fix_yaml functions 2023-12-21 08:21:34 +02:00
37259e550f Merge pull request #540 from Codium-ai/tr/backticks
Enhancement of PR Description Formatting and Instructions Update
2023-12-20 22:16:53 -08:00
66cbd6ef8f Merge pull request #537 from koid/feature/ignore-header-description-in-ai-response
Enhancement of AI Response Parsing Mechanism
2023-12-20 22:15:43 -08:00
a9d789978b fix: remove last line 2023-12-21 11:11:46 +09:00
f99862088e re-implemented test case 2023-12-21 11:09:25 +09:00
e2797ad09a re-implemented YAML extraction as a fallback 2023-12-21 11:06:41 +09:00
ccb116922f Merge pull request #529 from lukefx/bitbucket_webhook_improvements
feat: Improved server, security and commands
2023-12-20 17:27:06 +02:00
c079deba21 feat: Enhance PR description formatting and update instructions in pr_description_prompts.toml 2023-12-20 16:45:21 +02:00
16b61eb4e8 ignore header description in ai response 2023-12-20 11:50:27 +09:00
68c26b362b Merge pull request #533 from Codium-ai/hl/fix_incomplete_yaml
bug fix
2023-12-18 10:07:07 -08:00
6e63cf4014 Add log 2023-12-18 17:35:04 +02:00
c59e9f77a6 fix 2023-12-18 17:06:02 +02:00
2a3779776a Merge pull request #532 from Codium-ai/hl/native_labels_readme
Hl/native labels readme
2023-12-18 16:12:38 +02:00
e25980f141 fix: using the same get_settings convention 2023-12-18 14:58:25 +01:00
6c80fde6df fix 2023-12-18 13:44:37 +02:00
75dcb035a7 Update 2023-12-18 13:41:50 +02:00
2ac86f429f Merge pull request #531 from Codium-ai/disable_github_action
Update pr-agent-review.yaml
2023-12-18 13:39:09 +02:00
9d2003d789 Update pr-agent-review.yaml 2023-12-18 13:38:06 +02:00
d2aef95847 Merge pull request #530 from Codium-ai/tr/labels
Enhancement: Implement label case conversion and update label descriptions in settings files
2023-12-18 03:21:48 -08:00
1c4e64333c feat: Implement label case conversion and update label descriptions in settings files 2023-12-18 12:29:06 +02:00
f121a420c9 Add to describe 2023-12-18 10:08:29 +02:00
3b13738943 Add docs to custom labels page 2023-12-18 10:04:05 +02:00
7a5acb29ac feat: Improved server, security and commands
Signed-off-by: Luca Simone <info@lucasimone.info>
2023-12-17 17:38:27 +01:00
ce35addcd3 Merge pull request #528 from Codium-ai/tr/lazy_init
Refactor AI handler instantiation to use lazy initialization in PR tools
2023-12-17 07:01:24 -08:00
5fb373b212 Refactor AI handler instantiation to use lazy initialization in PR tools 2023-12-17 16:52:03 +02:00
54891ad1d2 Merge pull request #514 from brianpham93/abstract-BaseAiHandler
Abstract AiHandler to BaseAiHandler
2023-12-14 07:54:13 -08:00
02871b1e3d Remove logging from pr_agent.py and add line breaks in cli.py and github_action_runner.py 2023-12-14 09:08:47 +02:00
38ea9143f3 Make LangChain dependency optional in pr-agent and update requirements.txt 2023-12-14 09:05:53 +02:00
246be6147f Set LiteLLMAIHandler as default AI handler in all PR tools and simplify AI handler injection in PRAgent 2023-12-14 09:00:14 +02:00
3531016a2c Refactor AI handler instantiation in PRAgent and related classes 2023-12-14 08:53:22 +02:00
e37598fdca Merge remote-tracking branch 'upstream/main' into abstract-BaseAiHandler 2023-12-14 07:45:43 +08:00
557b39ec87 Merge branch 'base-ai-handler' into abstract-BaseAiHandler 2023-12-14 07:44:13 +08:00
69a7c77a0d Refactor PRAgent class and has_ai_handler_param
method

This commit refactors the PRAgent class and the has_ai_handler_param
method. The has_ai_handler_param method is moved outside the class and
made a standalone function. This change improves code organization and
readability. The has_ai_handler_param function now takes a class object
as a parameter and checks if the class constructor has an "ai_handler"
parameter. This refactoring is done to streamline the code and improve
its maintainability.

No issue references.
2023-12-14 07:15:56 +08:00
2a8c2e488a Merge pull request #524 from Codium-ai/hl/native_labels_gitlab
feat: Add repository labels retrieval function in gitlab_provider.py
2023-12-13 17:36:18 +02:00
89c30ab5dc feat: Add repository labels retrieval function in gitlab_provider.py 2023-12-13 17:21:58 +02:00
ebb2ed891b Add logging to pr_agent.py 2023-12-13 08:16:45 +08:00
be8d6af87f Add code documentation generation for PR diffs 2023-12-13 08:16:31 +08:00
8fb4a42ef1 Update AI handler instantiation in server files 2023-12-13 08:16:02 +08:00
ca1ccd7b91 update base 2023-12-12 23:56:20 +08:00
b7225cc674 update langchain 2023-12-12 23:52:50 +08:00
a627dcd64f Update langchain 2023-12-12 23:28:58 +08:00
0c66554d50 langchain: move model and temperature to chat_completion 2023-12-12 23:07:46 +08:00
506eafc0c5 add langchain in requirement 2023-12-12 23:04:01 +08:00
6c7beccb4f add LangChain AI Handler 2023-12-12 23:03:49 +08:00
7eb2e769cf Move ai handlers to specific folder 2023-12-12 23:03:38 +08:00
5239e1c3e9 Load default AI Handler from util function 2023-12-12 21:51:05 +08:00
648dd3299f Merge pull request #521 from Codium-ai/tr/bitbucket_app
feat: Enable PR description publishing as comment in bitbucket_app.py
2023-12-12 00:27:48 -08:00
77a6fafdfc feat: Update Usage.md with limitations of bitbucket platform in auto_describe tool usage 2023-12-12 10:26:09 +02:00
ea7511e3c8 feat: Update Usage.md with limitations of bitbucket platform in auto_describe tool usage 2023-12-12 10:23:37 +02:00
512c92fe51 feat: Enable PR description publishing as comment in bitbucket_app.py 2023-12-12 10:19:17 +02:00
1853b4ef47 Merge pull request #520 from Codium-ai/tr/bitbucket_app
Refactor auto tool execution order and enhance logging and documentation
2023-12-12 00:02:02 -08:00
2f10b4f3c5 feat: Refactor auto tool execution order in bitbucket_app.py, add logging in pr_description.py, and update tool configuration instructions in Usage.md 2023-12-12 09:59:26 +02:00
73a20076eb Merge pull request #519 from Codium-ai/tr/bitbucket_app
Enhancement: Automatic Tool Configuration for Bitbucket App
2023-12-11 23:26:30 -08:00
afb633811f remove bad default 2023-12-12 09:18:51 +02:00
81da328ae3 feat: Add automatic tool configuration for Bitbucket app in bitbucket_app.py and configuration.toml, update Usage.md 2023-12-12 08:06:20 +02:00
729f5e9c8e Merge pull request #518 from Codium-ai/hl/github_native_labels
Refactoring Label Handling Across Git Providers
2023-12-11 16:50:19 +02:00
fdc776887d Refactor labels 2023-12-11 16:47:38 +02:00
cb64f92cce Merge pull request #511 from Codium-ai/tr/local_settings_on_push
Enhancement: Apply Repository Settings on Every 'Synchronize' Event
2023-12-11 06:27:29 -08:00
f3ad0e1d2a Merge pull request #517 from Codium-ai/tr/main_tmp
Improve PR description formatting and handling in pr_description.py
2023-12-11 06:15:46 -08:00
480e2ee678 feat: Improve PR description formatting in pr_description.py 2023-12-11 15:55:04 +02:00
9b97073174 s 2023-12-11 12:00:44 +02:00
4271bb7e52 Merge pull request #516 from Codium-ai/coditamar-readme-clarifications
Refine README.md for clarity and precision
2023-12-11 01:53:46 -08:00
e9bf8574a8 Update README.md 2023-12-11 11:52:36 +02:00
ebf7027aab add openai handler 2023-12-11 17:49:20 +08:00
a1cbd80b2a update base ai handler 2023-12-11 17:49:09 +08:00
2ce4af16cb Update README.md
fix grammar according to PR-Agent suggestions
2023-12-11 11:10:27 +02:00
2c1dfe7f3f Update README.md 2023-12-11 10:58:30 +02:00
b8021d7ca3 rename file 2023-12-11 16:57:23 +08:00
523a896465 Rename AiHandler to LiteLLMAiHandler 2023-12-11 16:56:49 +08:00
f7a6348401 Merge pull request #515 from Codium-ai/tr/review_graphics
Enhancement of Code Feedback Formatting in utils.py
2023-12-10 22:37:18 -08:00
02c0c89b13 feat: Add exception handling for discussion creation in gitlab_provider.py 2023-12-11 08:29:09 +02:00
b8cc110cbe s 2023-12-10 19:51:08 +02:00
2b1e841ef1 s 2023-12-10 19:45:54 +02:00
a247fc3263 s 2023-12-10 17:46:49 +02:00
654938f27c feat: Enhance code feedback formatting in utils.py 2023-12-10 17:30:27 +02:00
b6409929d2 Remove extra code 2023-12-09 16:51:50 +00:00
c0303ff9ec Merge remote-tracking branch 'upstream/main' into abstract-BaseAiHandler 2023-12-09 16:47:13 +00:00
f2abe5c73e Abstract AiHandler to BaseAiHandler 2023-12-09 16:39:25 +00:00
7e47baa9db Refactor AI handler classes 2023-12-10 00:25:25 +08:00
a7a0de764c Merge pull request #512 from Codium-ai/trlabeling_files_extended
Refactoring and Enhancement of PR Description Formatting in 'pr_description.py'
2023-12-07 05:38:37 -08:00
1b22e59b4b feat: Update RELEASE_NOTES.md with version 0.11 details 2023-12-07 15:35:48 +02:00
f908d02ab4 readme 2023-12-07 15:26:36 +02:00
7d2a35e32c final commit 2023-12-07 10:27:19 +02:00
e351428848 s 2023-12-07 10:24:36 +02:00
4cd6649a44 feat: Enhance PR description formatting in pr_description.py
Improve the table structure for relevant files in PR description by adjusting the header and filename display. Add padding for filename and change summary, and move diff_plus_minus to a separate column. Refactor _insert_br_after_x_chars function to accept a variable length parameter.
2023-12-07 10:14:18 +02:00
e62acef6d2 s1 2023-12-07 09:50:36 +02:00
a043eb939b feat: Apply repo settings on push trigger in github_app.py 2023-12-07 08:42:18 +02:00
73eafa2c3d Merge pull request #509 from Codium-ai/trlabeling_files_extended
Enhancement of PR Description and Labeling Features
2023-12-06 07:05:22 -08:00
a61e492fe1 feat: Refactor PR files processing into separate function in pr_description.py 2023-12-06 17:01:21 +02:00
243f0f2b21 Update INSTALL.md 2023-12-06 16:52:47 +02:00
93b6d31505 s 2023-12-06 16:36:27 +02:00
429aed04b1 s 2023-12-06 16:32:53 +02:00
eeb20b055a feat: Add line count to file patch info and enhance PR description formatting 2023-12-06 15:29:45 +02:00
4b073b32a5 feat: Enhance PR description with file label dictionary and update prompts in pr_description_prompts.toml 2023-12-06 12:30:51 +02:00
f629755a9a feat: Refine field descriptions in pr_description_prompts.toml for semantic file labels 2023-12-06 10:59:44 +02:00
c1ed3ee511 feat: Refine field descriptions in pr_description_prompts.toml for semantic file labels 2023-12-06 08:08:01 +02:00
a4e6c99c82 Merge branch 'main' into hl/labeling_files 2023-12-05 08:28:59 -08:00
0b70e07b8c feat: Improve formatting in help.py command descriptions 2023-12-05 18:26:35 +02:00
862c236076 s 2023-12-05 18:10:13 +02:00
5c2f81a928 Merge pull request #508 from Codium-ai/trt/fix_describe
docs: Update issue link in INSTALL.md and enhance key formatting in p…
2023-12-05 07:01:07 -08:00
b76bc390f1 Merge pull request #503 from pzarfos/python312
Update dependencies in requirements.txt for Python 3.12
2023-12-05 06:55:19 -08:00
25d1e84b7f docs: Update issue link in INSTALL.md and enhance key formatting in pr_description.py 2023-12-05 16:54:18 +02:00
70a409abf1 Merge pull request #450 from koid/fix/specify-cache-directory-in-azure-devops
Specify Cache Directory in Azure DevOps in Lambda Function Setup
2023-12-05 06:48:44 -08:00
cf3401536a feat: Remove 'Refactoring' label from custom labels and update related descriptions 2023-12-05 07:48:21 +02:00
2feaee4306 feat: Update field descriptions in pr_description_prompts.toml for clarity 2023-12-04 21:45:22 +02:00
863eb0105d feat: Refactor semantic labels in PR description and improve clarity in pr_description.py and pr_description_prompts.toml 2023-12-04 21:23:59 +02:00
21a7a0f136 feat: Enhance link generation for relevant lines and refactor code in git providers and PR description tools 2023-12-04 21:06:56 +02:00
d2a129fe30 Add labeling files 2023-12-04 18:22:35 +02:00
fe796245a3 Merge pull request #501 from Codium-ai/tr/prompt_tuning
Refactoring and Enhancement of PR Agent Prompts
2023-12-04 03:18:12 -08:00
10bc84eb5b Merge pull request #505 from Codium-ai/mrT23-patch-1
Update Usage.md
2023-12-04 01:15:06 -08:00
06c0a35a65 Update Usage.md 2023-12-04 11:11:02 +02:00
082bcd00a1 Merge pull request #502 from pzarfos/local_models
Add descriptive error message for missing model in MAX_TOKENS array
2023-12-03 21:26:21 -08:00
71b421efa3 Updated requirements.txt for Python 3.12 2023-12-03 21:54:19 -05:00
317fec0536 Throw descriptive error message if model is not in MAX_TOKENS array 2023-12-03 21:06:55 -05:00
4dcbce41c8 feat: Refine prompts and improve formatting in pr_sort_code_suggestions_prompts.toml and pr_update_changelog_prompts.toml 2023-12-03 17:27:22 +02:00
b3fa654446 feat: Refactor prompts and improve formatting in pr_questions_prompts.toml 2023-12-03 17:23:52 +02:00
e09439fc1b feat: Enhance formatting and clarity in pr_information_from_user_prompts.toml 2023-12-03 17:17:24 +02:00
324e481ce7 feat: Improve formatting and clarity in pr_custom_labels.toml 2023-12-03 17:15:29 +02:00
abfad088e3 feat: Refine prompts and instructions in pr_add_docs.toml 2023-12-03 17:10:33 +02:00
f30789e6c8 feat: Refactor and enhance prompts in pr_code_suggestions_prompts.toml 2023-12-03 16:59:47 +02:00
5c01f97f54 feat: Enhance PR description prompts in pr_description_prompts.toml 2023-12-03 16:48:26 +02:00
2d726edbe4 feat: Improve formatting and clarity in pr_reviewer_prompts.toml 2023-12-03 16:40:06 +02:00
526ad00812 Merge pull request #500 from Codium-ai/tr/describe_message
Enhance pr_url assignment in github_provider.py for GitHub Actions compatibility
2023-12-03 02:05:38 -08:00
37812dfede feat: Update pr_url assignment in github_provider.py for GitHub Actions compatibility 2023-12-03 11:34:17 +02:00
c9debc38f2 Merge pull request #499 from Codium-ai/tr/describe_message
final update message in PR description
2023-12-03 01:02:21 -08:00
fe7d2bb924 update docs 2023-12-03 10:52:00 +02:00
586785ffde feat: Add pr_url attribute to git providers and final update message in PR description 2023-12-03 10:46:02 +02:00
c21e606eee Merge pull request #498 from Codium-ai/tr/update_pics
Update Image URLs in Markdown Documentation
2023-12-03 00:11:13 -08:00
a658766046 Merge pull request #495 from Codium-ai/tr/review_protection
Enhanced Exception Handling and Code Suggestion Formatting
2023-12-03 00:11:02 -08:00
3f2175e548 diagram 2023-12-03 09:12:10 +02:00
3ff30fcc92 fix logo for non-github image 2023-12-03 08:58:28 +02:00
07abf4788c docs: Update image URLs in markdown files 2023-12-03 08:41:09 +02:00
492dd3c281 docs: Update Azure setup instructions in Usage.md 2023-12-03 08:25:12 +02:00
d2fb1cfce5 Merge pull request #497 from network-charles/network-charles-patch-1
Update pr-agent/docs/Review.md Image
2023-12-02 22:18:56 -08:00
24fe5a572a Update REVIEW.md 2023-12-02 10:36:37 +01:00
3af9c3bfb9 feat: Enhance code suggestion publishing with language-specific formatting in pr_code_suggestions.py 2023-12-01 12:12:49 +02:00
c22084c7ac feat: Add exception handling for missing previous review in github_provider.py 2023-12-01 11:56:03 +02:00
96b91c9daa feat: Add dynaconf to requirements.txt 2023-11-30 18:29:27 +02:00
55464d5c5b Merge pull request #492 from Codium-ai/mrT23-patch-1
Update IMPROVE.md
2023-11-30 18:19:36 +02:00
f6048e8157 Merge pull request #490 from network-charles/network-charles-patch-1
Alphabetical Reordering of requirements.txt
2023-11-30 08:16:01 -08:00
e474982485 Merge pull request #491 from network-charles/network-charles-patch-2
Update INSTALL.md
2023-11-30 07:18:48 -08:00
18f06cc670 Update IMPROVE.md 2023-11-30 17:13:47 +02:00
574e3b9d32 Update IMPROVE.md 2023-11-30 16:35:44 +02:00
f7410da330 Update INSTALL.md 2023-11-30 14:13:20 +01:00
76f3d54519 Update INSTALL.md 2023-11-30 13:56:22 +01:00
59f117d916 Update INSTALL.md 2023-11-29 16:07:57 +01:00
4a71259be7 Update requirements.txt 2023-11-29 15:47:53 +01:00
b90dde48c0 Merge pull request #483 from tmokmss/add-bedrock-support
Add Amazon Bedrock support
2023-11-29 03:08:01 -08:00
c57807e53a Merge pull request #489 from Codium-ai/ok/gh_actions_fix
Improve error handling in settings retrieval
2023-11-29 11:55:22 +02:00
0e54a13272 Improve error handling in settings retrieval
Fix bug where default values were not being used in GitHub Action runners when environmental variables are not set. Now, if an environmental variable cannot be found and no default is given, the default value will be used if one exists. This will prevent errors during setup on different environments and ensure system stability.
2023-11-29 11:52:02 +02:00
ddc6c02018 Merge pull request #488 from Codium-ai/ok/gh_actions_fix
"Add fallback to environment variables in GitHub Action Runner"
2023-11-29 11:49:40 +02:00
b67d06ae59 "Add fallback to environment variables in GitHub Action Runner"
A new function `get_setting_or_env` was implemented to facilitate fetching of either settings or environmental variables in the GitHub Action Runner. This was necessary to resolve an issue where a certain undefined behaviour occurs in GitHub Actions, leading to an attribute error. The new function also provides a default value parameter to ensure the return of a value even in failed attempts to fetch from either settings or environment variables.
2023-11-29 11:47:52 +02:00
ca1289af03 Update pr-agent-review.yaml 2023-11-29 11:03:24 +02:00
5e642c10fa fallback to try_fix_yaml 2023-11-29 17:57:54 +09:00
b5a643d67a Merge pull request #487 from Codium-ai/ok/gh_actions_fix
Add utility function to handle boolean type conversion
2023-11-29 10:38:39 +02:00
580eede021 Add utility function to handle boolean type conversion
A utility function (`is_true`) was added to take care of validating and converting boolean values from string or boolean types. This function is used in three parts of the `run_action` method where automatic PR review, description, and improvement actions are triggered based on environment settings. This change makes the condition checks cleaner and prevents code duplication.
2023-11-29 10:33:12 +02:00
ea56910a2f Merge pull request #485 from Codium-ai/tr/bitbucket
Enhancement of Inline Comment Publishing in Bitbucket Provider and Logging Addition
2023-11-28 08:35:40 -08:00
51e1278cd7 feat: Enhance inline comment publishing in Bitbucket provider and add logging for no suggestions in pr_code_suggestions.py 2023-11-28 18:29:35 +02:00
ddeb4b598d Merge pull request #484 from Codium-ai/tr/review_fix_tags
Refactor: Improved label handling in pr_reviewer.py
2023-11-28 07:14:29 -08:00
7e029ead45 refactor: Improve label handling in pr_reviewer.py 2023-11-28 17:03:55 +02:00
f8f57419c4 Update ai_handler.py 2023-11-28 23:08:17 +09:00
917f4b6a01 hard code value 2023-11-28 20:59:21 +09:00
97d6fb999a set max_tokens_to_sample 2023-11-28 20:58:57 +09:00
1373ca23fc support Amazon Bedrock 2023-11-28 20:58:42 +09:00
4521077433 Merge pull request #481 from Codium-ai/ok/fix_improve
Refactoring Environment Variables Access
2023-11-27 23:31:47 -08:00
6264624c05 Merge branch 'main' into ok/fix_improve 2023-11-27 07:27:25 -08:00
5f6fa5a082 Update Usage.md 2023-11-27 16:18:02 +02:00
2dcee63df5 fix improve 2023-11-27 12:32:53 +02:00
c6cc676275 Update pr-agent-review.yaml 2023-11-27 08:22:58 +02:00
b8e4d10b9d summarize=true 2023-11-27 07:36:02 +02:00
70a957caf0 AUTO_IMPROVE 2023-11-27 07:35:17 +02:00
5ff9aaedfd Update IMPROVE.md 2023-11-26 17:41:20 +02:00
fc8865f8dc Merge pull request #476 from Codium-ai/tr/improve_inplace
Enhancements and Bug Fixes in Code Suggestions and Line Link Generation
2023-11-26 07:32:37 -08:00
466af37675 s 2023-11-26 17:21:02 +02:00
2202ff1cdf s 2023-11-26 17:17:36 +02:00
2022018d4c update tests 2023-11-26 17:16:04 +02:00
b1c374808d feat: Add line link generation in Bitbucket provider and improve markdown formatting in pr_code_suggestions.py and IMRPOVE.md 2023-11-26 17:12:02 +02:00
20978402ea s 2023-11-26 16:56:06 +02:00
8f615e17a3 s 2023-11-26 16:42:41 +02:00
5cbbaf44c9 feat: Add line link generation for GitLab and improve markdown formatting in pr_code_suggestions.py 2023-11-26 13:42:57 +02:00
f96d4924e7 feat: Add line link generation in git providers and refactor code suggestions generation 2023-11-26 11:57:45 +02:00
f36b672eaa feat: Add option to summarize code suggestions in pr_code_suggestions.py 2023-11-26 11:22:14 +02:00
f104b70703 Update INSTALL.md 2023-11-26 10:38:49 +02:00
d4e979cb02 Merge pull request #447 from Codium-ai/tr/pydantic
Refactor PR label handling and update CLI commands
2023-11-25 23:37:02 -08:00
668041c09f Code suggestions guidelines: 2023-11-26 09:32:02 +02:00
aa73eb2841 PR 2023-11-26 09:24:33 +02:00
14d4ca8c74 PR 2023-11-26 09:22:19 +02:00
690c113603 refactor: Improve clarity and consistency in pr_code_suggestions_prompts.toml and pr_reviewer_prompts.toml files 2023-11-26 09:17:42 +02:00
1a28c77783 Previous description 2023-11-26 09:08:33 +02:00
0326b7e4ac refactor: Update PR prompts in toml files for clarity and consistency 2023-11-26 09:05:45 +02:00
d8ae32fc55 language_extension_map 2023-11-26 08:52:55 +02:00
8db2e3b2a0 feat: Enhance readability in toml files and add verbosity level logging in pr_generate_labels.py 2023-11-26 08:42:04 +02:00
9465b7b577 refactor: Move clip_tokens function from pr_processing to utils module, and add tests 2023-11-26 08:29:47 +02:00
d7df4287f8 feat: Update PR prompts in toml files to enhance readability and consistency 2023-11-26 08:17:16 +02:00
b3238e90f2 s 2023-11-26 08:10:01 +02:00
fdfd6247fb Merge branch 'main' into tr/pydantic 2023-11-25 21:36:16 -08:00
46d4d04e94 Merge pull request #455 from lukefx/bitbucket-server
Added BitBucket Server and Data Center support
2023-11-25 21:33:26 -08:00
0f6564f42d feat: Added server and documentation 2023-11-25 17:37:44 +01:00
cddf183e03 Merge pull request #470 from Codium-ai/tr/glob
Enhance glob pattern handling and logging in file filtering
2023-11-22 23:19:09 -08:00
e80a0ed9c8 glob 2023-11-23 09:16:50 +02:00
d6d362b51e Merge pull request #469 from Codium-ai/mrT23-patch-1
Improve Documentation in Usage.md
2023-11-22 22:14:22 -08:00
4eff0282a1 Update Usage.md 2023-11-23 08:06:07 +02:00
8fc07df6ef Update INSTALL.md 2023-11-21 18:39:36 +02:00
84e4b607cc Merge pull request #467 from Codium-ai/ok/base_url
Add support for base_url in GitHub SDK
2023-11-21 16:51:16 +02:00
613ccb4c34 Add support for base_url in GitHub SDK 2023-11-21 16:48:36 +02:00
e95a6a8b07 Merge pull request #466 from Codium-ai/ok/gitlab_fix
Fix a bug in GitLab webhook
2023-11-21 16:36:40 +02:00
2add584fbc Fix a bug in GitLab webhook 2023-11-21 16:28:01 +02:00
54d7d59177 Update Usage.md 2023-11-20 20:06:07 +02:00
b3129c7dd9 Merge pull request #464 from Codium-ai/tr/more_protections
Refactor YAML parsing for improved error handling
2023-11-20 02:28:57 -08:00
3f76d95495 ScannerError 2023-11-20 10:35:35 +02:00
1b600cd85f Refactor YAML parsing for improved error handling 2023-11-20 10:30:59 +02:00
26cc26129c Merge pull request #463 from Codium-ai/tr/more_protections
minor fix
2023-11-19 07:45:39 -08:00
d1d7903e39 minor fix 2023-11-19 17:44:11 +02:00
dff4d1befc Merge pull request #462 from Codium-ai/tr/more_protections
Enhancements in YAML Parsing and Error Handling
2023-11-19 07:40:06 -08:00
3504a64269 protections 2023-11-19 17:35:40 +02:00
83247cadec protections 2023-11-19 17:30:57 +02:00
5ca1748b93 Merge pull request #460 from Codium-ai/tr/update_instructions
GFM mode for 'review' instructions
2023-11-19 01:20:36 -08:00
c7a681038d gfm instructions 2023-11-19 11:11:11 +02:00
eb977b4c24 gfm instructions 2023-11-19 11:02:11 +02:00
b62e0967d5 fix: Revert back to exception since context.get will not throw KeyError 2023-11-17 10:08:40 +01:00
14a934b146 Update Usage.md 2023-11-17 10:41:52 +02:00
26dc2e9d21 fix: raising exception instead of empty string
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-11-16 11:19:46 +01:00
d78a71184d fix: Use checked exception KeyError for missing key
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-11-16 10:59:01 +01:00
eae30c32a2 fix: Use checked exception for ValueError
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-11-16 10:58:35 +01:00
bc28d657b2 Merge pull request #438 from koid/fix/remove-unnecessary-setup
Removal of Redundant Logger Setup
2023-11-15 10:35:13 -08:00
416a5495da Merge pull request #453 from Codium-ai/tr/v_010
Version 0.10 Release and Workflow Update
2023-11-15 09:46:31 -08:00
a2b27dcac8 v10 2023-11-15 19:45:51 +02:00
d8e4e2e8fd Merge pull request #454 from Codium-ai/coditamar-bitbucket-doc-type
Update INSTALL.md
2023-11-15 09:44:03 -08:00
3fae5cbd8d feat: Added BitBucket Server
Signed-off-by: Luca Simone <info@lucasimone.info>
2023-11-15 15:47:44 +01:00
896a81d173 Update INSTALL.md 2023-11-15 15:20:50 +02:00
b216af8f04 v10 2023-11-15 14:49:18 +02:00
388cc740b6 Merge pull request #436 from rhyst/support-vertex-ai
Support Google's Vertex AI
2023-11-15 04:26:08 -08:00
6214494c84 Merge pull request #452 from Codium-ai/tr/review_extra_labels
Add Review Labels for Security and Effort Estimation
2023-11-15 04:25:03 -08:00
762a6981e1 extra_labels 2023-11-15 14:12:59 +02:00
b362c406bc Merge remote-tracking branch 'origin/main' into tr/review_extra_labels 2023-11-15 14:07:44 +02:00
7a342d3312 extra_labels 2023-11-15 14:07:32 +02:00
2e95988741 extra_labels 2023-11-15 14:04:17 +02:00
9478447141 extra_labels 2023-11-15 14:02:13 +02:00
082293b48c Merge pull request #451 from Codium-ai/tr/persistent_enhacments
Enhancement of Persistent Comments in PR Review
2023-11-15 03:55:15 -08:00
e1d92206f3 docs 2023-11-15 13:32:32 +02:00
557ec72bfe Update documentation for Vertex AI 2023-11-15 10:27:48 +00:00
6b4b16dcf9 Support Google's Vertex AI 2023-11-15 10:26:58 +00:00
c4899a6c54 bitbucket 2023-11-15 12:11:02 +02:00
24d82e65cb gitlab 2023-11-15 09:45:10 +02:00
2567a6cf27 gitlab 2023-11-15 09:40:45 +02:00
94cb6b9795 more feedback 2023-11-15 09:06:26 +02:00
e878bbbe36 Merge pull request #449 from zmeir/patch-1
Fix `get_user_description` in case `pr_description.enable_pr_type=false`
2023-11-14 22:09:59 -08:00
172b5f0787 add instructions to lambda function section 2023-11-15 13:22:07 +09:00
0df0542958 prompt 2023-11-13 15:55:35 +02:00
7d89b82967 Fix get_user_description in case pr_description.enable_pr_type=false
Fixes an issue when getting the user description after a PR-Agent description was already generated, in case the configuration setting `pr_description.enable_pr_type` was `false`.
2023-11-13 14:41:14 +02:00
c5f9bbbf92 Merge pull request #448 from Codium-ai/hl/optional_custom_labels
remove the "one or more" for custom labels
2023-11-13 13:51:18 +02:00
a5e5a82952 s 2023-11-13 13:49:16 +02:00
ccbb62b50a remove the "one or more" for custom labels 2023-11-13 13:47:06 +02:00
a8dddd1999 prompt 2023-11-13 12:14:18 +02:00
f5c6dd55b8 triple quote 2023-11-13 12:04:58 +02:00
0e932af2e3 multi line 2023-11-13 12:01:08 +02:00
1df36c6a44 Merge pull request #446 from Codium-ai/tr/fix_cli_args
Handling CLI Arguments with Quotes in pr_agent
2023-11-12 17:29:38 +02:00
e9891fc530 s1 2023-11-12 16:37:53 +02:00
9e5e9afe92 Refactor CLI argument handling and request processing 2023-11-12 16:11:34 +02:00
5e43c202dd s1 2023-11-12 15:45:22 +02:00
727eea2b62 s1 2023-11-12 15:00:06 +02:00
37e6608e68 Merge pull request #444 from Codium-ai/tr/fallback_yaml
Implementing Fallback Mechanisms for YAML Parsing
2023-11-12 00:43:15 -08:00
f64d5f1e2a tests 2023-11-12 08:36:57 +02:00
8fdf174dec fallback 2023-11-10 18:44:19 +02:00
29d4f98b19 Merge pull request #441 from Codium-ai/tr/presistent_review
Add Persistent Review Feature to PR Agent
2023-11-09 05:26:51 -08:00
737792d83c publish_persistent_comment 2023-11-09 15:24:55 +02:00
7e5889061c publish_persistent_comment 2023-11-09 15:20:31 +02:00
755e04cf65 bitbucket finally works 2023-11-08 20:41:55 +02:00
44d6c95714 response 2023-11-08 20:38:18 +02:00
14610d5375 persistent
s
2023-11-08 20:16:08 +02:00
f9c832d6cb Merge pull request #439 from Codium-ai/tr/fixes_added_files
Enhancement of Patch Handling and PR Processing
2023-11-08 04:48:07 -08:00
c2bec614e5 s 2023-11-08 14:46:11 +02:00
49725e92f2 s 2023-11-08 14:41:15 +02:00
a1e32d8331 s 2023-11-08 14:36:59 +02:00
0293412a42 s 2023-11-08 14:31:08 +02:00
10ec0a1812 s 2023-11-08 14:21:03 +02:00
69b68b78f5 s 2023-11-08 14:17:59 +02:00
c5bc4b44ff fix added files 2023-11-08 12:51:30 +02:00
39e5102a2e fix added files 2023-11-08 12:47:18 +02:00
f0991526b5 remove unnecessary setup_logger 2023-11-08 16:56:44 +09:00
6c82bc9a3e Merge pull request #437 from Codium-ai/tr/new_gpt4
Introduce support for 'gpt-4-1106-preview' model and dynamic token limit calculation
2023-11-07 04:49:50 -08:00
54f41dd603 code 2023-11-07 14:41:15 +02:00
094f641fb5 code 2023-11-07 14:38:37 +02:00
a35a75eb34 get_max_tokens + added 'gpt-4-1106-preview' 2023-11-07 14:28:41 +02:00
5a7c118b56 Merge pull request #434 from Codium-ai/document_describe
Update DESCRIBE.md
2023-11-06 11:00:06 -08:00
cf9e0fbbc5 Update DESCRIBE.md 2023-11-06 17:55:58 +02:00
ef9af261ed Merge pull request #433 from Codium-ai/hl/user_labels
Keep user labels
2023-11-06 15:17:19 +02:00
ff79776410 Keep user labels 2023-11-06 15:14:08 +02:00
ec3f2fb485 Revert "generate labels keep user labels only"
This reverts commit 94a2a5e527.
2023-11-06 15:08:29 +02:00
94a2a5e527 generate labels keep user labels only 2023-11-06 15:07:06 +02:00
ea4bc548fc Merge pull request #432 from Codium-ai/hl/type_vs_labels
Support git providers with no label support
2023-11-06 14:38:29 +02:00
1eefd3365b Merge commit 'e352c98ce83bfbd99078f62d8705eb938a6ba5b5' into hl/type_vs_labels 2023-11-06 14:24:33 +02:00
db37ee819a support git providers with no label support 2023-11-06 14:11:49 +02:00
e352c98ce8 Merge pull request #431 from Codium-ai/hl/type_vs_labels
Refactoring PR Labels Handling and Display
2023-11-06 02:10:38 -08:00
e96b03da57 add configuration enable_pr_type 2023-11-06 11:58:26 +02:00
1d2aedf169 Don't Display pr labels in the text 2023-11-06 11:35:22 +02:00
4c484f8e86 Merge pull request #423 from zmeir/zmeir-external-incremental_review_thresholds
Implementing Thresholds for Incremental PR Reviews
2023-11-06 01:07:01 -08:00
8a79114ed9 Merge pull request #430 from Codium-ai/tr/fix_prompt
Fix PR Description Prompt and Data Preparation
2023-11-06 01:06:26 -08:00
cd69f43c77 Merge pull request #428 from Codium-ai/tr/fixes
Enhancements and Fixes in Bitbucket Provider
2023-11-06 01:06:15 -08:00
6d6d864417 fix prompt 2023-11-06 09:44:59 +02:00
b286c8ed20 Added documentation for the new configurations 2023-11-06 09:44:04 +02:00
7238c81f0c fix prompt 2023-11-06 09:41:26 +02:00
62412f8cd4 fix prompt 2023-11-06 09:38:39 +02:00
5d2bdadb45 fix prompt 2023-11-06 09:33:10 +02:00
06d030637c fix prompt 2023-11-06 09:32:46 +02:00
8e3fa3926a Extract incremental review checks to separate method 2023-11-06 09:21:22 +02:00
92071fcf1c Stack all incremental parameters 2023-11-06 09:13:04 +02:00
fed1c160eb files walkthrough bullets 2023-11-06 08:43:15 +02:00
e37daf6987 link to change 2023-11-06 08:27:34 +02:00
8fc663911f fixe bitbucket get_repo_settings bug 2023-11-06 08:15:43 +02:00
bb2760ae41 tools 2023-11-06 08:10:04 +02:00
3548b88463 type and labels 2023-11-05 15:48:39 +02:00
c917e48098 Merge pull request #427 from koid/fix/add-middleware
Adding Middleware to FastAPI Initialization
2023-11-05 01:40:37 -07:00
e6ef123ce5 add middleware when initializing fastapi 2023-11-05 15:38:19 +09:00
194bfe1193 Update INSTALL.md 2023-11-05 07:59:59 +02:00
e456cf36aa Merge pull request #425 from Codium-ai/ok/protect_apply_settings
Add exception handling for applying repo settings failure
2023-11-03 11:07:49 -07:00
fe3527de3c Add exception handling for applying repo settings failure 2023-11-03 12:23:49 +02:00
b99c769b53 Merge pull request #415 from zmeir/zmeir-patch-2
Refactor Command Handling for Different Triggers
2023-11-02 18:32:42 +02:00
60bdfb78df Merge pull request #424 from Codium-ai/ok/bitbucket_fix
Update Bitbucket Provider to Use 'position' Instead of 'start_line' for Inline Comments
2023-11-02 18:31:18 +02:00
c0b3c76884 Merge remote-tracking branch 'origin/main' into ok/bitbucket_fix 2023-11-02 15:27:11 +02:00
e1370a8385 Update publish_inline_comments in bitbucket_provider.py to use 'position' instead of 'start_line' 2023-11-02 15:24:47 +02:00
c623c3baf4 Added new configurations to prevent too frequent incremental commits on push trigger 2023-11-02 12:24:54 +02:00
d0f3a4139d Merge pull request #422 from Codium-ai/pr_review_fix_type_example
small fix to pr type example yaml
2023-11-02 11:48:49 +02:00
3ddc7e79d1 Update pr_reviewer_prompts.toml 2023-11-02 11:45:34 +02:00
3e14edfd4e Merge pull request #421 from zmeir/patch-1
Fix error in `get_main_pr_languages` when the diff is empty
2023-11-02 01:20:36 -07:00
15573e2286 Fix error in get_main_pr_languages when the diff is empty
This can happen for example when you have one commit add a line to a file and the next commit deletes that line. Then if those are the only 2 commits in the PR the diff will be empty.
2023-11-02 10:10:54 +02:00
ce64877063 Merge pull request #419 from KennyDizi/fix_synstax_error
Fix Syntax Error in f-string Expression
2023-11-02 08:23:17 +02:00
6666a128ee Update Usage.md 2023-11-01 18:36:12 +02:00
9fbf89670d Improve expression portion of f-strings 2023-11-01 19:11:52 +07:00
ad1c51c536 Fix SyntaxError: f-string expression part cannot include a backslash 2023-11-01 19:06:29 +07:00
9ab7ccd20d Merge pull request #416 from zmeir/patch-1
Fix formatting when last commit message contains _
2023-11-01 13:13:31 +02:00
c907f93ab8 Merge pull request #418 from KennyDizi/fix/configuration-typo
Fix Typo and Update Comment for Ollama Configuration
2023-10-31 11:14:51 -07:00
29a8cf8357 fix typo for ollama 2023-10-31 20:38:27 +07:00
7b6a6c7164 Fix formatting when last commit message contains _ 2023-10-31 10:05:13 +02:00
cf4d007737 Fix commands list for push trigger 2023-10-31 00:00:48 +02:00
a751bb0ef0 Merge pull request #414 from Codium-ai/ok/fix_github_bug
Bugfix: ignored github_app.commands on .pr-agent.toml
2023-10-30 20:28:54 +02:00
26d6280a20 Merge remote-tracking branch 'origin/main' into ok/fix_github_bug 2023-10-30 20:19:41 +02:00
32a19fdab6 Merge pull request #413 from Codium-ai/ok/bitbucket_repo_settings
Update Method to Fetch Repository Settings in bitbucket_provider.py
2023-10-30 20:18:59 +02:00
775ccb3f25 Refactor _perform_commands function in github_app.py to improve command handling 2023-10-30 20:14:25 +02:00
a1c6c57f7b Merge remote-tracking branch 'origin/main' into ok/bitbucket_repo_settings 2023-10-30 18:38:08 +02:00
73bb70fef4 Update get_repo_settings in bitbucket_provider.py to fetch file via API request 2023-10-30 18:36:46 +02:00
dcac6c145c Merge pull request #412 from Codium-ai/ok/fix_gitlab_bug
Update get_repo_settings to decode file from target branch in gitlab_…
2023-10-30 17:04:09 +02:00
4bda9dfe04 Update get_repo_settings to decode file from target branch in gitlab_provider.py 2023-10-30 17:01:49 +02:00
66644f0224 Merge pull request #411 from Codium-ai/ok/fix_gitlab_bug
Add Logging Context to Handle Request Calls in gitlab_webhook.py
2023-10-30 16:53:40 +02:00
e74bb80668 Refactor get_repo_settings method in gitlab_provider.py to decode file contents 2023-10-30 16:45:47 +02:00
e06fb534d3 Merge remote-tracking branch 'origin/main' into ok/fix_gitlab_bug 2023-10-30 16:34:03 +02:00
71a341855e Add log_context to handle_request calls in gitlab_webhook.py 2023-10-30 16:00:09 +02:00
7d949ad6e2 Update GENERATE_CUSTOM_LABELS.md 2023-10-30 15:20:17 +02:00
4b5f86fcf0 Merge pull request #410 from Codium-ai/fix_link_in_install
small fix in link in install.md
2023-10-30 02:58:52 -07:00
cd11f51df0 small fix in link in install.md 2023-10-30 11:47:24 +02:00
b40c0b9b23 Merge pull request #409 from zmeir/patch-1
Fix call to `_get_previous_review_comment`
2023-10-30 01:28:12 -07:00
816ddeeb9e Fix call to _get_previous_review_comment
Hey @mrT23, I thinks there's a problem with moving this line to after `self.git_provider.publish_comment(pr_comment)`.

The reason I originally placed it here is because otherwise, if you run `/review --pr_reviewer.remove_previous_review_comment=true` it will publish your review and then immediately after delete it, because it will look for the previous review comment only after you published your new review - so it will take your new review as the previous one. In order to get the real "previous" review you must collect the comments list before publishing a review, so placing this method call first ensures that.

The method `self._get_previous_review_comment()` is a no-op if `pr_reviewer.remove_previous_review_comment=false` so I see no downside in keeping it before `self.git_provider.publish_comment(pr_comment)`

Additionally, the check for `if previous_review_comment:` is redundant because it's done internally in `self._remove_previous_review_comment`. I thought it looked cleaner without this extra nesting here, but if you think more verbosity is better I'll keep it.
2023-10-30 09:06:51 +02:00
11f01a226c Update RELEASE_NOTES.md 2023-10-30 08:22:36 +02:00
b57ec301e8 Merge pull request #408 from Codium-ai/tr/final_fixes
fixed review
2023-10-29 09:02:48 -07:00
71da20ea7e better link 2023-10-29 18:01:50 +02:00
c895657310 fixed review 2023-10-29 17:59:46 +02:00
eda20ccca9 Merge pull request #407 from zmeir/patch-1
Update Usage.md with new GitHub App features
2023-10-29 16:54:59 +02:00
aed113cd79 Update Usage.md with new GitHub App features 2023-10-29 16:33:38 +02:00
0ab07a46c6 Merge pull request #405 from Codium-ai/tr/final_fixes
Final Fixes and Updates to PR Agent
2023-10-29 06:02:34 -07:00
5f32e28933 generate_labels 2023-10-29 15:02:16 +02:00
7538c4dd2f generate_labels 2023-10-29 14:59:50 +02:00
e3845283f8 release notes 2023-10-29 14:58:36 +02:00
a85921d3c5 release notes 2023-10-29 14:49:35 +02:00
27b64fbcaf release notes 2023-10-29 14:47:46 +02:00
8d50f2ae82 release notes 2023-10-29 14:43:45 +02:00
e97a03f522 Merge remote-tracking branch 'origin/main' into tr/final_fixes 2023-10-29 14:38:33 +02:00
2e3344b5b0 Merge pull request #406 from Codium-ai/hl/custom_labels
Add documentation to custom labels
2023-10-29 05:38:11 -07:00
e1b51eace7 release notes 2023-10-29 14:37:04 +02:00
49e3d5ec5f Add documentation 2023-10-29 13:58:01 +02:00
afa78ed3fb final fixes 2023-10-29 13:07:22 +02:00
72d5e4748e final fixes 2023-10-29 13:05:15 +02:00
61d3e1ebf4 Merge pull request #394 from zmeir/zmeir-external-push_trigger
Added support for automatic review on push event
2023-10-29 13:04:33 +02:00
055b5ea700 final fixes 2023-10-29 13:03:12 +02:00
3434296792 Documentation 2023-10-29 13:02:07 +02:00
ae375c2ff0 final fixes 2023-10-29 13:01:55 +02:00
3d5efdf4f3 Merge commit '9a585de36461a6941cb77009e5ab5f4b568a1ff7' into hl/custom_labels 2023-10-29 13:01:53 +02:00
9a585de364 Merge pull request #404 from Codium-ai/tr/final_fixes
final fixes
2023-10-29 12:31:40 +02:00
c27dc436c4 final fixes 2023-10-29 12:29:14 +02:00
e83747300d Merge branch 'main' of github.com:Codium-ai/pr-agent into hl/custom_labels 2023-10-29 12:09:43 +02:00
7374243d0b enable_custom_labels 2023-10-29 11:40:36 +02:00
5c568bc0c5 Merge pull request #403 from Codium-ai/tr/fix_custom_labels
Refactoring Custom Labels Handling and Documentation Update
2023-10-29 02:34:18 -07:00
22c196cb3b Merge remote-tracking branch 'origin/main' into tr/fix_custom_labels
# Conflicts:
#	pr_agent/git_providers/github_provider.py
2023-10-29 10:58:42 +02:00
d2cc856cfc Merge pull request #402 from Codium-ai/tr/github_action_uses_toml
Update GitHub Action to Use .pr_agent.toml
2023-10-29 01:55:33 -07:00
013a689b33 generate_labels fix 2023-10-29 10:43:04 +02:00
d772213cfc fix labels 2023-10-29 08:58:12 +02:00
638db96311 github action now also uses .pr_agent.toml 2023-10-28 13:34:32 +03:00
4dffabf397 Merge pull request #396 from Codium-ai/hl/custom_labels
Implement Custom Labels for PRs
2023-10-28 01:37:54 +03:00
6f2bbd3baa Add documentation 2023-10-28 00:45:59 +03:00
9e41f3780c disable custom labels by default 2023-10-27 21:22:56 +03:00
f53ec1d0cc move enable custom labels to custom labels function 2023-10-27 21:12:58 +03:00
f7666cb59a Update INSTALL.md 2023-10-27 11:49:39 +03:00
a7cb59ca8b small fix 2023-10-27 08:10:29 +03:00
ca0ea77415 refactor 2023-10-27 07:58:42 +03:00
0cf27e5fee custom labels disabled by default 2023-10-27 07:54:59 +03:00
f3bdbfc103 Add /generate_labels function + fix issues 2023-10-26 23:28:33 +03:00
20e3acdd86 Merge pull request #393 from Kryslynn93/patch-1
Update configuration.toml
2023-10-26 07:43:00 -07:00
f965b09571 Merge pull request #398 from Codium-ai/tr/readme_updates
Update Documentation and Installation Instructions
2023-10-26 07:37:05 -07:00
e6bea76eee Typo 2023-10-26 17:07:16 +03:00
414f2b6767 Fix incremental review if there are no new commits (would have performed a full review instead) 2023-10-26 16:49:55 +03:00
6541575a0e Refactor to use pull_request synchronize event 2023-10-26 16:49:54 +03:00
02570ea797 Remove previous review comment on push event 2023-10-26 16:46:54 +03:00
b8583c998d readme 2023-10-26 12:16:58 +03:00
726594600b readme 2023-10-26 12:10:14 +03:00
c77cc1d6ed readme 2023-10-26 11:56:03 +03:00
b6c9e01a59 readme 2023-10-26 11:51:32 +03:00
ec673214c8 Update INSTALL.md 2023-10-26 11:18:07 +03:00
16777a5334 Add custom label description 2023-10-25 13:48:27 +03:00
65bb70a1dd Added support for automatic review on push event
The new feature can be enabled via the new configuration `github_app.handle_push_event`. To avoid any unwanted side-effects, the current default of this configuration is set to `false`.

The high level flow (assuming the configuration is enabled):
1. receive push event from GitHub
2. extract branch and commits from event
3. find PR url for branch (currently does not support PRs from forks)
4. perform configured commands (e.g. `/describe`, `/review -i`)

The push event flow is guarded by a backlog queue so that multiple push events on the same branch won't trigger multiple duplicate runs of the PR-Agent commands.
Example timeline:
1. push 1 - start handling event
2. push 2 - waiting to be handled while push 1 event is still running
3. push 3 - event is dropped since handling it and handling push 2 is the same, so it is redundant
4. push 1 finished being handled
5. push 2 awakens from wait and continues handling (potentially reviewing the commits of both push 2 and push 3)

All of these options are configurable and can be enabled/disabled as per the user's desire.

Additional minor changes in this PR:
1. Created `DefaultDictWithTimeout` utility class to avoid too much boilerplate code in managing caches for outdated triggers.
2. Guard against running increment review when there are no new commits.
3. Minor styling changes for incremented review text.
2023-10-25 11:15:23 +03:00
1a89c7eadf refactor + add description options 2023-10-24 22:28:57 +03:00
07617eab5a add custom labels 2023-10-24 22:06:27 +03:00
f9e4c2b098 Update configuration.toml 2023-10-23 21:34:12 -04:00
fa24413201 Custom Labels 2023-10-23 16:29:33 +03:00
b6cabda586 quick fix 2023-10-19 17:24:37 +03:00
abbce60f18 Merge remote-tracking branch 'origin/main' 2023-10-19 17:10:30 +03:00
5daaaf2c1d quick fix 2023-10-19 17:10:21 +03:00
e8f207691e Merge pull request #391 from Codium-ai/tr/readme
Update and Enhance DESCRIBE.md Documentation
2023-10-19 02:03:50 -07:00
b0dce4ceae describe 2023-10-19 12:02:12 +03:00
fc494296d7 Merge pull request #387 from Codium-ai/ok/json_logging_in_bitbucket
Enhancing Logging in Bitbucket, GitLab, and Google Cloud Storage Secret Provider
2023-10-19 11:59:26 +03:00
67b4069540 describe 2023-10-19 11:45:41 +03:00
e6defcc846 describe 2023-10-19 11:43:18 +03:00
096fcbbc17 describe 2023-10-19 11:40:01 +03:00
eb7add1c77 describe 2023-10-19 11:38:21 +03:00
1b6fb3ea53 Merge pull request #385 from Codium-ai/hl/fix_add_docs_in_scripts
Add Blacklist for Non-Editable File Extensions in Documentation
2023-10-19 11:21:36 +03:00
c57b70f1d4 Merge pull request #390 from Codium-ai/tr/readme
Enhancing Documentation and Updating Configuration for PR Descriptions
2023-10-19 01:04:24 -07:00
a2c3db463a use_bullet_points 2023-10-19 10:45:42 +03:00
193da1c356 update readme 2023-10-19 09:22:26 +03:00
5bc26880b3 update readme 2023-10-19 09:20:36 +03:00
21a1cc970e - update readme
- minor prompts change
2023-10-19 09:16:20 +03:00
954727ad67 Merge pull request #386 from Codium-ai/ok/fix_bitbucket_pipeline
Refactor Bitbucket Pipeline Integration and Update Documentation
2023-10-18 16:45:26 +03:00
1314898cbf Enhance logging in bitbucket_app, gitlab_webhook, and google_cloud_storage_secret_provider with JSON format and additional context 2023-10-18 16:44:03 +03:00
ff04d459d7 Update Bitbucket Pipeline instructions in INSTALL.md, remove redundant functionality 2023-10-18 15:46:43 +03:00
88ca501c0c Merge pull request #377 from zmeir/zmeir-review_incremental_detect_header
Get previous incremental review
2023-10-18 00:30:42 +03:00
fe284a8f91 Merge pull request #382 from Codium-ai/tr/similar_issue_fix
Enhancements and Error Handling in Similar Issue Tool
2023-10-17 09:49:35 -07:00
d41fe0cf79 comment 2023-10-17 19:45:04 +03:00
3673924fe9 Add docs editable blacklist of file extensions like sql, yaml... 2023-10-17 18:50:39 +03:00
d5c098de73 another protection 2023-10-17 10:21:05 +03:00
9f5c0daa8e protection 2023-10-17 09:43:48 +03:00
bce2262d4e Merge pull request #381 from moccajoghurt/feature-allow-custom-urls
Support Custom Domain URLs for Azure DevOps Integration
2023-10-16 22:38:27 -07:00
e6f1e0520a remove azure.com url restriction 2023-10-16 20:38:14 +02:00
d8de89ae33 Get previous incremental review
When getting the last commit in `/review -i` consider also the last __incremental__ review, not just the last __full__ review

Full disclosure I'm not really sure the `/review -i` feature work very well - I might be wrong but it seemed like the actual review in fact addressed all the changes in the PR, and not just the ones from the last review (even though it adds a link to the commit of the last review).  
I think the commit list gathered in `/review -i` doesn't propagate the actual list the reviewer uses. Again, I might be wrong, just took a brief glance at it.
2023-10-16 16:37:10 +03:00
428c38e3d9 Merge pull request #376 from Codium-ai/feature/better_logger
Refactor logging system to use custom logger across the codebase
2023-10-16 16:32:27 +03:00
7ffdf8de37 Remove verbosity level check in handle_patch_deletions test 2023-10-16 16:25:57 +03:00
83e670c5df Enhance logging context in github_app server with server type 2023-10-16 16:13:09 +03:00
c324d88be3 Refactor logging system to use custom logger across the codebase 2023-10-16 14:56:00 +03:00
41166dc271 Merge pull request #374 from Codium-ai/fix/repo_specfic_settings
Repo settings file - fix a bug and apply to GitHub app
2023-10-13 15:44:05 -07:00
e7258e732b Refactor repo-specific settings application into a utility function, fix merge bug 2023-10-14 01:39:05 +03:00
18ee9d66b0 Update Usage.md 2023-10-13 05:00:41 +03:00
8755f635b4 Update Usage.md 2023-10-10 17:23:58 +03:00
e2417ebe88 Merge pull request #363 from Codium-ai/tr/pr_suggestions
publish each suggestion seperatly only on gitlab
2023-10-08 17:01:44 +03:00
264dea2a8b Merge pull request #359 from pzarfos/codecommit_changelog
added checkmark on features table for update_changelog with CodeCommit
2023-10-08 17:00:59 +03:00
da98fd712f note 2023-10-08 16:58:22 +03:00
e6548f4fe1 simpler solution 2023-10-08 16:57:22 +03:00
e66fed2468 Merge pull request #362 from zmeir/zmeir-fix_help_message_for_bot
Fixed help message for bot user
2023-10-08 16:52:18 +03:00
1b3fb49f9c publish each suggestion seperatly only on gitlab 2023-10-08 16:50:25 +03:00
66a5f06b45 Merge pull request #360 from zmeir/zmeir-fix_typo_in_describe_md
Small typo in DESCRIBE.md
2023-10-08 16:37:51 +03:00
51c817ba29 Merge pull request #357 from jamesrom/feat/file_ignores
Add support for ignoring files
2023-10-08 16:30:02 +03:00
8f9f09ecbf Fixed help message for bot user
This changes the help message to display properly when running a custom deployment of the PR-Agent app (i.e. not via GitHub Actions, and with the setting `github_app.override_deployment_type=false`)
2023-10-08 16:19:11 +03:00
d77a71bf47 Small typo in DESCRIBE.md 2023-10-08 14:35:54 +03:00
70c0ef5ce1 added checkmark on features table for update_changelog with CodeCommit 2023-10-07 09:57:51 -04:00
92e9012fb6 Error handling 2023-10-07 09:39:53 +11:00
43dc648b05 Simplify filter 2023-10-06 22:44:29 +11:00
6dee18b24a Update usage documentation 2023-10-06 22:13:03 +11:00
baa0e95227 Code comments for ignore.toml 2023-10-06 21:53:10 +11:00
b27f57d05d Update settings, documentation 2023-10-06 21:03:36 +11:00
fd8c90041c azure 2023-10-06 08:31:31 +03:00
ea6253e2e8 revert azure 2023-10-06 08:12:11 +03:00
2a270886ea Merge pull request #354 from Codium-ai/tr/prompts
Enhancements in Markdown Conversion and Line Number Linking
2023-10-05 18:27:29 +03:00
2945c36899 source_branch 2023-10-05 18:21:52 +03:00
1bab26f1c5 gfm_supported 2023-10-05 18:08:02 +03:00
72eecbbf61 add line number 2023-10-05 17:59:08 +03:00
989c56220b add line number 2023-10-05 17:48:36 +03:00
e387086890 Add support for ignoring files
Add ignore.toml, configuration for ignoring files
Add file_filter.py, for matching files against glob/regex patterns
Update relevant code to use file filter
+Tests
2023-10-06 01:43:35 +11:00
088f256415 stable 2023-10-05 17:03:10 +03:00
d92f5284df Merge pull request #352 from Codium-ai/tr/prompts
Refactoring Patch Extra Lines and Updating Prompts
2023-10-05 08:55:14 +03:00
f3e794e50b Patch Extra Lines 2023-10-05 08:46:02 +03:00
44239f1a79 Patch Extra Lines 2023-10-05 08:38:43 +03:00
428e6382bd prompts minor update 2023-10-05 08:17:37 +03:00
d13a92515b Merge pull request #349 from Codium-ai/tr/large_prs_readme
readme updates
2023-10-02 18:20:41 +03:00
eaf7cfbcf2 readme updates 2023-10-02 18:18:15 +03:00
abb633db0f readme updates 2023-10-02 18:10:41 +03:00
ca11cfa54e Merge pull request #347 from Codium-ai/hl/document_incremental_review
Add Incremental Review to user guide
2023-10-02 14:17:04 +03:00
8df57941c6 Merge pull request #348 from Codium-ai/add-x-badge
Update README.md - add X badge
2023-10-02 13:21:49 +03:00
af45dcc7df Update README.md - add X badge 2023-10-02 11:59:56 +03:00
18c33ae6fc add screenshot 2023-10-02 11:45:05 +03:00
896d65a43a Update README.md 2023-10-02 10:59:03 +03:00
02ea2c7a40 Merge pull request #345 from brianpham93/azure-devops-get-item-error
Azure Devops: Set file content as empty string when azure_devops_client.get_item fails
2023-10-02 10:57:08 +03:00
fdbb7f176c Merge pull request #346 from Codium-ai/GadiZimerman-patch-1
Update README.md
2023-10-02 10:56:46 +03:00
5386ec359d Merge pull request #337 from Codium-ai/hl/add_docs
Add code documentations in PR
2023-10-02 10:55:36 +03:00
85f64ad895 update readme and user guide 2023-10-02 10:11:28 +03:00
589d329a3c Add error logs for troubleshooting 2023-10-02 05:37:27 +00:00
3585a4ebff Update README.md 2023-10-01 23:20:13 +03:00
706f6bf44d update Roadmap 2023-10-01 19:57:34 +03:00
54f29fcf38 add Incremental Review to user guide 2023-10-01 19:55:41 +03:00
e941fa9ec0 Add to user tools guide 2023-10-01 19:51:15 +03:00
4479c5f11b Azure Devops: Set file content as empty string when error 2023-10-01 16:22:37 +00:00
b2369c66d8 Merge commit '8d075b76ae081d0d38813f789478e4fa0f404cd8' into hl/add_docs
# Conflicts:
#	README.md
2023-10-01 13:55:50 +03:00
ab5ac8ffa8 rename vars + Add to README.md 2023-10-01 13:52:00 +03:00
ccc7f1e10a rename vars 2023-10-01 13:07:08 +03:00
8d075b76ae Merge pull request #344 from brianpham93/azure-devops-ignore-tree
Ignore change item with `gitObjectType == 'tree'`
2023-10-01 10:39:03 +03:00
32a8b0e9bc Ignore change item with gitObjectType == 'tree' 2023-10-01 07:34:01 +00:00
69c6acf89d Merge pull request #343 from Codium-ai/tr/prompts_and_readme
Update Documentation and Prompts
2023-10-01 09:05:16 +03:00
e07412c098 prompt and readme updates 2023-10-01 09:00:58 +03:00
8cec3ffde3 Merge pull request #341 from Codium-ai/tr/readme
Update and Refactor Documentation
2023-09-30 10:54:58 +03:00
25bc54785b update docs 2023-09-30 10:51:37 +03:00
8b033ccc94 Merge pull request #340 from Codium-ai/tr/readme
Update Documentation and CLI Execution Method
2023-09-29 16:43:10 +03:00
2003b6915b typos 2023-09-29 16:39:25 +03:00
175218c779 cli 2023-09-29 16:31:13 +03:00
f96c6cbc95 Merge pull request #339 from Codium-ai/tr/readme
Enhancements to PR-Agent Documentation and Settings
2023-09-29 11:56:02 +03:00
4dbb70c9d5 typos 2023-09-29 11:54:37 +03:00
73cc7c2d71 typos 2023-09-29 11:53:39 +03:00
902975b660 Merge remote-tracking branch 'origin/tr/readme' into tr/readme 2023-09-29 11:44:19 +03:00
813fa8571e tools guide 2023-09-29 11:44:03 +03:00
b5c505f727 ASK 2023-09-29 11:43:38 +03:00
26b9e8a235 ASK 2023-09-29 11:37:31 +03:00
c90e72cb75 Improve 2023-09-29 11:30:47 +03:00
55f022d93e improve 2023-09-29 11:24:26 +03:00
71b532d4d5 <kbd> 2023-09-29 10:38:01 +03:00
c18ae77299 <kbd> 2023-09-29 10:36:58 +03:00
2f0fa246c0 borders 2023-09-29 10:34:18 +03:00
a371f7ab84 review 2023-09-29 10:30:20 +03:00
e1149862b2 similar issue 2023-09-29 10:01:32 +03:00
b8f93516ce describe 2023-09-29 09:47:13 +03:00
d15d374cdc Merge pull request #338 from coka-stefan/main
Add lockb to bad extensions
2023-09-29 09:20:49 +03:00
cae0f627e2 Add lockb to bad extensions 2023-09-28 22:26:25 +02:00
7fbdc3aead rstrip 2023-09-28 22:47:26 +03:00
0551922839 Merge commit '663ae92bdf3bb3a22b8b7ab437385c882f96e475' into hl/add_docs
# Conflicts:
#	pr_agent/tools/pr_add_docs.py
2023-09-28 22:46:07 +03:00
043d453cab add doc placement before after 2023-09-28 22:44:15 +03:00
663ae92bdf Add Docs 2023-09-28 22:42:03 +03:00
96824aa9e2 Revert "Add Docs"
This reverts commit 5cca299b16.
2023-09-28 21:16:14 +03:00
5cca299b16 Add Docs 2023-09-28 21:13:48 +03:00
cd3527f7d4 add configurable docstring style 2023-09-28 20:58:37 +03:00
bb12c75431 reformat 2023-09-28 20:15:18 +03:00
4accddcaa7 revert verbosity 2023-09-28 20:12:36 +03:00
bb8a0f10f4 refine /add_docs 2023-09-28 20:11:18 +03:00
c3cbaaf09e Initial add docs 2023-09-27 16:48:17 +03:00
a6e65e867f release notes v0.8 2023-09-27 09:23:19 +03:00
0df8071673 Merge pull request #331 from dulalbert/patch-2
INSTALL.md Fixed typo in the hyperlink
2023-09-26 08:22:07 +03:00
b17a4d9551 INSTALL.md Fixed typo in the hyperlink 2023-09-26 10:29:26 +08:00
dc7db4cbdd Merge pull request #330 from Codium-ai/tr/action_defaults
Enhancements in GitHub Action and Error Handling
2023-09-25 18:59:57 +03:00
4e94fcc372 typo 2023-09-25 18:57:50 +03:00
4c72cfbff4 auto tools in github action 2023-09-25 18:56:10 +03:00
ac89867ac7 Merge pull request #329 from Codium-ai/tr/action_defaults
Adding Environment Variables for Automated Actions in GitHub
2023-09-25 18:30:53 +03:00
34ed598c20 yaml 2023-09-25 18:30:20 +03:00
e7aee84ea8 isinstance 2023-09-25 18:23:56 +03:00
388684e2e8 none 2023-09-25 18:19:35 +03:00
8f81c18647 auto commands in github action 2023-09-25 18:01:32 +03:00
ba78475944 Merge pull request #327 from Codium-ai/tr/no_comments
Update Review Guidelines to Exclude Comments
2023-09-25 17:25:31 +03:00
75dd5688fa Merge pull request #324 from pzarfos/feature/get_pr_id_320
Added 'get_pr_id' function for the CodeCommit provider
2023-09-25 17:24:21 +03:00
aa32024078 no comments 2023-09-25 16:58:08 +03:00
9167c20512 added unit tests 2023-09-23 10:41:53 -04:00
a7fb5d98b1 add get_pr_id() to CodeCommitProvider 2023-09-23 08:08:46 -04:00
fda47bb5cf Merge pull request #304 from sarbjitsinghgrewal/fix_bitbucket_pipeline
Fix bitbucket pipeline
2023-09-22 14:36:42 +03:00
9c4f849066 Merge pull request #321 from dulalbert/patch-1
Correct typo in pr_reviewer_prompts.toml
2023-09-22 12:44:09 +03:00
3e2e2d6c6e update install.md 2023-09-22 12:23:41 +05:30
56cc804fcf Merge branch 'main' of https://github.com/Codium-ai/pr-agent into fix_bitbucket_pipeline 2023-09-22 12:19:49 +05:30
62746294e3 Correct typo in pr_reviewer_prompts.toml 2023-09-22 10:23:01 +08:00
d384b0644e Merge pull request #320 from Codium-ai/tr/pr_id
Implementing get_pr_id method in Git Providers
2023-09-21 21:38:49 +03:00
3e07fe618f pr_id gitlab 2023-09-21 21:35:00 +03:00
be54fb5bf8 pr_id 2023-09-21 21:29:41 +03:00
46ec3c0754 implement suggestions in bitbucket pipeline 2023-09-21 14:42:59 +05:30
5e608cc7e7 Merge branch 'main' of https://github.com/Codium-ai/pr-agent into fix_bitbucket_pipeline 2023-09-21 12:48:32 +05:30
04162564ca Merge pull request #315 from Codium-ai/tr/fixes_20_9
Fixing potential null values in git patch processing
2023-09-20 17:00:59 +03:00
992f51a019 protections 2023-09-20 15:59:35 +03:00
2bc25b7435 Merge remote-tracking branch 'origin/main' into tr/fixes_20_9 2023-09-20 15:58:05 +03:00
fcd9821d10 protections 2023-09-20 15:57:06 +03:00
911ad299e2 Merge pull request #314 from Codium-ai/mrT23-patch-1
Update README.md
2023-09-20 14:50:53 +03:00
fbfa186733 Update README.md 2023-09-20 14:50:21 +03:00
7545b25823 Update README.md 2023-09-20 14:49:50 +03:00
1370a051f1 Update INSTALL.md 2023-09-20 14:47:52 +03:00
dcbd3132d1 Release notes 2023-09-20 14:41:24 +03:00
497f84b3bd Update release notes 2023-09-20 14:23:55 +03:00
c2fe2fc657 Added a release notes file 2023-09-20 13:50:10 +03:00
f7abdc6ae8 Merge branch 'main' of https://github.com/Codium-ai/pr-agent into fix_bitbucket_pipeline 2023-09-20 14:47:21 +05:30
d327245edf Merge pull request #312 from Codium-ai/tr/fixes_20_9
Enhancing error handling in PR review tools
2023-09-20 07:59:02 +03:00
632de3f186 protections 2023-09-20 07:39:56 +03:00
de14b0e4c0 Merge pull request #310 from never-known-soldier/update/README.md
Update README.md file
2023-09-19 13:29:35 +03:00
f010d1389b Merge branch 'main' into update/README.md 2023-09-19 13:28:39 +03:00
4411f6d88a Update README.md file 2023-09-19 12:54:33 +05:30
a2ca43afcd Merge branch 'main' of https://github.com/Codium-ai/pr-agent into fix_bitbucket_pipeline 2023-09-18 10:34:18 +05:30
1f62520606 Merge pull request #306 from Codium-ai/tr/etr
Adding Estimated Review Effort Feature and Handling Cases with No Detected Language
2023-09-17 17:10:52 +03:00
c0511c954e icon 2023-09-17 17:08:02 +03:00
818ab5a9e8 fixed tests 2023-09-17 16:56:23 +03:00
291ffdd6ae gfm_markdown 2023-09-17 16:51:16 +03:00
4fbe7d14b5 protection for no language 2023-09-17 16:41:53 +03:00
ea91a38541 Estimated effort to review 2023-09-17 16:31:58 +03:00
caaee4e43d Estimated time to review 2023-09-15 17:09:58 +03:00
43af4aa182 remove token from config 2023-09-15 16:08:13 +05:30
e343ce8468 bitbucket pipeline for adding reviews 2023-09-15 16:05:55 +05:30
7b2c01181b Merge pull request #3 from sarbjitsinghgrewal/fix_bitbucket_pipeline
Fix bitbucket pipeline
2023-09-15 12:44:14 +05:30
978c56c128 update pipeline 2023-09-15 12:38:34 +05:30
4043dfff9e Merge branch 'main' of https://github.com/Codium-ai/pr-agent into fix_bitbucket_pipeline 2023-09-14 15:31:18 +05:30
279d45996f Merge pull request #301 from Codium-ai/add-links-to-readme
Addition of Relevant Links to README.md
2023-09-14 12:38:57 +03:00
01aa038ad6 Update README.md - add links 2023-09-14 11:53:47 +03:00
084256b923 fixed config 2023-09-14 08:23:34 +03:00
dc42713217 Merge pull request #285 from Codium-ai/markers
Markers
2023-09-14 08:21:35 +03:00
99f17666c5 merge 2023-09-14 08:20:36 +03:00
bba22667f1 merge 2023-09-14 08:13:00 +03:00
1b8349b0ef merge 2023-09-14 07:47:04 +03:00
b94e3521d1 Merge remote-tracking branch 'origin/main' into markers
# Conflicts:
#	pr_agent/tools/pr_description.py
2023-09-14 07:46:30 +03:00
32931f0bc0 Update Usage.md 2023-09-13 10:38:31 +03:00
72ac8e8091 Merge pull request #299 from Codium-ai/tr/readme
Enhancement of Similar Issue Tool and Documentation Updates
2023-09-13 08:19:13 +03:00
33045e6898 graphic adjustments 2023-09-13 08:17:13 +03:00
069c3a8e5c Merge remote-tracking branch 'origin/tr/readme' into tr/readme 2023-09-13 08:16:36 +03:00
9c0656c296 graphic adjustments 2023-09-13 08:16:23 +03:00
228ee26541 graphic adjustments 2023-09-13 08:16:08 +03:00
f8d548367f graphic adjustments 2023-09-13 08:15:15 +03:00
d3f466f59b graphic adjustments 2023-09-13 08:04:36 +03:00
6b45940128 Merge remote-tracking branch 'origin/main' into tr/readme 2023-09-13 07:47:21 +03:00
a52e94fcbc similar issue 2023-09-13 07:46:43 +03:00
ee3874f0aa Merge pull request #297 from Codium-ai/tr/fix_tests
Enhancing Logging in pr_similar_issue.py
2023-09-13 07:27:50 +03:00
31ba7acf49 Support issue comments in GitHub Actions 2023-09-12 16:53:54 +03:00
b7a2551cab Support issue comments in GitHub Actions 2023-09-12 16:46:02 +03:00
d4eb100cbc Support issue comments in GitHub Actions 2023-09-12 16:44:20 +03:00
21feb92b75 Support issue comments in GitHub Actions 2023-09-12 16:41:12 +03:00
2f6178306f Fix a bug in GitHub Actions 2023-09-12 13:28:35 +03:00
36e7c1c22f Merge remote-tracking branch 'origin/main' 2023-09-12 13:24:55 +03:00
c31baa5aea Fix a bug in GitHub Actions 2023-09-12 13:24:47 +03:00
67052aa714 add bitbucket access token 2023-09-12 11:28:36 +05:30
caee7cbf50 add bitbucket access token 2023-09-12 11:20:38 +05:30
9bee3055c2 add bitbucket access token 2023-09-12 11:15:10 +05:30
901eda2f10 logs 2023-09-12 07:57:21 +03:00
8cf7d2d0b1 Merge pull request #296 from Codium-ai/tr/fix_tests
gfm_supported
2023-09-12 07:49:19 +03:00
d7f43d6ee0 gfm_supported 2023-09-12 07:43:15 +03:00
9bd5140ea4 update access token 2023-09-11 16:33:45 +05:30
12bd9e8b42 add bitbucket pipeline 2023-09-11 16:08:23 +05:30
ca8997b616 Merge branch 'main' of https://github.com/Codium-ai/pr-agent into fix_bitbucket_publish_description 2023-09-11 09:36:23 +05:30
8e42162b5e Merge pull request #278 from sarbjitsinghgrewal/fix_bitbucket_publish_description
Fix bitbucket publish description
2023-09-10 14:13:26 +03:00
98d0835c48 Merge remote-tracking branch 'origin/main' into fix_bitbucket_publish_description 2023-09-10 14:08:17 +03:00
2aef9dfe55 Merge remote-tracking branch 'origin/main' into fix_bitbucket_publish_description 2023-09-10 14:06:54 +03:00
115b513c9b Remove 'bitbucket' explicit dependency anywhere that's not in bitbucket_provider.py 2023-09-10 14:06:13 +03:00
fd63fe4c95 Merge pull request #293 from Codium-ai/tr/litellm_debugger
Integration of Litellm Client with AI Handler
2023-09-10 13:56:06 +03:00
d40285e4d3 Merge branch 'main' into tr/litellm_debugger 2023-09-10 13:40:35 +03:00
517658fb37 Merge pull request #282 from Codium-ai/tr/issue_tool
Adding Similar Issue Tool and Pinecone Integration
2023-09-10 13:39:34 +03:00
f9f0f220c2 pinecone-datasets 2023-09-10 13:31:36 +03:00
6382b8a68b LITELLM_TOKEN 2023-09-10 13:28:56 +03:00
e371b217ec Merge remote-tracking branch 'origin/main' into tr/litellm_debugger 2023-09-10 13:27:19 +03:00
7dec7b0583 Merge pull request #291 from krrishdholakia/main
adding documentation on how to call local hf models
2023-09-10 13:25:44 +03:00
bf6a235add pinecone-datasets==0.6.1 2023-09-10 13:16:05 +03:00
1d9489c734 Merge remote-tracking branch 'origin/tr/issue_tool' into tr/issue_tool 2023-09-10 08:39:20 +03:00
bd588b4509 solved dependencies 2023-09-10 08:39:03 +03:00
245f29e58a solved dependencies 2023-09-10 08:22:42 +03:00
7f5f2d2d1a solved dependencies 2023-09-10 08:07:39 +03:00
fe500845b7 upgrade pip 2023-09-10 07:46:51 +03:00
b42b2536b5 upgrade pip 2023-09-10 07:39:01 +03:00
498ad3d19c upgrade pip 2023-09-10 07:36:25 +03:00
892dbe458e litellm client 2023-09-09 17:35:45 +03:00
1b098aea13 adding documentation on how to call local hf models 2023-09-08 09:59:44 -07:00
ed1816a2d7 Merge branch 'main' of https://github.com/Codium-ai/pr-agent into fix_bitbucket_publish_description 2023-09-08 11:24:05 +05:30
e90c9e5853 Merge pull request #287 from cloudlinux/gerrit
[gerrit] Added support project's config file: `.pr_agent.toml`
2023-09-07 19:06:32 +03:00
e4f28b157f Added support project's config file: .pr_agent.toml
+ removed markdown/html formatting from the review due to gerrit does not support it
2023-09-07 13:13:07 +01:00
6fb8a882af ordering requirements.txt 2023-09-07 12:41:31 +03:00
9889d26d3e merged main 2023-09-07 12:31:22 +03:00
b23a4c0535 Merge remote-tracking branch 'origin/main' into tr/issue_tool
# Conflicts:
#	requirements.txt
2023-09-07 12:30:16 +03:00
0f7a481eaa Merge pull request #277 from krrishdholakia/hf-usage
Showing how to use huggingface models with PR-Agent
2023-09-07 12:28:47 +03:00
3fc88b2bc4 Merge pull request #276 from krrishdholakia/main
Add docs on using Azure
2023-09-07 12:20:26 +03:00
ed5aaaab45 Merge branch 'main' into main 2023-09-07 12:19:59 +03:00
145b5db458 added 'publish_description_as_comment' support 2023-09-07 12:10:33 +03:00
8321792a8d == 2023-09-06 18:12:16 +03:00
8af8fd8e5d github action 2023-09-06 17:43:43 +03:00
753ea3e44c Update INSTALL.md 2023-09-06 11:35:41 +03:00
660601f7c5 Merge pull request #280 from Codium-ai/coditamar/install
Update INSTALL.md
2023-09-06 11:32:18 +03:00
4e7f67f596 Merge pull request #279 from Codium-ai/coditamar/readme-minor-enhancement
Enhancements to README.md for Improved Clarity and Detail
2023-09-06 11:31:55 +03:00
e486addb8f Update INSTALL.md
minor clarification to Method 8 GitLab
2023-09-06 11:28:19 +03:00
4a5310e2a1 Update README.md 2023-09-06 10:46:25 +03:00
8962c9cf8a stable 2023-09-06 09:43:23 +03:00
bc95cf5b8e stable 2023-09-06 09:12:25 +03:00
dcd8196b94 Merge remote-tracking branch 'origin/main' into tr/issue_tool
# Conflicts:
#	pr_agent/settings/configuration.toml
2023-09-06 08:43:41 +03:00
901c1dc3f0 issue tool 2023-09-06 08:43:01 +03:00
adb9964823 Merge branch 'main' of https://github.com/Codium-ai/pr-agent into fix_bitbucket_publish_description 2023-09-06 09:32:43 +05:30
335877c4a7 fix publish description for bitbucket 2023-09-06 09:26:23 +05:30
5da6a0147c showing how to use huggingface models 2023-09-05 16:23:22 -07:00
cd1ae55f4f bump litellm version to fix azure deployment id error 2023-09-05 15:26:45 -07:00
ca50724952 adding details on calling azure 2023-09-05 15:19:56 -07:00
c0b23e1091 Merge remote-tracking branch 'origin/main' into tr/issue_tool
# Conflicts:
#	pr_agent/algo/utils.py
2023-09-05 08:05:33 +03:00
704c169181 Merge branch 'main' of https://github.com/Codium-ai/pr-agent into fix_bitbucket_improve_issue 2023-09-05 10:00:07 +05:30
746140b26e Add support for markers in description 2023-09-04 12:11:39 -04:00
970a7896e9 Merge branch 'main' of https://github.com/Codium-ai/pr-agent into fix_bitbucket_improve_issue 2023-08-31 13:35:32 +05:30
2aaa722102 Merge branch 'main' of https://github.com/Codium-ai/pr-agent into fix_bitbucket_improve_issue 2023-08-29 09:49:19 +05:30
39522abc03 fix conflicts 2023-08-28 11:21:47 +05:30
0e42634da4 add publish_labels and get_labels functions 2023-08-25 10:15:30 +05:30
f0dc485305 Merge branch 'main' of https://github.com/Codium-ai/pr-agent into fix_bitbucket_improve_issue 2023-08-24 16:14:29 +05:30
db6bf41051 update readme 2023-08-24 15:56:20 +05:30
67ff50583a fix improve, update_changelog and review inline comment 2023-08-24 11:52:20 +05:30
6693aa3cbc semi stable 2023-08-20 15:01:06 +03:00
154 changed files with 12859 additions and 2683 deletions

View File

@ -2,8 +2,11 @@ name: Build-and-test
on:
push:
branches:
- main
pull_request:
types: [ opened, reopened ]
branches:
- main
jobs:
build-and-test:

33
.github/workflows/docs-ci.yaml vendored Normal file
View File

@ -0,0 +1,33 @@
name: docs-ci
on:
push:
branches:
- main
- add-docs-portal
paths:
- docs/**
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: actions/setup-python@v5
with:
python-version: 3.x
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
- uses: actions/cache@v4
with:
key: mkdocs-material-${{ env.cache_id }}
path: .cache
restore-keys: |
mkdocs-material-
- run: pip install mkdocs-material
- run: pip install "mkdocs-material[imaging]"
- run: pip install mkdocs-glightbox
- run: mkdocs gh-deploy -f docs/mkdocs.yml --force

View File

@ -5,8 +5,9 @@
name: PR-Agent
on:
pull_request:
issue_comment:
# pull_request:
# issue_comment:
workflow_dispatch:
permissions:
issues: write
@ -24,4 +25,11 @@ jobs:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
OPENAI_ORG: ${{ secrets.OPENAI_ORG }} # optional
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PINECONE.API_KEY: ${{ secrets.PINECONE_API_KEY }}
PINECONE.ENVIRONMENT: ${{ secrets.PINECONE_ENVIRONMENT }}
GITHUB_ACTION_CONFIG.AUTO_DESCRIBE: true
GITHUB_ACTION_CONFIG.AUTO_REVIEW: true
GITHUB_ACTION_CONFIG.AUTO_IMPROVE: true

5
.gitignore vendored
View File

@ -1,8 +1,11 @@
.idea/
.lsp/
.vscode/
venv/
pr_agent/settings/.secrets.toml
__pycache__
dist/
*.egg-info/
build/
review.md
.DS_Store
docs/.cache/

3
.pr_agent.toml Normal file
View File

@ -0,0 +1,3 @@
[pr_reviewer]
enable_review_labels_effort = true
enable_auto_approval = true

View File

@ -1,373 +0,0 @@
## Installation
To get started with PR-Agent quickly, you first need to acquire two tokens:
1. An OpenAI key from [here](https://platform.openai.com/), with access to GPT-4.
2. A GitHub personal access token (classic) with the repo scope.
There are several ways to use PR-Agent:
- [Method 1: Use Docker image (no installation required)](INSTALL.md#method-1-use-docker-image-no-installation-required)
- [Method 2: Run from source](INSTALL.md#method-2-run-from-source)
- [Method 3: Run as a GitHub Action](INSTALL.md#method-3-run-as-a-github-action)
- [Method 4: Run as a polling server](INSTALL.md#method-4-run-as-a-polling-server)
- [Method 5: Run as a GitHub App](INSTALL.md#method-5-run-as-a-github-app)
- [Method 6: Deploy as a Lambda Function](INSTALL.md#method-6---deploy-as-a-lambda-function)
- [Method 7: AWS CodeCommit](INSTALL.md#method-7---aws-codecommit-setup)
- [Method 8: Run a GitLab webhook server](INSTALL.md#method-8---run-a-gitlab-webhook-server)
---
### Method 1: Use Docker image (no installation required)
To request a review for a PR, or ask a question about a PR, you can run directly from the Docker image. Here's how:
1. To request a review for a PR, run the following command:
```
docker run --rm -it -e OPENAI.KEY=<your key> -e GITHUB.USER_TOKEN=<your token> codiumai/pr-agent --pr_url <pr_url> review
```
2. To ask a question about a PR, run the following command:
```
docker run --rm -it -e OPENAI.KEY=<your key> -e GITHUB.USER_TOKEN=<your token> codiumai/pr-agent --pr_url <pr_url> ask "<your question>"
```
Note: If you want to ensure you're running a specific version of the Docker image, consider using the image's digest.
The digest is a unique identifier for a specific version of an image. You can pull and run an image using its digest by referencing it like so: repository@sha256:digest. Always ensure you're using the correct and trusted digest for your operations.
1. To request a review for a PR using a specific digest, run the following command:
```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
```
2. To ask a question about a PR using the same digest, run the following command:
```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> ask "<your question>"
```
Possible questions you can ask include:
- What is the main theme of this PR?
- Is the PR ready for merge?
- What are the main changes in this PR?
- Should this PR be split into smaller parts?
- Can you compose a rhymed song about this PR?
---
### Method 2: Run from source
1. Clone this repository:
```
git clone https://github.com/Codium-ai/pr-agent.git
```
2. Install the requirements in your favorite virtual environment:
```
pip install -r requirements.txt
```
3. Copy the secrets template file and fill in your OpenAI key and your GitHub user token:
```
cp pr_agent/settings/.secrets_template.toml pr_agent/settings/.secrets.toml
chmod 600 pr_agent/settings/.secrets.toml
# Edit .secrets.toml file
```
4. Add the pr_agent folder to your PYTHONPATH, then run the cli.py script:
```
export PYTHONPATH=[$PYTHONPATH:]<PATH to pr_agent folder>
python pr_agent/cli.py --pr_url <pr_url> /review
python pr_agent/cli.py --pr_url <pr_url> /ask <your question>
python pr_agent/cli.py --pr_url <pr_url> /describe
python pr_agent/cli.py --pr_url <pr_url> /improve
```
---
### Method 3: Run as a GitHub Action
You can use our pre-built Github Action Docker image to run PR-Agent as a Github Action.
1. Add the following file to your repository under `.github/workflows/pr_agent.yml`:
```yaml
on:
pull_request:
issue_comment:
jobs:
pr_agent_job:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
contents: write
name: Run pr agent on every pull request, respond to user comments
steps:
- name: PR Agent action step
id: pragent
uses: Codium-ai/pr-agent@main
env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
** if you want to pin your action to a specific commit for stability reasons
```yaml
on:
pull_request:
issue_comment:
jobs:
pr_agent_job:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
contents: write
name: Run pr agent on every pull request, respond to user comments
steps:
- name: PR Agent action step
id: pragent
uses: Codium-ai/pr-agent@<commit_sha>
env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
2. Add the following secret to your repository under `Settings > Secrets`:
```
OPENAI_KEY: <your key>
```
The GITHUB_TOKEN secret is automatically created by GitHub.
3. Merge this change to your main branch.
When you open your next PR, you should see a comment from `github-actions` bot with a review of your PR, and instructions on how to use the rest of the tools.
4. You may configure PR-Agent by adding environment variables under the env section corresponding to any configurable property in the [configuration](./Usage.md) file. Some examples:
```yaml
env:
# ... previous environment values
OPENAI.ORG: "<Your organization name under your OpenAI account>"
PR_REVIEWER.REQUIRE_TESTS_REVIEW: "false" # Disable tests review
PR_CODE_SUGGESTIONS.NUM_CODE_SUGGESTIONS: 6 # Increase number of code suggestions
```
---
### Method 4: Run as a polling server
Request reviews by tagging your Github user on a PR
Follow steps 1-3 of method 2.
Run the following command to start the server:
```
python pr_agent/servers/github_polling.py
```
---
### Method 5: Run as a GitHub App
Allowing you to automate the review process on your private or public repositories.
1. Create a GitHub App from the [Github Developer Portal](https://docs.github.com/en/developers/apps/creating-a-github-app).
- Set the following permissions:
- Pull requests: Read & write
- Issue comment: Read & write
- Metadata: Read-only
- Contents: Read-only
- Set the following events:
- Issue comment
- Pull request
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))")
```
3. Acquire the following pieces of information from your app's settings page:
- App private key (click "Generate a private key" and save the file)
- App ID
4. Clone this repository:
```
git clone https://github.com/Codium-ai/pr-agent.git
```
5. Copy the secrets template file and fill in the following:
```
cp pr_agent/settings/.secrets_template.toml pr_agent/settings/.secrets.toml
# Edit .secrets.toml file
```
- Your OpenAI key.
- Copy your app's private key to the private_key field.
- Copy your app's ID to the app_id field.
- Copy your app's webhook secret to the webhook_secret field.
- Set deployment_type to 'app' in [configuration.toml](./pr_agent/settings/configuration.toml)
> The .secrets.toml file is not copied to the Docker image by default, and is only used for local development.
> If you want to use the .secrets.toml file in your Docker image, you can add remove it from the .dockerignore file.
> In most production environments, you would inject the secrets file as environment variables or as mounted volumes.
> For example, in order to inject a secrets file as a volume in a Kubernetes environment you can update your pod spec to include the following,
> assuming you have a secret named `pr-agent-settings` with a key named `.secrets.toml`:
```
volumes:
- name: settings-volume
secret:
secretName: pr-agent-settings
// ...
containers:
// ...
volumeMounts:
- mountPath: /app/pr_agent/settings_prod
name: settings-volume
```
> Another option is to set the secrets as environment variables in your deployment environment, for example `OPENAI.KEY` and `GITHUB.USER_TOKEN`.
6. 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 codiumai/pr-agent:github_app --target github_app -f docker/Dockerfile
docker push codiumai/pr-agent:github_app # Push to your Docker repository
```
7. Host the app using a server, serverless function, or container environment. Alternatively, for development and
debugging, you may use tools like smee.io to forward webhooks to your local machine.
You can check [Deploy as a Lambda Function](#deploy-as-a-lambda-function)
8. Go back to your app's settings, and set the following:
- Webhook URL: The URL of your app's server or the URL of the smee.io channel.
- Webhook secret: The secret you generated earlier.
9. Install the app by navigating to the "Install App" tab and selecting your desired repositories.
> **Note:** When running PR-Agent from GitHub App, the default configuration file (configuration.toml) will be loaded.<br>
> However, you can override the default tool parameters by uploading a local configuration file<br>
> For more information please check out [CONFIGURATION.md](Usage.md#working-from-github-app-pre-built-repo)
---
### Method 6 - Deploy as a Lambda Function
1. Follow steps 1-5 of [Method 5](#method-5-run-as-a-github-app).
2. Build a docker image that can be used as a lambda function
```shell
docker buildx build --platform=linux/amd64 . -t codiumai/pr-agent:serverless -f docker/Dockerfile.lambda
```
3. Push image to ECR
```shell
docker tag codiumai/pr-agent:serverless <AWS_ACCOUNT>.dkr.ecr.<AWS_REGION>.amazonaws.com/codiumai/pr-agent:serverless
docker push <AWS_ACCOUNT>.dkr.ecr.<AWS_REGION>.amazonaws.com/codiumai/pr-agent:serverless
```
4. Create a lambda function that uses the uploaded image. Set the lambda timeout to be at least 3m.
5. Configure the lambda function to have a Function URL.
6. Go back to steps 8-9 of [Method 5](#method-5-run-as-a-github-app) with the function url as your Webhook URL.
The Webhook URL would look like `https://<LAMBDA_FUNCTION_URL>/api/v1/github_webhooks`
---
### Method 7 - AWS CodeCommit Setup
Not all features have been added to CodeCommit yet. As of right now, CodeCommit has been implemented to run the pr-agent CLI on the command line, using AWS credentials stored in environment variables. (More features will be added in the future.) The following is a set of instructions to have pr-agent do a review of your CodeCommit pull request from the command line:
1. Create an IAM user that you will use to read CodeCommit pull requests and post comments
* Note: That user should have CLI access only, not Console access
2. Add IAM permissions to that user, to allow access to CodeCommit (see IAM Role example below)
3. Generate an Access Key for your IAM user
4. Set the Access Key and Secret using environment variables (see Access Key example below)
5. Set the `git_provider` value to `codecommit` in the `pr_agent/settings/configuration.toml` settings file
6. Set the `PYTHONPATH` to include your `pr-agent` project directory
* Option A: Add `PYTHONPATH="/PATH/TO/PROJECTS/pr-agent` to your `.env` file
* Option B: Set `PYTHONPATH` and run the CLI in one command, for example:
* `PYTHONPATH="/PATH/TO/PROJECTS/pr-agent python pr_agent/cli.py [--ARGS]`
##### AWS CodeCommit IAM Role Example
Example IAM permissions to that user to allow access to CodeCommit:
* Note: The following is a working example of IAM permissions that has read access to the repositories and write access to allow posting comments
* Note: If you only want pr-agent to review your pull requests, you can tighten the IAM permissions further, however this IAM example will work, and allow the pr-agent to post comments to the PR
* Note: You may want to replace the `"Resource": "*"` with your list of repos, to limit access to only those repos
```
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"codecommit:BatchDescribe*",
"codecommit:BatchGet*",
"codecommit:Describe*",
"codecommit:EvaluatePullRequestApprovalRules",
"codecommit:Get*",
"codecommit:List*",
"codecommit:PostComment*",
"codecommit:PutCommentReaction",
"codecommit:UpdatePullRequestDescription",
"codecommit:UpdatePullRequestTitle"
],
"Resource": "*"
}
]
}
```
##### AWS CodeCommit Access Key and Secret
Example setting the Access Key and Secret using environment variables
```sh
export AWS_ACCESS_KEY_ID="XXXXXXXXXXXXXXXX"
export AWS_SECRET_ACCESS_KEY="XXXXXXXXXXXXXXXX"
export AWS_DEFAULT_REGION="us-east-1"
```
##### AWS CodeCommit CLI Example
After you set up AWS CodeCommit using the instructions above, here is an example CLI run that tells pr-agent to **review** a given pull request.
(Replace your specific PYTHONPATH and PR URL in the example)
```sh
PYTHONPATH="/PATH/TO/PROJECTS/pr-agent" python pr_agent/cli.py \
--pr_url https://us-east-1.console.aws.amazon.com/codesuite/codecommit/repositories/MY_REPO_NAME/pull-requests/321 \
review
```
---
### Method 8 - Run a GitLab webhook server
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:
```
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 [Method 5](#method-5-run-as-a-github-app).
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](./pr_agent/settings/configuration.toml)
5. Create a webhook in GitLab. Set the URL to the URL of your app's server. Set the secret token to the generated secret from step 2.
In the "Trigger" section, check the comments and merge request events boxes.
6. Test your installation by opening a merge request or commenting or a merge request using one of CodiumAI's commands.
---
### Appendix - **Debugging LLM API Calls**
If you're testing your codium/pr-agent server, and need to see if calls were made successfully + the exact call logs, you can use the [LiteLLM Debugger tool](https://docs.litellm.ai/docs/debugging/hosted_debugging).
You can do this by setting `litellm_debugger=true` in configuration.toml. Your Logs will be viewable in real-time @ `admin.litellm.ai/<your_email>`. Set your email in the `.secrets.toml` under 'user_email'.
<img src="./pics/debugger.png" width="800"/>

2
MANIFEST.in Normal file
View File

@ -0,0 +1,2 @@
recursive-include pr_agent *.toml
recursive-exclude pr_agent *.secrets.toml

319
README.md
View File

@ -2,47 +2,173 @@
<div align="center">
<img src="./pics/logo-dark.png#gh-dark-mode-only" width="330"/>
<img src="./pics/logo-light.png#gh-light-mode-only" width="330"/><br/>
Making pull requests less painful with an AI agent
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://codium.ai/images/pr_agent/logo-dark.png" width="330">
<source media="(prefers-color-scheme: light)" srcset="https://codium.ai/images/pr_agent/logo-light.png" width="330">
<img src="https://codium.ai/images/pr_agent/logo-light.png" alt="logo" width="330">
</picture>
<br/>
CodiumAI PR-Agent aims to help efficiently review and handle pull requests, by providing AI feedbacks and suggestions
</div>
[![GitHub license](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://github.com/Codium-ai/pr-agent/blob/main/LICENSE)
[![Static Badge](https://img.shields.io/badge/Chrome-Extension-violet)](https://chromewebstore.google.com/detail/pr-agent-chrome-extension/ephlnjeghhogofkifjloamocljapahnl)
[![Static Badge](https://img.shields.io/badge/Code-Benchmark-blue)](https://pr-agent-docs.codium.ai/finetuning_benchmark/)
[![Discord](https://badgen.net/badge/icon/discord?icon=discord&label&color=purple)](https://discord.com/channels/1057273017547378788/1126104260430528613)
[![Twitter](https://img.shields.io/twitter/follow/codiumai)](https://twitter.com/codiumai)
<a href="https://github.com/Codium-ai/pr-agent/commits/main">
<img alt="GitHub" src="https://img.shields.io/github/last-commit/Codium-ai/pr-agent/main?style=for-the-badge" height="20">
</a>
</div>
### [Documentation](https://pr-agent-docs.codium.ai/)
- See the [Installation Guide](https://pr-agent-docs.codium.ai/installation/) for instructions on installing PR-Agent on different platforms.
- See the [Usage Guide](https://pr-agent-docs.codium.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://pr-agent-docs.codium.ai/tools/) for a detailed description of the different tools, and the available configurations for each tool.
## Table of Contents
- [News and Updates](#news-and-updates)
- [Overview](#overview)
- [Example results](#example-results)
- [Try it now](#try-it-now)
- [PR-Agent Pro 💎](#pr-agent-pro-)
- [How it works](#how-it-works)
- [Why use PR-Agent?](#why-use-pr-agent)
## News and Updates
### July 4, 2024
Added improved support for claude-sonnet-3.5 model (anthropic, vertex, bedrock), including dedicated prompts.
### June 17, 2024
New option for a self-review checkbox is now available for the `/improve` tool, along with the ability(💎) to enable auto-approve, or demand self-review in addition to human reviewer. See more [here](https://pr-agent-docs.codium.ai/tools/improve/#self-review).
<kbd><img src="https://www.codium.ai/images/pr_agent/self_review_1.png" width="512"></kbd>
### June 6, 2024
New option now available (💎) - **apply suggestions**:
<kbd><img src="https://www.codium.ai/images/pr_agent/apply_suggestion_1.png" width="512"></kbd>
&rarr;
<kbd><img src="https://www.codium.ai/images/pr_agent/apply_suggestion_2.png" width="512"></kbd>
## Overview
<div style="text-align:left;">
CodiumAI `PR-Agent` is an open-source tool aiming to help developers review pull requests faster and more efficiently. It automatically analyzes the pull request and can provide several types of PR feedback:
Supported commands per platform:
**Auto Description (/describe)**: Automatically generating [PR description](https://github.com/Codium-ai/pr-agent/pull/229#issue-1860711415) - title, type, summary, code walkthrough and labels.
\
**Auto Review (/review)**: [Adjustable feedback](https://github.com/Codium-ai/pr-agent/pull/229#issuecomment-1695022908) about the PR main theme, type, relevant tests, security issues, score, and various suggestions for the PR content.
\
**Question Answering (/ask ...)**: Answering [free-text questions](https://github.com/Codium-ai/pr-agent/pull/229#issuecomment-1695021332) about the PR.
\
**Code Suggestions (/improve)**: [Committable code suggestions](https://github.com/Codium-ai/pr-agent/pull/229#discussion_r1306919276) for improving the PR.
\
**Update Changelog (/update_changelog)**: Automatically updating the CHANGELOG.md file with the [PR changes](https://github.com/Codium-ai/pr-agent/pull/168#discussion_r1282077645).
| | | GitHub | Gitlab | Bitbucket | Azure DevOps |
|-------|---------------------------------------------------------------------------------------------------------|:--------------------:|:--------------------:|:--------------------:|:--------------------:|
| TOOLS | Review | ✅ | ✅ | ✅ | ✅ |
| | ⮑ Incremental | ✅ | | | |
| | ⮑ [SOC2 Compliance](https://pr-agent-docs.codium.ai/tools/review/#soc2-ticket-compliance) 💎 | ✅ | ✅ | ✅ | ✅ |
| | Describe | ✅ | ✅ | ✅ | ✅ |
| | ⮑ [Inline File Summary](https://pr-agent-docs.codium.ai/tools/describe#inline-file-summary) 💎 | ✅ | | | |
| | Improve | ✅ | ✅ | ✅ | ✅ |
| | ⮑ Extended | ✅ | ✅ | ✅ | ✅ |
| | Ask | ✅ | ✅ | ✅ | ✅ |
| | ⮑ [Ask on code lines](https://pr-agent-docs.codium.ai/tools/ask#ask-lines) | ✅ | ✅ | | |
| | [Custom Prompt](https://pr-agent-docs.codium.ai/tools/custom_prompt/) 💎 | ✅ | ✅ | ✅ | ✅ |
| | [Test](https://pr-agent-docs.codium.ai/tools/test/) 💎 | ✅ | ✅ | | ✅ |
| | Reflect and Review | ✅ | ✅ | ✅ | ✅ |
| | Update CHANGELOG.md | ✅ | ✅ | ✅ | ✅ |
| | Find Similar Issue | ✅ | | | |
| | [Add PR Documentation](https://pr-agent-docs.codium.ai/tools/documentation/) 💎 | ✅ | ✅ | | ✅ |
| | [Custom Labels](https://pr-agent-docs.codium.ai/tools/custom_labels/) 💎 | ✅ | ✅ | | ✅ |
| | [Analyze](https://pr-agent-docs.codium.ai/tools/analyze/) 💎 | ✅ | ✅ | | ✅ |
| | [CI Feedback](https://pr-agent-docs.codium.ai/tools/ci_feedback/) 💎 | ✅ | | | |
| | [Similar Code](https://pr-agent-docs.codium.ai/tools/similar_code/) 💎 | ✅ | | | |
| | | | | | |
| USAGE | CLI | ✅ | ✅ | ✅ | ✅ |
| | App / webhook | ✅ | ✅ | ✅ | ✅ |
| | Tagging bot | ✅ | | | |
| | Actions | ✅ | | ✅ | |
| | | | | | |
| CORE | PR compression | ✅ | ✅ | ✅ | ✅ |
| | Repo language prioritization | ✅ | ✅ | ✅ | ✅ |
| | Adaptive and token-aware file patch fitting | ✅ | ✅ | ✅ | ✅ |
| | Multiple models support | ✅ | ✅ | ✅ | ✅ |
| | [Static code analysis](https://pr-agent-docs.codium.ai/core-abilities/#static-code-analysis) 💎 | ✅ | ✅ | ✅ | ✅ |
| | [Global and wiki configurations](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/) 💎 | ✅ | ✅ | ✅ | ✅ |
| | [PR interactive actions](https://www.codium.ai/images/pr_agent/pr-actions.mp4) 💎 | ✅ | | | |
- 💎 means this feature is available only in [PR-Agent Pro](https://www.codium.ai/pricing/)
[//]: # (- Support for additional git providers is described in [here]&#40;./docs/Full_environments.md&#41;)
___
See the [usage guide](./Usage.md) for instructions how to run the different tools from [CLI](./Usage.md#working-from-a-local-repo-cli), or by [online usage](./Usage.md#online-usage).
**Auto Description ([`/describe`](https://pr-agent-docs.codium.ai/tools/describe/))**: Automatically generating PR description - title, type, summary, code walkthrough and labels.
\
**Auto Review ([`/review`](https://pr-agent-docs.codium.ai/tools/review/))**: Adjustable feedback about the PR, possible issues, security concerns, review effort and more.
\
**Code Suggestions ([`/improve`](https://pr-agent-docs.codium.ai/tools/improve/))**: Code suggestions for improving the PR.
\
**Question Answering ([`/ask ...`](https://pr-agent-docs.codium.ai/tools/ask/))**: Answering free-text questions about the PR.
\
**Update Changelog ([`/update_changelog`](https://pr-agent-docs.codium.ai/tools/update_changelog/))**: Automatically updating the CHANGELOG.md file with the PR changes.
\
**Find Similar Issue ([`/similar_issue`](https://pr-agent-docs.codium.ai/tools/similar_issues/))**: Automatically retrieves and presents similar issues.
\
**Add Documentation 💎 ([`/add_docs`](https://pr-agent-docs.codium.ai/tools/documentation/))**: Generates documentation to methods/functions/classes that changed in the PR.
\
**Generate Custom Labels 💎 ([`/generate_labels`](https://pr-agent-docs.codium.ai/tools/custom_labels/))**: Generates custom labels for the PR, based on specific guidelines defined by the user.
\
**Analyze 💎 ([`/analyze`](https://pr-agent-docs.codium.ai/tools/analyze/))**: Identify code components that changed in the PR, and enables to interactively generate tests, docs, and code suggestions for each component.
\
**Custom Prompt 💎 ([`/custom_prompt`](https://pr-agent-docs.codium.ai/tools/custom_prompt/))**: Automatically generates custom suggestions for improving the PR code, based on specific guidelines defined by the user.
\
**Generate Tests 💎 ([`/test component_name`](https://pr-agent-docs.codium.ai/tools/test/))**: Generates unit tests for a selected component, based on the PR code changes.
\
**CI Feedback 💎 ([`/checks ci_job`](https://pr-agent-docs.codium.ai/tools/ci_feedback/))**: Automatically generates feedback and analysis for a failed CI job.
\
**Similar Code 💎 ([`/find_similar_component`](https://pr-agent-docs.codium.ai/tools/similar_code/))**: Retrieves the most similar code components from inside the organization's codebase, or from open-source code.
___
<h3>Example results:</h3>
## Example results
</div>
<h4><a href="https://github.com/Codium-ai/pr-agent/pull/229#issuecomment-1687561986">/describe:</a></h4>
<h4><a href="https://github.com/Codium-ai/pr-agent/pull/530">/describe</a></h4>
<div align="center">
<p float="center">
<img src="https://www.codium.ai/images/describe-2.gif" width="800">
<img src="https://www.codium.ai/images/pr_agent/describe_new_short_main.png" width="512">
</p>
</div>
<hr>
<h4><a href="https://github.com/Codium-ai/pr-agent/pull/229#issuecomment-1695021901">/review:</a></h4>
<h4><a href="https://github.com/Codium-ai/pr-agent/pull/732#issuecomment-1975099151">/review</a></h4>
<div align="center">
<p float="center">
<img src="https://www.codium.ai/images/review-2.gif" width="800">
<kbd>
<img src="https://www.codium.ai/images/pr_agent/review_new_short_main.png" width="512">
</kbd>
</p>
</div>
<hr>
<h4><a href="https://github.com/Codium-ai/pr-agent/pull/732#issuecomment-1975099159">/improve</a></h4>
<div align="center">
<p float="center">
<kbd>
<img src="https://www.codium.ai/images/pr_agent/improve_new_short_main.png" width="512">
</kbd>
</p>
</div>
<hr>
<h4><a href="https://github.com/Codium-ai/pr-agent/pull/530">/generate_labels</a></h4>
<div align="center">
<p float="center">
<kbd><img src="https://www.codium.ai/images/pr_agent/geneare_custom_labels_main_short.png" width="300"></kbd>
</p>
</div>
@ -83,46 +209,14 @@ See the [usage guide](./Usage.md) for instructions how to run the different tool
[//]: # (</div>)
<div align="left">
## Table of Contents
- [Overview](#overview)
- [Try it now](#try-it-now)
- [Installation](#installation)
- [Usage guide](./Usage.md)
- [How it works](#how-it-works)
- [Why use PR-Agent](#why-use-pr-agent)
- [Roadmap](#roadmap)
</div>
<hr>
## Overview
`PR-Agent` offers extensive pull request functionalities across various git providers:
| | | GitHub | Gitlab | Bitbucket | CodeCommit | Azure DevOps | Gerrit |
|-------|---------------------------------------------|:------:|:------:|:---------:|:----------:|:----------:|:----------:|
| TOOLS | Review | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| | Ask | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| | Auto-Description | :white_check_mark: | :white_check_mark: | | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| | Improve Code | :white_check_mark: | :white_check_mark: | | :white_check_mark: | | :white_check_mark: |
| | ⮑ Extended | :white_check_mark: | :white_check_mark: | | :white_check_mark: | | :white_check_mark: |
| | Reflect and Review | :white_check_mark: | | | | :white_check_mark: | :white_check_mark: |
| | Update CHANGELOG.md | :white_check_mark: | | | | | |
| | | | | | | |
| USAGE | CLI | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| | App / webhook | :white_check_mark: | :white_check_mark: | | | |
| | Tagging bot | :white_check_mark: | | | | |
| | Actions | :white_check_mark: | | | | |
| | Web server | | | | | | :white_check_mark: |
| | | | | | | |
| CORE | PR compression | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| | Repo language prioritization | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| | Adaptive and token-aware<br />file patch fitting | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| | Multiple models support | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| | Incremental PR Review | :white_check_mark: | | | | | |
Review the **[usage guide](./Usage.md)** section for detailed instructions how to use the different tools, select the relevant git provider (GitHub, Gitlab, Bitbucket,...), and adjust the configuration file to your needs.
## Try it now
You can try GPT-4 powered PR-Agent, on your public GitHub repository, instantly. Just mention `@CodiumAI-Agent` and add the desired command in any PR comment. The agent will generate a response based on your command.
Try the GPT-4 powered PR-Agent instantly on _your public GitHub repository_. Just mention `@CodiumAI-Agent` and add the desired command in any PR comment. The agent will generate a response based on your command.
For example, add a comment to any pull request with the following text:
```
@CodiumAI-Agent /review
@ -132,71 +226,104 @@ and the agent will respond with a review of your PR
![Review generation process](https://www.codium.ai/images/demo-2.gif)
To set up your own PR-Agent, see the [Installation](#installation) section below.
To set up your own PR-Agent, see the [Installation](https://pr-agent-docs.codium.ai/installation/) section below.
Note that when you set your own PR-Agent or use CodiumAI hosted PR-Agent, there is no need to mention `@CodiumAI-Agent ...`. Instead, directly start with the command, e.g., `/ask ...`.
---
## Installation
[//]: # (## Installation)
To get started with PR-Agent quickly, you first need to acquire two tokens:
[//]: # (To use your own version of PR-Agent, you first need to acquire two tokens:)
1. An OpenAI key from [here](https://platform.openai.com/), with access to GPT-4.
2. A GitHub personal access token (classic) with the repo scope.
[//]: # ()
[//]: # (1. An OpenAI key from [here]&#40;https://platform.openai.com/&#41;, with access to GPT-4.)
[//]: # (2. A GitHub personal access token &#40;classic&#41; with the repo scope.)
[//]: # ()
[//]: # (There are several ways to use PR-Agent:)
[//]: # ()
[//]: # (**Locally**)
[//]: # (- [Using pip package]&#40;https://pr-agent-docs.codium.ai/installation/locally/#using-pip-package&#41;)
[//]: # (- [Using Docker image]&#40;https://pr-agent-docs.codium.ai/installation/locally/#using-docker-image&#41;)
[//]: # (- [Run from source]&#40;https://pr-agent-docs.codium.ai/installation/locally/#run-from-source&#41;)
[//]: # ()
[//]: # (**GitHub specific methods**)
[//]: # (- [Run as a GitHub Action]&#40;https://pr-agent-docs.codium.ai/installation/github/#run-as-a-github-action&#41;)
[//]: # (- [Run as a GitHub App]&#40;https://pr-agent-docs.codium.ai/installation/github/#run-as-a-github-app&#41;)
[//]: # ()
[//]: # (**GitLab specific methods**)
[//]: # (- [Run a GitLab webhook server]&#40;https://pr-agent-docs.codium.ai/installation/gitlab/&#41;)
[//]: # ()
[//]: # (**BitBucket specific methods**)
[//]: # (- [Run as a Bitbucket Pipeline]&#40;https://pr-agent-docs.codium.ai/installation/bitbucket/&#41;)
## PR-Agent Pro 💎
[PR-Agent Pro](https://www.codium.ai/pricing/) is a hosted version of PR-Agent, provided by CodiumAI. It is available for a monthly fee, and provides the following benefits:
1. **Fully managed** - We take care of everything for you - hosting, models, regular updates, and more. Installation is as simple as signing up and adding the PR-Agent app to your GitHub\GitLab\BitBucket repo.
2. **Improved privacy** - No data will be stored or used to train models. PR-Agent Pro will employ zero data retention, and will use an OpenAI account with zero data retention.
3. **Improved support** - PR-Agent Pro users will receive priority support, and will be able to request new features and capabilities.
4. **Extra features** -In addition to the benefits listed above, PR-Agent Pro will emphasize more customization, and the usage of static code analysis, in addition to LLM logic, to improve results.
See [here](https://pr-agent-docs.codium.ai/#pr-agent-pro) for a list of features available in PR-Agent Pro.
There are several ways to use PR-Agent:
- [Method 1: Use Docker image (no installation required)](INSTALL.md#method-1-use-docker-image-no-installation-required)
- [Method 2: Run from source](INSTALL.md#method-2-run-from-source)
- [Method 3: Run as a GitHub Action](INSTALL.md#method-3-run-as-a-github-action)
- [Method 4: Run as a polling server](INSTALL.md#method-4-run-as-a-polling-server)
- Request reviews by tagging your GitHub user on a PR
- [Method 5: Run as a GitHub App](INSTALL.md#method-5-run-as-a-github-app)
- Allowing you to automate the review process on your private or public repositories
- [Method 6: Deploy as a Lambda Function](INSTALL.md#method-6---deploy-as-a-lambda-function)
- [Method 7: AWS CodeCommit](INSTALL.md#method-7---aws-codecommit-setup)
- [Method 8: Run a GitLab webhook server](INSTALL.md#method-8---run-a-gitlab-webhook-server)
## How it works
The following diagram illustrates PR-Agent tools and their flow:
![PR-Agent Tools](https://www.codium.ai/wp-content/uploads/2023/07/codiumai-diagram-v4.jpg)
![PR-Agent Tools](https://codium.ai/images/pr_agent/diagram-v0.9.png)
Check out the [PR Compression strategy](./PR_COMPRESSION.md) page for more details on how we convert a code diff to a manageable LLM prompt
Check out the [PR Compression strategy](https://pr-agent-docs.codium.ai/core-abilities/#pr-compression-strategy) page for more details on how we convert a code diff to a manageable LLM prompt
## Why use PR-Agent?
A reasonable question that can be asked is: `"Why use PR-Agent? What make it stand out from existing tools?"`
A reasonable question that can be asked is: `"Why use PR-Agent? What makes it stand out from existing tools?"`
Here are some advantages of PR-Agent:
- We emphasize **real-life practical usage**. Each tool (review, improve, ask, ...) has a single GPT-4 call, no more. We feel that this is critical for realistic team usage - obtaining an answer quickly (~30 seconds) and affordably.
- Our [PR Compression strategy](./PR_COMPRESSION.md) is a core ability that enables to effectively tackle both short and long PRs.
- Our [PR Compression strategy](https://pr-agent-docs.codium.ai/core-abilities/#pr-compression-strategy) is a core ability that enables to effectively tackle both short and long PRs.
- Our JSON prompting strategy enables to have **modular, customizable tools**. For example, the '/review' tool categories can be controlled via the [configuration](pr_agent/settings/configuration.toml) file. Adding additional categories is easy and accessible.
- We support **multiple git providers** (GitHub, Gitlab, Bitbucket, CodeCommit), **multiple ways** to use the tool (CLI, GitHub Action, GitHub App, Docker, ...), and **multiple models** (GPT-4, GPT-3.5, Anthropic, Cohere, Llama2).
- We are open-source, and welcome contributions from the community.
- We support **multiple git providers** (GitHub, Gitlab, Bitbucket), **multiple ways** to use the tool (CLI, GitHub Action, GitHub App, Docker, ...), and **multiple models** (GPT-4, GPT-3.5, Anthropic, Cohere, Llama2).
## Roadmap
## Data privacy
- [x] Support additional models, as a replacement for OpenAI (see [here](https://github.com/Codium-ai/pr-agent/pull/172))
- [x] Develop additional logic for handling large PRs (see [here](https://github.com/Codium-ai/pr-agent/pull/229))
- [ ] Add additional context to the prompt. For example, repo (or relevant files) summarization, with tools such a [ctags](https://github.com/universal-ctags/ctags)
- [ ] PR-Agent for issues, and just for pull requests
- [ ] Adding more tools. Possible directions:
- [x] PR description
- [x] Inline code suggestions
- [x] Reflect and review
- [x] Rank the PR (see [here](https://github.com/Codium-ai/pr-agent/pull/89))
- [ ] Enforcing CONTRIBUTING.md guidelines
- [ ] Performance (are there any performance issues)
- [ ] Documentation (is the PR properly documented)
- [ ] ...
### Self-hosted PR-Agent
## Similar Projects
- If you host PR-Agent with your OpenAI API key, it is between you and OpenAI. You can read their API data privacy policy here:
https://openai.com/enterprise-privacy
- [CodiumAI - Meaningful tests for busy devs](https://github.com/Codium-ai/codiumai-vscode-release) (although various capabilities are much more advanced in the CodiumAI IDE plugins)
- [Aider - GPT powered coding in your terminal](https://github.com/paul-gauthier/aider)
- [openai-pr-reviewer](https://github.com/coderabbitai/openai-pr-reviewer)
- [CodeReview BOT](https://github.com/anc95/ChatGPT-CodeReview)
- [AI-Maintainer](https://github.com/merwanehamadi/AI-Maintainer)
### CodiumAI-hosted PR-Agent Pro 💎
- When using PR-Agent Pro 💎, hosted by CodiumAI, we will not store any of your data, nor will we use it for training. You will also benefit from an OpenAI account with zero data retention.
- For certain clients, CodiumAI-hosted PR-Agent Pro will use CodiumAIs proprietary models — if this is the case, you will be notified.
- No passive collection of Code and Pull Requests data — PR-Agent will be active only when you invoke it, and it will then extract and analyze only data relevant to the executed command and queried pull request.
### PR-Agent Chrome extension
- The [PR-Agent Chrome extension](https://chromewebstore.google.com/detail/pr-agent-chrome-extension/ephlnjeghhogofkifjloamocljapahnl) serves solely to modify the visual appearance of a GitHub PR screen. It does not transmit any user's repo or pull request code. Code is only sent for processing when a user submits a GitHub comment that activates a PR-Agent tool, in accordance with the standard privacy policy of PR-Agent.
## Links
[![Join our Discord community](https://raw.githubusercontent.com/Codium-ai/codiumai-vscode-release/main/media/docs/Joincommunity.png)](https://discord.gg/kG35uSHDBc)
- Discord community: https://discord.gg/kG35uSHDBc
- CodiumAI site: https://codium.ai
- Blog: https://www.codium.ai/blog/
- Troubleshooting: https://www.codium.ai/blog/technical-faq-and-troubleshooting/
- Support: support@codium.ai

103
RELEASE_NOTES.md Normal file
View File

@ -0,0 +1,103 @@
## [Version 0.11] - 2023-12-07
- codiumai/pr-agent:0.11
- codiumai/pr-agent:0.11-github_app
- codiumai/pr-agent:0.11-bitbucket-app
- codiumai/pr-agent:0.11-gitlab_webhook
- codiumai/pr-agent:0.11-github_polling
- codiumai/pr-agent:0.11-github_action
### Added::Algo
- New section in `/describe` tool - [PR changes walkthrough](https://github.com/Codium-ai/pr-agent/pull/509)
- Improving PR Agent [prompts](https://github.com/Codium-ai/pr-agent/pull/501)
- Persistent tools (`/review`, `/describe`) now send an [update message](https://github.com/Codium-ai/pr-agent/pull/499) after finishing
- Add Amazon Bedrock [support](https://github.com/Codium-ai/pr-agent/pull/483)
### Fixed
- Update [dependencies](https://github.com/Codium-ai/pr-agent/pull/503) in requirements.txt for Python 3.12
## [Version 0.10] - 2023-11-15
- codiumai/pr-agent:0.10
- codiumai/pr-agent:0.10-github_app
- codiumai/pr-agent:0.10-bitbucket-app
- codiumai/pr-agent:0.10-gitlab_webhook
- codiumai/pr-agent:0.10-github_polling
- codiumai/pr-agent:0.10-github_action
### Added::Algo
- Review tool now works with [persistent comments](https://github.com/Codium-ai/pr-agent/pull/451) by default
- Bitbucket now publishes review suggestions with [code links](https://github.com/Codium-ai/pr-agent/pull/428)
- Enabling to limit [max number of tokens](https://github.com/Codium-ai/pr-agent/pull/437/files)
- Support ['gpt-4-1106-preview'](https://github.com/Codium-ai/pr-agent/pull/437/files) model
- Support for Google's [Vertex AI](https://github.com/Codium-ai/pr-agent/pull/436)
- Implementing [thresholds](https://github.com/Codium-ai/pr-agent/pull/423) for incremental PR reviews
- Decoupled custom labels from [PR type](https://github.com/Codium-ai/pr-agent/pull/431)
### Fixed
- Fixed bug in [parsing quotes](https://github.com/Codium-ai/pr-agent/pull/446) in CLI
- Preserve [user-added labels](https://github.com/Codium-ai/pr-agent/pull/433) in pull requests
- Bug fixes in GitLab and BitBucket
## [Version 0.9] - 2023-10-29
- codiumai/pr-agent:0.9
- codiumai/pr-agent:0.9-github_app
- codiumai/pr-agent:0.9-bitbucket-app
- codiumai/pr-agent:0.9-gitlab_webhook
- codiumai/pr-agent:0.9-github_polling
- codiumai/pr-agent:0.9-github_action
### Added::Algo
- New tool - [generate_labels](https://github.com/Codium-ai/pr-agent/blob/main/docs/GENERATE_CUSTOM_LABELS.md)
- New ability to use [customize labels](https://github.com/Codium-ai/pr-agent/blob/main/docs/GENERATE_CUSTOM_LABELS.md#how-to-enable-custom-labels) on the `review` and `describe` tools.
- New tool - [add_docs](https://github.com/Codium-ai/pr-agent/blob/main/docs/ADD_DOCUMENTATION.md)
- GitHub Action: Can now use a `.pr_agent.toml` file to control configuration parameters (see [Usage Guide](./Usage.md#working-with-github-action)).
- GitHub App: Added ability to trigger tools on [push events](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#github-app-automatic-tools-for-new-code-pr-push)
- Support custom domain URLs for Azure devops integration (see [link](https://github.com/Codium-ai/pr-agent/pull/381)).
- PR Description default mode is now in [bullet points](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L35).
### Added::Documentation
Significant documentation updates (see [Installation Guide](https://github.com/Codium-ai/pr-agent/blob/main/INSTALL.md), [Usage Guide](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md), and [Tools Guide](https://github.com/Codium-ai/pr-agent/blob/main/docs/TOOLS_GUIDE.md))
### Fixed
- Fixed support for BitBucket pipeline (see [link](https://github.com/Codium-ai/pr-agent/pull/386))
- Fixed a bug in `review -i` tool
- Added blacklist for specific file extensions in `add_docs` tool (see [link](https://github.com/Codium-ai/pr-agent/pull/385/))
## [Version 0.8] - 2023-09-27
- codiumai/pr-agent:0.8
- codiumai/pr-agent:0.8-github_app
- codiumai/pr-agent:0.8-bitbucket-app
- codiumai/pr-agent:0.8-gitlab_webhook
- codiumai/pr-agent:0.8-github_polling
- codiumai/pr-agent:0.8-github_action
### Added::Algo
- GitHub Action: Can control which tools will run automatically when a new PR is created. (see usage guide: https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#working-with-github-action)
- Code suggestion tool: Will try to avoid an 'add comments' suggestion (see https://github.com/Codium-ai/pr-agent/pull/327)
### Fixed
- Gitlab: Fixed a bug of improper usage of pr_id
## [Version 0.7] - 2023-09-20
### Docker Tags
- codiumai/pr-agent:0.7
- codiumai/pr-agent:0.7-github_app
- codiumai/pr-agent:0.7-bitbucket-app
- codiumai/pr-agent:0.7-gitlab_webhook
- codiumai/pr-agent:0.7-github_polling
- codiumai/pr-agent:0.7-github_action
### Added::Algo
- New tool /similar_issue - Currently on GitHub app and CLI: indexes the issues in the repo, find the most similar issues to the target issue.
- Describe markers: Empower the /describe tool with a templating capability (see more details in https://github.com/Codium-ai/pr-agent/pull/273).
- New feature in the /review tool - added an estimated effort estimation to the review (https://github.com/Codium-ai/pr-agent/pull/306).
### Added::Infrastructure
- Implementation of a GitLab webhook.
- Implementation of a BitBucket app.
### Fixed
- Protection against no code suggestions generated.
- Resilience to repositories where the languages cannot be automatically detected.

182
Usage.md
View File

@ -1,182 +0,0 @@
## Usage guide
### Table of Contents
- [Introduction](#introduction)
- [Working from a local repo (CLI)](#working-from-a-local-repo-cli)
- [Online usage](#online-usage)
- [Working with GitHub App](#working-with-github-app)
- [Working with GitHub Action](#working-with-github-action)
- [Appendix - additional configurations walkthrough](#appendix---additional-configurations-walkthrough)
### Introduction
There are 3 basic ways to invoke CodiumAI PR-Agent:
1. Locally running a CLI command
2. Online usage - by [commenting](https://github.com/Codium-ai/pr-agent/pull/229#issuecomment-1695021901) on a PR
3. Enabling PR-Agent tools to run automatically when a new PR is opened
See the [installation guide](/INSTALL.md) for instructions on how to setup your own PR-Agent.
Specifically, CLI commands can be issued by invoking a pre-built [docker image](/INSTALL.md#running-from-source), or by invoking a [locally cloned repo](INSTALL.md#method-2-run-from-source).
For online usage, you will need to setup either a [GitHub App](INSTALL.md#method-5-run-as-a-github-app), or a [GitHub Action](INSTALL.md#method-3-run-as-a-github-action).
GitHub App and GitHub Action also enable to run PR-Agent specific tool automatically when a new PR is opened.
#### The configuration file
The different tools and sub-tools used by CodiumAI PR-Agent are adjustable via the **[configuration file](pr_agent/settings/configuration.toml)**.
In addition to general configuration options, each tool has its own configurations. For example, the `review` tool will use parameters from the [pr_reviewer](/pr_agent/settings/configuration.toml#L16) section in the configuration file.
**git provider:**
The [git_provider](pr_agent/settings/configuration.toml#L4) field in the configuration file determines the GIT provider that will be used by PR-Agent. Currently, the following providers are supported:
`
"github", "gitlab", "azure", "codecommit", "local"
`
[//]: # (** online usage:**)
[//]: # (Options that are available in the configuration file can be specified at run time when calling actions. Two examples:)
[//]: # (```)
[//]: # (- /review --pr_reviewer.extra_instructions="focus on the file: ...")
[//]: # (- /describe --pr_description.add_original_user_description=false -pr_description.extra_instructions="make sure to mention: ...")
[//]: # (```)
### Working from a local repo (CLI)
When running from your local repo (CLI), your local configuration file will be used.
Examples for invoking the different tools via the CLI:
- **Review**: `python cli.py --pr_url=<pr_url> /review`
- **Describe**: `python cli.py --pr_url=<pr_url> /describe`
- **Improve**: `python cli.py --pr_url=<pr_url> /improve`
- **Ask**: `python cli.py --pr_url=<pr_url> /ask "Write me a poem about this PR"`
- **Reflect**: `python cli.py --pr_url=<pr_url> /reflect`
- **Update Changelog**: `python cli.py --pr_url=<pr_url> /update_changelog`
`<pr_url>` is the url of the relevant PR (for example: https://github.com/Codium-ai/pr-agent/pull/50).
**Notes:**
(1) in addition to editing your local configuration file, you can also change any configuration value by adding it to the command line:
```
python cli.py --pr_url=<pr_url> /review --pr_reviewer.extra_instructions="focus on the file: ..."
```
(2) You can print results locally, without publishing them, by setting in `configuration.toml`:
```
[config]
publish_output=true
verbosity_level=2
```
This is useful for debugging or experimenting with the different tools.
### Online usage
Online usage means invoking PR-Agent tools by [comments](https://github.com/Codium-ai/pr-agent/pull/229#issuecomment-1695021901) on a PR.
Commands for invoking the different tools via comments:
- **Review**: `/review`
- **Describe**: `/describe`
- **Improve**: `/improve`
- **Ask**: `/ask "..."`
- **Reflect**: `/reflect`
- **Update Changelog**: `/update_changelog`
To edit a specific configuration value, just add `--config_path=<value>` to any command.
For example if you want to edit the `review` tool configurations, you can run:
```
/review --pr_reviewer.extra_instructions="..." --pr_reviewer.require_score_review=false
```
Any configuration value in [configuration file](pr_agent/settings/configuration.toml) file can be similarly edited.
### Working with GitHub App
When running PR-Agent from [GitHub App](INSTALL.md#method-5-run-as-a-github-app), the default configurations from a pre-built repo will be initially loaded.
#### GitHub app automatic tools
The [github_app](pr_agent/settings/configuration.toml#L56) section defines GitHub app specific configurations.
An important parameter is `pr_commands`, which is a list of tools that will be **run automatically when a new PR is opened**:
```
[github_app]
pr_commands = [
"/describe --pr_description.add_original_user_description=true --pr_description.keep_original_user_title=true",
"/auto_review",
]
```
This means that when a new PR is opened, PR-Agent will run the `describe` and `auto_review` tools.
For the describe tool, the `add_original_user_description` and `keep_original_user_title` parameters will be set to true.
However, you can override the default tool parameters by uploading a local configuration file called `.pr_agent.toml` to the root of your repo.
For example, if your local `.pr_agent.toml` file contains:
```
[pr_description]
add_original_user_description = false
keep_original_user_title = false
```
When a new PR is opened, PR-Agent will run the `describe` tool with the above parameters.
Note that a local `.pr_agent.toml` file enables you to edit and customize the default parameters of any tool, not just the ones that are run automatically.
#### Editing the prompts
The prompts for the various PR-Agent tools are defined in the `pr_agent/settings` folder.
In practice, the prompts are loaded and stored as a standard setting object.
Hence, editing them is similar to editing any other configuration value - just place the relevant key in `.pr_agent.toml`file, and override the default value.
For example, if you want to edit the prompts of the [describe](./pr_agent/settings/pr_description_prompts.toml) tool, you can add the following to your `.pr_agent.toml` file:
```
[pr_description_prompt]
system="""
...
"""
user="""
...
"""
```
Note that the new prompt will need to generate an output compatible with the relevant [post-process function](./pr_agent/tools/pr_description.py#L137).
### Working with GitHub Action
TBD
### Appendix - additional configurations walkthrough
#### Changing a model
See [here](pr_agent/algo/__init__.py) for the list of available models.
To use Llama2 model, for example, set:
```
[config]
model = "replicate/llama-2-70b-chat:2c1608e18606fad2812020dc541930f2d0495ce32eee50074220b87300bc16e1"
[replicate]
key = ...
```
(you can obtain a Llama2 key from [here](https://replicate.com/replicate/llama-2-70b-chat/api))
Also review the [AiHandler](pr_agent/algo/ai_handler.py) file for instruction how to set keys for other models.
#### Extra instructions
All PR-Agent tools have a parameter called `extra_instructions`, that enables to add free-text extra instructions. Example usage:
```
/update_changelog --pr_update_changelog.extra_instructions="Make sure to update also the version ..."
```
#### Azure DevOps provider
To use Azure DevOps provider use the following settings in configuration.toml:
```
[config]
git_provider="azure"
use_repo_settings_file=false
```
And use the following settings (you have to replace the values) in .secrets.toml:
```
[azure_devops]
org = "https://dev.azure.com/YOUR_ORGANIZATION/"
pat = "YOUR_PAT_TOKEN"
```

View File

@ -8,12 +8,16 @@ ENV PYTHONPATH=/app
FROM base as github_app
ADD pr_agent pr_agent
CMD ["python", "pr_agent/servers/github_app.py"]
CMD ["python", "-m", "gunicorn", "-k", "uvicorn.workers.UvicornWorker", "-c", "pr_agent/servers/gunicorn_config.py", "--forwarded-allow-ips", "*", "pr_agent.servers.github_app:app"]
FROM base as bitbucket_app
ADD pr_agent pr_agent
CMD ["python", "pr_agent/servers/bitbucket_app.py"]
FROM base as bitbucket_server_webhook
ADD pr_agent pr_agent
CMD ["python", "pr_agent/servers/bitbucket_server_webhook.py"]
FROM base as github_polling
ADD pr_agent pr_agent
CMD ["python", "pr_agent/servers/github_polling.py"]
@ -22,6 +26,10 @@ FROM base as gitlab_webhook
ADD pr_agent pr_agent
CMD ["python", "pr_agent/servers/gitlab_webhook.py"]
FROM base as azure_devops_webhook
ADD pr_agent pr_agent
CMD ["python", "pr_agent/servers/azuredevops_server_webhook.py"]
FROM base as test
ADD requirements-dev.txt .
RUN pip install -r requirements-dev.txt && rm requirements-dev.txt

View File

@ -1,10 +1,10 @@
FROM public.ecr.aws/lambda/python:3.10
RUN yum update -y && \
yum install -y gcc python3-devel && \
yum install -y gcc python3-devel git && \
yum clean all
ADD pyproject.toml .
ADD pyproject.toml requirements.txt .
RUN pip install . && rm pyproject.toml
RUN pip install mangum==0.17.0
COPY pr_agent/ ${LAMBDA_TASK_ROOT}/pr_agent/

1
docs/README.md Normal file
View File

@ -0,0 +1 @@
# [Visit Our Docs Portal](https://pr-agent-docs.codium.ai/)

1
docs/docs/CNAME Normal file
View File

@ -0,0 +1 @@
pr-agent-docs.codium.ai

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
docs/docs/assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 KiB

140
docs/docs/assets/logo.svg Normal file
View File

@ -0,0 +1,140 @@
<?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>

After

Width:  |  Height:  |  Size: 9.0 KiB

View File

@ -0,0 +1,49 @@
## PR-Agent chrome extension
PR-Agent Chrome extension is a collection of tools that integrates seamlessly with your GitHub environment, aiming to enhance your PR-Agent usage experience, and providing additional features.
## Features
### Toolbar extension
With PR-Agent Chrome extension, it's [easier than ever](https://www.youtube.com/watch?v=gT5tli7X4H4) to interactively configure and experiment with the different tools and configuration options.
After you found the setup that works for you, you can also easily export it as a persistent configuration file, and use it for automatic commands.
<img src="https://codium.ai/images/pr_agent/toolbar1.png" width="512">
<img src="https://codium.ai/images/pr_agent/toolbar2.png" width="512">
### PR-Agent filters
PR-Agent filters is a sidepanel option. that allows you to filter different message in the conversation tab.
For example, you can choose to present only message from PR-Agent, or filter those messages, focusing only on user's comments.
<img src="https://codium.ai/images/pr_agent/pr_agent_filters1.png" width="256">
<img src="https://codium.ai/images/pr_agent/pr_agent_filters2.png" width="256">
### Enhanced code suggestions
PR-Agent Chrome extension adds the following capabilities to code suggestions tool's comments:
- Auto-expand the table when you are viewing a code block, to avoid clipping.
- Adding a "quote-and-reply" button, that enables to address and comment on a specific suggestion (for example, asking the author to fix the issue)
<img src="https://codium.ai/images/pr_agent/chrome_extension_code_suggestion1.png" width="512">
<img src="https://codium.ai/images/pr_agent/chrome_extension_code_suggestion2.png" width="512">
## Installation
Go to the marketplace and install the extension:
[PR-Agent Chrome Extension](https://chromewebstore.google.com/detail/pr-agent-chrome-extension/ephlnjeghhogofkifjloamocljapahnl)
## Pre-requisites
The PR-Agent Chrome extension will work on any repo where you have previously [installed PR-Agent](https://pr-agent-docs.codium.ai/installation/).
## Data privacy and security
The PR-Agent Chrome extension only modifies the visual appearance of a GitHub PR screen. It does not transmit any user's repo or pull request code. Code is only sent for processing when a user submits a GitHub comment that activates a PR-Agent tool, in accordance with the standard privacy policy of PR-Agent.

View File

@ -1,42 +1,52 @@
# Git Patch Logic
## PR Compression Strategy
There are two scenarios:
1. The PR is small enough to fit in a single prompt (including system and user prompt)
2. The PR is too large to fit in a single prompt (including system and user prompt)
For both scenarios, we first use the following strategy
#### Repo language prioritization strategy
#### Repo language prioritization strategy
We prioritize the languages of the repo based on the following criteria:
1. Exclude binary files and non code files (e.g. images, pdfs, etc)
2. Given the main languages used in the repo
2. We sort the PR files by the most common languages in the repo (in descending order):
3. We sort the PR files by the most common languages in the repo (in descending order):
* ```[[file.py, file2.py],[file3.js, file4.jsx],[readme.md]]```
## Small PR
### Small PR
In this case, we can fit the entire PR in a single prompt:
1. Exclude binary files and non code files (e.g. images, pdfs, etc)
2. We Expand the surrounding context of each patch to 6 lines above and below the patch
## Large PR
2. We Expand the surrounding context of each patch to 3 lines above and below the patch
### Motivation
### Large PR
#### Motivation
Pull Requests can be very long and contain a lot of information with varying degree of relevance to the pr-agent.
We want to be able to pack as much information as possible in a single LMM prompt, while keeping the information relevant to the pr-agent.
#### PR compression strategy
#### Compression strategy
We prioritize additions over deletions:
- Combine all deleted files into a single list (`deleted files`)
- File patches are a list of hunks, remove all hunks of type deletion-only from the hunks in the file patch
#### Adaptive and token-aware file patch fitting
We use [tiktoken](https://github.com/openai/tiktoken) to tokenize the patches after the modifications described above, and we use the following strategy to fit the patches into the prompt:
1. Within each language we sort the files by the number of tokens in the file (in descending order):
* ```[[file2.py, file.py],[file4.jsx, file3.js],[readme.md]]```
2. Iterate through the patches in the order described above
2. Add the patches to the prompt until the prompt reaches a certain buffer from the max token length
3. If there are still patches left, add the remaining patches as a list called `other modified files` to the prompt until the prompt reaches the max token length (hard stop), skip the rest of the patches.
4. If we haven't reached the max token length, add the `deleted files` to the prompt until the prompt reaches the max token length (hard stop), skip the rest of the patches.
### Example
![](https://codium.ai/images/git_patch_logic.png)
1. Within each language we sort the files by the number of tokens in the file (in descending order):
- ```[[file2.py, file.py],[file4.jsx, file3.js],[readme.md]]```
2. Iterate through the patches in the order described above
3. Add the patches to the prompt until the prompt reaches a certain buffer from the max token length
4. If there are still patches left, add the remaining patches as a list called `other modified files` to the prompt until the prompt reaches the max token length (hard stop), skip the rest of the patches.
5. If we haven't reached the max token length, add the `deleted files` to the prompt until the prompt reaches the max token length (hard stop), skip the rest of the patches.
#### Example
![Core Abilities](https://codium.ai/images/git_patch_logic.png){width=768}
## YAML Prompting
TBD
## Static Code Analysis 💎
TBD

36
docs/docs/css/custom.css Normal file
View File

@ -0,0 +1,36 @@
:root {
--md-primary-fg-color: #765bfa;
--md-accent-fg-color: #AEA1F1;
}
.md-nav--primary {
.md-nav__link {
font-size: 18px; /* Change the font size as per your preference */
}
}
/*.md-nav__title, .md-nav__link {*/
/* font-size: 18px;*/
/* margin-top: 14px; !* Adjust the space as needed *!*/
/* margin-bottom: 14px; !* Adjust the space as needed *!*/
/*}*/
.md-tabs__link {
font-size: 18px;
}
.md-header__title {
font-size: 20px;
margin-left: 0px !important;
}
.md-content img {
border-width: 1px;
border-style: solid;
border-color: black;
outline-width: 1px;
outline-style: solid;
outline-color: darkgray;
}

View File

@ -0,0 +1,92 @@
# PR-Agent Code Fine-tuning Benchmark
On coding tasks, the gap between open-source models and top closed-source models such as GPT4 is significant.
<br>
In practice, open-source models are unsuitable for most real-world code tasks, and require further fine-tuning to produce acceptable results.
_PR-Agent fine-tuning benchmark_ aims to benchmark open-source models on their ability to be fine-tuned for a coding task.
Specifically, we chose to fine-tune open-source models on the task of analyzing a pull request, and providing useful feedback and code suggestions.
Here are the results:
<br>
<br>
**Model performance:**
| Model name | Model size [B] | Better than gpt-4 rate, after fine-tuning [%] |
|-----------------------------|----------------|----------------------------------------------|
| **DeepSeek 34B-instruct** | **34** | **40.7** |
| DeepSeek 34B-base | 34 | 38.2 |
| Phind-34b | 34 | 38 |
| Granite-34B | 34 | 37.6 |
| Codestral-22B-v0.1 | 22 | 32.7 |
| QWEN-1.5-32B | 32 | 29 |
| | | |
| **CodeQwen1.5-7B** | **7** | **35.4** |
| Granite-8b-code-instruct | 8 | 34.2 |
| CodeLlama-7b-hf | 7 | 31.8 |
| Gemma-7B | 7 | 27.2 |
| DeepSeek coder-7b-instruct | 7 | 26.8 |
| Llama-3-8B-Instruct | 8 | 26.8 |
| Mistral-7B-v0.1 | 7 | 16.1 |
<br>
**Fine-tuning impact:**
| Model name | Model size [B] | Fine-tuned | Better than gpt-4 rate [%] |
|---------------------------|----------------|------------|----------------------------|
| DeepSeek 34B-instruct | 34 | yes | 40.7 |
| DeepSeek 34B-instruct | 34 | no | 3.6 |
## Results analysis
- **Fine-tuning is a must** - without fine-tuning, open-source models provide poor results on most real-world code tasks, which include complicated prompt and lengthy context. We clearly see that without fine-tuning, deepseek model was 96.4% of the time inferior to GPT-4, while after fine-tuning, it is better 40.7% of the time.
- **Always start from a code-dedicated model** — When fine-tuning, always start from a code-dedicated model, and not from a general-usage model. The gaps in downstream results are very big.
- **Don't believe the hype** —newer models, or models from big-tech companies (Llama3, Gemma, Mistral), are not always better for fine-tuning.
- **The best large model** - For large 34B code-dedicated models, the gaps when doing proper fine-tuning are small. The current top model is **DeepSeek 34B-instruct**
- **The best small model** - For small 7B code-dedicated models, the gaps when fine-tuning are much larger. **CodeQWEN 1.5-7B** is by far the best model for fine-tuning.
- **Base vs. instruct** - For the top model (deepseek), we saw small advantage when starting from the instruct version. However, we recommend testing both versions on each specific task, as the base model is generally considered more suitable for fine-tuning.
## The dataset
### Training dataset
Our training dataset comprises 25,000 pull requests, aggregated from permissive license repos. For each pull request, we generated responses for the three main tools of PR-Agent:
[Describe](https://pr-agent-docs.codium.ai/tools/describe/), [Review](https://pr-agent-docs.codium.ai/tools/improve/) and [Improve](https://pr-agent-docs.codium.ai/tools/improve/).
On the raw data collected, we employed various automatic and manual cleaning techniques to ensure the outputs were of the highest quality, and suitable for instruct-tuning.
Here are the prompts, and example outputs, used as input-output pairs to fine-tune the models:
| Tool | Prompt | Example output |
|----------|------------------------------------------------------------------------------------------------------------|----------------|
| Describe | [link](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/pr_description_prompts.toml) | [link](https://github.com/Codium-ai/pr-agent/pull/910#issue-2303989601) |
| Review | [link](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/pr_reviewer_prompts.toml) | [link](https://github.com/Codium-ai/pr-agent/pull/910#issuecomment-2118761219) |
| Improve | [link](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/pr_code_suggestions_prompts.toml) | [link](https://github.com/Codium-ai/pr-agent/pull/910#issuecomment-2118761309) |
### Evaluation dataset
- For each tool, we aggregated 100 additional examples to be used for evaluation. These examples were not used in the training dataset, and were manually selected to represent diverse real-world use-cases.
- For each test example, we generated two responses: one from the fine-tuned model, and one from the best code model in the world, `gpt-4-turbo-2024-04-09`.
- We used a third LLM to judge which response better answers the prompt, and will likely be perceived by a human as better response.
<br>
We experimented with three model as judges: `gpt-4-turbo-2024-04-09`, `gpt-4o`, and `claude-3-opus-20240229`. All three produced similar results, with the same ranking order. This strengthens the validity of our testing protocol.
The evaluation prompt can be found [here](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/pr_evaluate_prompt_response.toml)
Here is an example of a judge model feedback:
```
command: improve
model1_score: 9,
model2_score: 6,
why: |
Response 1 is better because it provides more actionable and specific suggestions that directly
enhance the code's maintainability, performance, and best practices. For example, it suggests
using a variable for reusable widget instances and using named routes for navigation, which
are practical improvements. In contrast, Response 2 focuses more on general advice and less
actionable suggestions, such as changing variable names and adding comments, which are less
critical for immediate code improvement."
```

81
docs/docs/index.md Normal file
View File

@ -0,0 +1,81 @@
# Overview
CodiumAI PR-Agent is an open-source tool to help efficiently review and handle pull requests.
- See the [Installation Guide](./installation/index.md) for instructions on installing and running the tool on different git platforms.
- See the [Usage Guide](./usage-guide/index.md) for instructions on running the PR-Agent commands via different interfaces, including _CLI_, _online usage_, or by _automatically triggering_ them when a new PR is opened.
- See the [Tools Guide](./tools/index.md) for a detailed description of the different tools.
## PR-Agent Features
PR-Agent offers extensive pull request functionalities across various git providers.
| | | GitHub | Gitlab | Bitbucket | Azure DevOps |
|-------|-----------------------------------------------------------------------------------------------------------------------|:------:|:------:|:---------:|:------------:|
| TOOLS | Review | ✅ | ✅ | ✅ | ✅ |
| | ⮑ Incremental | ✅ | | | |
| | ⮑ [SOC2 Compliance](https://pr-agent-docs.codium.ai/tools/review/#soc2-ticket-compliance){:target="_blank"} 💎 | ✅ | ✅ | ✅ | ✅ |
| | Ask | ✅ | ✅ | ✅ | ✅ |
| | Describe | ✅ | ✅ | ✅ | ✅ |
| | ⮑ [Inline file summary](https://pr-agent-docs.codium.ai/tools/describe/#inline-file-summary){:target="_blank"} 💎 | ✅ | ✅ | | ✅ |
| | Improve | ✅ | ✅ | ✅ | ✅ |
| | ⮑ Extended | ✅ | ✅ | ✅ | ✅ |
| | [Custom Prompt](./tools/custom_prompt.md){:target="_blank"} 💎 | ✅ | ✅ | ✅ | ✅ |
| | Reflect and Review | ✅ | ✅ | ✅ | ✅ |
| | Update CHANGELOG.md | ✅ | ✅ | ✅ | |
| | Find Similar Issue | ✅ | | | |
| | [Add PR Documentation](./tools/documentation.md){:target="_blank"} 💎 | ✅ | ✅ | | ✅ |
| | [Generate Custom Labels](./tools/describe.md#handle-custom-labels-from-the-repos-labels-page-💎){:target="_blank"} 💎 | ✅ | ✅ | | ✅ |
| | [Analyze PR Components](./tools/analyze.md){:target="_blank"} 💎 | ✅ | ✅ | | ✅ |
| | | | | | |
| USAGE | CLI | ✅ | ✅ | ✅ | ✅ |
| | App / webhook | ✅ | ✅ | ✅ | ✅ |
| | Actions | ✅ | | | |
| | | | | |
| CORE | PR compression | ✅ | ✅ | ✅ | ✅ |
| | Repo language prioritization | ✅ | ✅ | ✅ | ✅ |
| | Adaptive and token-aware file patch fitting | ✅ | ✅ | ✅ | ✅ |
| | Multiple models support | ✅ | ✅ | ✅ | ✅ |
| | Incremental PR review | ✅ | | | |
| | [Static code analysis](./tools/analyze.md/){:target="_blank"} 💎 | ✅ | ✅ | ✅ | ✅ |
| | [Multiple configuration options](./usage-guide/configuration_options.md){:target="_blank"} 💎 | ✅ | ✅ | ✅ | ✅ |
💎 marks a feature available only in [PR-Agent Pro](https://www.codium.ai/pricing/){:target="_blank"}
## Example Results
<hr>
#### [/describe](https://github.com/Codium-ai/pr-agent/pull/530)
<figure markdown="1">
![/describe](https://www.codium.ai/images/pr_agent/describe_new_short_main.png){width=512}
</figure>
<hr>
#### [/review](https://github.com/Codium-ai/pr-agent/pull/732#issuecomment-1975099151)
<figure markdown="1">
![/review](https://www.codium.ai/images/pr_agent/review_new_short_main.png){width=512}
</figure>
<hr>
#### [/improve](https://github.com/Codium-ai/pr-agent/pull/732#issuecomment-1975099159)
<figure markdown="1">
![/improve](https://www.codium.ai/images/pr_agent/improve_new_short_main.png){width=512}
</figure>
<hr>
#### [/generate_labels](https://github.com/Codium-ai/pr-agent/pull/530)
<figure markdown="1">
![/generate_labels](https://www.codium.ai/images/pr_agent/geneare_custom_labels_main_short.png){width=300}
</figure>
<hr>
## How it Works
The following diagram illustrates PR-Agent tools and their flow:
![PR-Agent Tools](https://codium.ai/images/pr_agent/diagram-v0.9.png)
Check out the [PR Compression strategy](core-abilities/index.md) page for more details on how we convert a code diff to a manageable LLM prompt

View File

@ -0,0 +1,35 @@
## Azure DevOps provider
To use Azure DevOps provider use the following settings in configuration.toml:
```
[config]
git_provider="azure"
```
Azure DevOps provider supports [PAT token](https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=Windows) or [DefaultAzureCredential](https://learn.microsoft.com/en-us/azure/developer/python/sdk/authentication-overview#authentication-in-server-environments) authentication.
PAT is faster to create, but has build in expiration date, and will use the user identity for API calls.
Using DefaultAzureCredential you can use managed identity or Service principle, which are more secure and will create separate ADO user identity (via AAD) to the agent.
If PAT was chosen, you can assign the value in .secrets.toml.
If DefaultAzureCredential was chosen, you can assigned the additional env vars like AZURE_CLIENT_SECRET directly,
or use managed identity/az cli (for local development) without any additional configuration.
in any case, 'org' value must be assigned in .secrets.toml:
```
[azure_devops]
org = "https://dev.azure.com/YOUR_ORGANIZATION/"
# pat = "YOUR_PAT_TOKEN" needed only if using PAT for authentication
```
### Azure DevOps Webhook
To trigger from an Azure webhook, you need to manually [add a webhook](https://learn.microsoft.com/en-us/azure/devops/service-hooks/services/webhooks?view=azure-devops).
Use the "Pull request created" type to trigger a review, or "Pull request commented on" to trigger any supported comment with /<command> <args> comment on the relevant PR. Note that for the "Pull request commented on" trigger, only API v2.0 is supported.
For webhook security, create a sporadic username/password pair and configure the webhook username and password on both the server and Azure DevOps webhook. These will be sent as basic Auth data by the webhook with each request:
```
[azure_devops_server]
webhook_username = "<basic auth user>"
webhook_password = "<basic auth password>"
```
> :warning: **Ensure that the webhook endpoint is only accessible over HTTPS** to mitigate the risk of credential interception when using basic authentication.

View File

@ -0,0 +1,70 @@
## Run as a Bitbucket Pipeline
You can use the Bitbucket Pipeline system to run PR-Agent on every pull request open or update.
1. Add the following file in your repository bitbucket_pipelines.yml
```yaml
pipelines:
pull-requests:
'**':
- step:
name: PR Agent Review
image: python:3.10
services:
- docker
script:
- docker run -e CONFIG.GIT_PROVIDER=bitbucket -e OPENAI.KEY=$OPENAI_API_KEY -e BITBUCKET.BEARER_TOKEN=$BITBUCKET_BEARER_TOKEN codiumai/pr-agent:latest --pr_url=https://bitbucket.org/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG/pull-requests/$BITBUCKET_PR_ID review
```
2. Add the following secure variables to your repository under Repository settings > Pipelines > Repository variables.
OPENAI_API_KEY: `<your key>`
BITBUCKET_BEARER_TOKEN: `<your token>`
You can get a Bitbucket token for your repository by following Repository Settings -> Security -> Access Tokens.
Note that comments on a PR are not supported in Bitbucket Pipeline.
## Run using CodiumAI-hosted Bitbucket app
Please contact [support@codium.ai](mailto:support@codium.ai) or visit [CodiumAI pricing page](https://www.codium.ai/pricing/) if you're interested in a hosted BitBucket app solution that provides full functionality including PR reviews and comment handling. It's based on the [bitbucket_app.py](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/git_providers/bitbucket_provider.py) implementation.
## Bitbucket Server and Data Center
Login into your on-prem instance of Bitbucket with your service account username and password.
Navigate to `Manage account`, `HTTP Access tokens`, `Create Token`.
Generate the token and add it to .secret.toml under `bitbucket_server` section
```toml
[bitbucket_server]
bearer_token = "<your key>"
```
### Run it as CLI
Modify `configuration.toml`:
```toml
git_provider="bitbucket_server"
```
and pass the Pull request URL:
```shell
python cli.py --pr_url https://git.onpreminstanceofbitbucket.com/projects/PROJECT/repos/REPO/pull-requests/1 review
```
### Run it as service
To run pr-agent as webhook, build the docker image:
```
docker build . -t codiumai/pr-agent:bitbucket_server_webhook --target bitbucket_server_webhook -f docker/Dockerfile
docker push codiumai/pr-agent:bitbucket_server_webhook # Push to your Docker repository
```
Navigate to `Projects` or `Repositories`, `Settings`, `Webhooks`, `Create Webhook`.
Fill the name and URL, Authentication None select the Pull Request Opened checkbox to receive that event as webhook.
The URL should end with `/webhook`, for example: https://domain.com/webhook

View File

@ -0,0 +1,242 @@
## Run as a GitHub Action
You can use our pre-built Github Action Docker image to run PR-Agent as a Github Action.
1) Add the following file to your repository under `.github/workflows/pr_agent.yml`:
```yaml
on:
pull_request:
types: [opened, reopened, ready_for_review]
issue_comment:
jobs:
pr_agent_job:
if: ${{ github.event.sender.type != 'Bot' }}
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
contents: write
name: Run pr agent on every pull request, respond to user comments
steps:
- name: PR Agent action step
id: pragent
uses: Codium-ai/pr-agent@main
env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
** if you want to pin your action to a specific release (v2.0 for example) for stability reasons, use:
```yaml
...
steps:
- name: PR Agent action step
id: pragent
uses: Codium-ai/pr-agent@v2.0
...
```
2) Add the following secret to your repository under `Settings > Secrets and variables > Actions > New repository secret > Add secret`:
```
Name = OPENAI_KEY
Secret = <your key>
```
The GITHUB_TOKEN secret is automatically created by GitHub.
3) Merge this change to your main branch.
When you open your next PR, you should see a comment from `github-actions` bot with a review of your PR, and instructions on how to use the rest of the tools.
4) You may configure PR-Agent by adding environment variables under the env section corresponding to any configurable property in the [configuration](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml) file. Some examples:
```yaml
env:
# ... previous environment values
OPENAI.ORG: "<Your organization name under your OpenAI account>"
PR_REVIEWER.REQUIRE_TESTS_REVIEW: "false" # Disable tests review
PR_CODE_SUGGESTIONS.NUM_CODE_SUGGESTIONS: 6 # Increase number of code suggestions
```
See detailed usage instructions in the [USAGE GUIDE](https://pr-agent-docs.codium.ai/usage-guide/automations_and_usage/#github-action)
---
## Run as a GitHub App
Allowing you to automate the review process on your private or public repositories.
1) Create a GitHub App from the [Github Developer Portal](https://docs.github.com/en/developers/apps/creating-a-github-app).
- Set the following permissions:
- Pull requests: Read & write
- Issue comment: Read & write
- Metadata: Read-only
- Contents: Read-only
- Set the following events:
- Issue comment
- Pull request
- Push (if you need to enable triggering on PR update)
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))")
```
3) Acquire the following pieces of information from your app's settings page:
- App private key (click "Generate a private key" and save the file)
- App ID
4) Clone this repository:
```
git clone https://github.com/Codium-ai/pr-agent.git
```
5) Copy the secrets template file and fill in the following:
```
cp pr_agent/settings/.secrets_template.toml pr_agent/settings/.secrets.toml
# Edit .secrets.toml file
```
- Your OpenAI key.
- Copy your app's private key to the private_key field.
- Copy your app's ID to the app_id field.
- Copy your app's webhook secret to the webhook_secret field.
- Set deployment_type to 'app' in [configuration.toml](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml)
> The .secrets.toml file is not copied to the Docker image by default, and is only used for local development.
> If you want to use the .secrets.toml file in your Docker image, you can add remove it from the .dockerignore file.
> In most production environments, you would inject the secrets file as environment variables or as mounted volumes.
> For example, in order to inject a secrets file as a volume in a Kubernetes environment you can update your pod spec to include the following,
> assuming you have a secret named `pr-agent-settings` with a key named `.secrets.toml`:
```
volumes:
- name: settings-volume
secret:
secretName: pr-agent-settings
// ...
containers:
// ...
volumeMounts:
- mountPath: /app/pr_agent/settings_prod
name: settings-volume
```
> Another option is to set the secrets as environment variables in your deployment environment, for example `OPENAI.KEY` and `GITHUB.USER_TOKEN`.
6) 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 codiumai/pr-agent:github_app --target github_app -f docker/Dockerfile
docker push codiumai/pr-agent:github_app # Push to your Docker repository
```
7. Host the app using a server, serverless function, or container environment. Alternatively, for development and
debugging, you may use tools like smee.io to forward webhooks to your local machine.
You can check [Deploy as a Lambda Function](#deploy-as-a-lambda-function)
8. Go back to your app's settings, and set the following:
- Webhook URL: The URL of your app's server or the URL of the smee.io channel.
- Webhook secret: The secret you generated earlier.
9. Install the app by navigating to the "Install App" tab and selecting your desired repositories.
> **Note:** When running PR-Agent from GitHub App, the default configuration file (configuration.toml) will be loaded.
> However, you can override the default tool parameters by uploading a local configuration file `.pr_agent.toml`
> For more information please check out the [USAGE GUIDE](../usage-guide/automations_and_usage.md#github-app)
---
## Deploy as a Lambda Function
Note that since AWS Lambda env vars cannot have "." in the name, you can replace each "." in an env variable with "__".<br>
For example: `GITHUB.WEBHOOK_SECRET` --> `GITHUB__WEBHOOK_SECRET`
1. Follow steps 1-5 from [here](#run-as-a-github-app).
2. Build a docker image that can be used as a lambda function
```shell
docker buildx build --platform=linux/amd64 . -t codiumai/pr-agent:serverless -f docker/Dockerfile.lambda
```
3. Push image to ECR
```shell
docker tag codiumai/pr-agent:serverless <AWS_ACCOUNT>.dkr.ecr.<AWS_REGION>.amazonaws.com/codiumai/pr-agent:serverless
docker push <AWS_ACCOUNT>.dkr.ecr.<AWS_REGION>.amazonaws.com/codiumai/pr-agent:serverless
```
4. Create a lambda function that uses the uploaded image. Set the lambda timeout to be at least 3m.
5. Configure the lambda function to have a Function URL.
6. In the environment variables of the Lambda function, specify `AZURE_DEVOPS_CACHE_DIR` to a writable location such as /tmp. (see [link](https://github.com/Codium-ai/pr-agent/pull/450#issuecomment-1840242269))
7. Go back to steps 8-9 of [Method 5](#run-as-a-github-app) with the function url as your Webhook URL.
The Webhook URL would look like `https://<LAMBDA_FUNCTION_URL>/api/v1/github_webhooks`
---
## AWS CodeCommit Setup
Not all features have been added to CodeCommit yet. As of right now, CodeCommit has been implemented to run the pr-agent CLI on the command line, using AWS credentials stored in environment variables. (More features will be added in the future.) The following is a set of instructions to have pr-agent do a review of your CodeCommit pull request from the command line:
1. Create an IAM user that you will use to read CodeCommit pull requests and post comments
* Note: That user should have CLI access only, not Console access
2. Add IAM permissions to that user, to allow access to CodeCommit (see IAM Role example below)
3. Generate an Access Key for your IAM user
4. Set the Access Key and Secret using environment variables (see Access Key example below)
5. Set the `git_provider` value to `codecommit` in the `pr_agent/settings/configuration.toml` settings file
6. Set the `PYTHONPATH` to include your `pr-agent` project directory
* Option A: Add `PYTHONPATH="/PATH/TO/PROJECTS/pr-agent` to your `.env` file
* Option B: Set `PYTHONPATH` and run the CLI in one command, for example:
* `PYTHONPATH="/PATH/TO/PROJECTS/pr-agent python pr_agent/cli.py [--ARGS]`
---
#### AWS CodeCommit IAM Role Example
Example IAM permissions to that user to allow access to CodeCommit:
* Note: The following is a working example of IAM permissions that has read access to the repositories and write access to allow posting comments
* Note: If you only want pr-agent to review your pull requests, you can tighten the IAM permissions further, however this IAM example will work, and allow the pr-agent to post comments to the PR
* Note: You may want to replace the `"Resource": "*"` with your list of repos, to limit access to only those repos
```
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"codecommit:BatchDescribe*",
"codecommit:BatchGet*",
"codecommit:Describe*",
"codecommit:EvaluatePullRequestApprovalRules",
"codecommit:Get*",
"codecommit:List*",
"codecommit:PostComment*",
"codecommit:PutCommentReaction",
"codecommit:UpdatePullRequestDescription",
"codecommit:UpdatePullRequestTitle"
],
"Resource": "*"
}
]
}
```
#### AWS CodeCommit Access Key and Secret
Example setting the Access Key and Secret using environment variables
```sh
export AWS_ACCESS_KEY_ID="XXXXXXXXXXXXXXXX"
export AWS_SECRET_ACCESS_KEY="XXXXXXXXXXXXXXXX"
export AWS_DEFAULT_REGION="us-east-1"
```
#### AWS CodeCommit CLI Example
After you set up AWS CodeCommit using the instructions above, here is an example CLI run that tells pr-agent to **review** a given pull request.
(Replace your specific PYTHONPATH and PR URL in the example)
```sh
PYTHONPATH="/PATH/TO/PROJECTS/pr-agent" python pr_agent/cli.py \
--pr_url https://us-east-1.console.aws.amazon.com/codesuite/codecommit/repositories/MY_REPO_NAME/pull-requests/321 \
review
```

View File

@ -0,0 +1,20 @@
## Run a GitLab webhook server
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:
```
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://pr-agent-docs.codium.ai/installation/github/#run-as-a-github-app) steps 4-7.
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 the URL of your app's server. Set the secret token to the generated secret from step 2.
In the "Trigger" section, check the comments and merge request events boxes.
6. Test your installation by opening a merge request or commenting or a merge request using one of CodiumAI's commands.

View File

@ -0,0 +1,22 @@
# Installation
## Self-hosted PR-Agent
If you choose to host you own PR-Agent, 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 models](../usage-guide/additional_configurations.md/#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)]
There are several ways to use self-hosted PR-Agent:
- [Locally](./locally.md)
- [GitHub](./github.md)
- [GitLab](./gitlab.md)
- [BitBucket](./bitbucket.md)
- [Azure DevOps](./azure.md)
## PR-Agent Pro 💎
PR-Agent Pro, an app for GitHub\GitLab\BitBucket hosted by CodiumAI, is also available.
<br>
With PR-Agent Pro Installation is as simple as signing up and adding the PR-Agent app to your relevant repo.
<br>
See [here](./pr_agent_pro.md) for more details.

View File

@ -0,0 +1,121 @@
## Using pip package
Install the package:
```
pip install pr-agent
```
Then run the relevant tool with the script below.
<br>
Make sure to fill in the required parameters (`user_token`, `openai_key`, `pr_url`, `command`):
```python
from pr_agent import cli
from pr_agent.config_loader import get_settings
def main():
# Fill in the following values
provider = "github" # GitHub provider
user_token = "..." # GitHub user token
openai_key = "..." # OpenAI key
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?"', ...)
# Setting the configurations
get_settings().set("CONFIG.git_provider", provider)
get_settings().set("openai.key", openai_key)
get_settings().set("github.user_token", user_token)
# Run the command. Feedback will appear in GitHub PR comments
cli.run_command(pr_url, command)
if __name__ == '__main__':
main()
```
## Using Docker image
A list of the relevant tools can be found in the [tools guide](../tools/ask.md).
To invoke a tool (for example `review`), you can run directly from the Docker image. Here's how:
- For GitHub:
```
docker run --rm -it -e OPENAI.KEY=<your key> -e GITHUB.USER_TOKEN=<your token> codiumai/pr-agent:latest --pr_url <pr_url> review
```
- 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
```
Note: If you have a dedicated GitLab instance, you need to specify the custom url as variable:
```
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:
```
docker run --rm -it -e CONFIG.GIT_PROVIDER=bitbucket -e OPENAI.KEY=$OPENAI_API_KEY -e BITBUCKET.BEARER_TOKEN=$BITBUCKET_BEARER_TOKEN codiumai/pr-agent:latest --pr_url=<pr_url> review
```
For other git providers, update CONFIG.GIT_PROVIDER accordingly, and check the `pr_agent/settings/.secrets_template.toml` file for the environment variables expected names and values.
---
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
1. Clone this repository:
```
git clone https://github.com/Codium-ai/pr-agent.git
```
2. Navigate to the `/pr-agent` folder and install the requirements in your favorite virtual environment:
```
pip install -e .
```
*Note: If you get an error related to Rust in the dependency installation then make sure Rust is installed and in your `PATH`, instructions: https://rustup.rs*
3. Copy the secrets template file and fill in your OpenAI key and your GitHub user token:
```
cp pr_agent/settings/.secrets_template.toml pr_agent/settings/.secrets.toml
chmod 600 pr_agent/settings/.secrets.toml
# Edit .secrets.toml file
```
4. Run the cli.py script:
```
python3 -m pr_agent.cli --pr_url <pr_url> review
python3 -m pr_agent.cli --pr_url <pr_url> ask <your question>
python3 -m pr_agent.cli --pr_url <pr_url> describe
python3 -m pr_agent.cli --pr_url <pr_url> improve
python3 -m pr_agent.cli --pr_url <pr_url> add_docs
python3 -m pr_agent.cli --pr_url <pr_url> generate_labels
python3 -m pr_agent.cli --issue_url <issue_url> similar_issue
...
```
[Optional] Add the pr_agent folder to your PYTHONPATH
```
export PYTHONPATH=$PYTHONPATH:<PATH to pr_agent folder>
```

View File

@ -0,0 +1,64 @@
## Getting Started with PR-Agent Pro
PR-Agent Pro is a versatile application compatible with GitHub, GitLab, and BitBucket, hosted by CodiumAI.
See [here](https://pr-agent-docs.codium.ai/#pr-agent-pro) for more details about the benefits of using PR-Agent Pro.
Interested parties can subscribe to PR-Agent Pro through the following [link](https://www.codium.ai/pricing/).
After subscribing, you are granted the ability to easily install the application across any of your repositories.
![PR Agent Pro](https://codium.ai/images/pr_agent/pr_agent_pro_install.png){width=468}
Each user who wants to use PR-Agent pro needs to buy a seat.
Initially, CodiumAI offers a two-week trial period at no cost, after which continued access requires each user to secure a personal seat.
Once a user acquires a seat, they gain the flexibility to use PR-Agent Pro across any repository where it was enabled.
Users without a purchased seat who interact with a repository featuring PR-Agent Pro are entitled to receive up to five complimentary feedbacks.
Beyond this limit, PR-Agent Pro will cease to respond to their inquiries unless a seat is purchased.
## Install PR-Agent Pro for GitLab (Teams & Enterprise)
Since GitLab platform does not support apps, installing PR-Agent Pro for GitLab is a bit more involved, and requires the following steps:
### Step 1
Acquire a personal, project or group level access token. Enable the “api” scope in order to allow PR-Agent to read pull requests, comment and respond to requests.
<figure markdown="1">
![Step 1](https://www.codium.ai/images/pr_agent/gitlab_pro_pat.png){width=750}
</figure>
Store the token in a safe place, you wont be able to access it again after it was generated.
### Step 2
Generate a shared secret and link it to the access token. Browse to [https://register.gitlab.pr-agent.codium.ai](https://register.gitlab.pr-agent.codium.ai).
Fill in your generated GitLab token and your company or personal name in the appropriate fields and click "Submit".
You should see "Success!" displayed above the Submit button, and a shared secret will be generated. Store it in a safe place, you wont be able to access it again after it was generated.
### Step 3
Install a webhook for your repository or groups, by clicking “webhooks” on the settings menu. Click the “Add new webhook” button.
<figure markdown="1">
![Step 3.1](https://www.codium.ai/images/pr_agent/gitlab_pro_add_webhook.png)
</figure>
In the webhook definition form, fill in the following fields:
URL: https://pro.gitlab.pr-agent.codium.ai/webhook
Secret token: Your CodiumAI key
Trigger: Check the comments and merge request events boxes.
Enable SSL verification: Check the box.
<figure markdown="1">
![Step 3.2](https://www.codium.ai/images/pr_agent/gitlab_pro_webhooks.png){width=750}
</figure>
### Step 4
Youre all set!
Open a new merge request or add a MR comment with one of PR-Agents commands such as /review, /describe or /improve.

View File

@ -0,0 +1,17 @@
## Self-hosted PR-Agent
- If you host PR-Agent with your OpenAI API key, it is between you and OpenAI. You can read their API data privacy policy here:
https://openai.com/enterprise-privacy
## PR-Agent Pro 💎
- When using PR-Agent Pro 💎, hosted by CodiumAI, we will not store any of your data, nor will we use it for training. You will also benefit from an OpenAI account with zero data retention.
- For certain clients, CodiumAI-hosted PR-Agent Pro will use CodiumAIs proprietary models. If this is the case, you will be notified.
- No passive collection of Code and Pull Requests data — PR-Agent will be active only when you invoke it, and it will then extract and analyze only data relevant to the executed command and queried pull request.
## PR-Agent Chrome extension
- The [PR-Agent Chrome extension](https://chromewebstore.google.com/detail/pr-agent-chrome-extension/ephlnjeghhogofkifjloamocljapahnl) serves solely to modify the visual appearance of a GitHub PR screen. It does not transmit any user's repo or pull request code. Code is only sent for processing when a user submits a GitHub comment that activates a PR-Agent tool, in accordance with the standard privacy policy of PR-Agent.

View File

@ -0,0 +1,81 @@
# Overview
CodiumAI PR-Agent is an open-source tool to help efficiently review and handle pull requests.
- See the [Installation Guide](./installation/index.md) for instructions on installing and running the tool on different git platforms.
- See the [Usage Guide](./usage-guide/index.md) for instructions on running the PR-Agent commands via different interfaces, including _CLI_, _online usage_, or by _automatically triggering_ them when a new PR is opened.
- See the [Tools Guide](./tools/index.md) for a detailed description of the different tools.
## PR-Agent Features
PR-Agent offers extensive pull request functionalities across various git providers.
| | | GitHub | Gitlab | Bitbucket | Azure DevOps |
|-------|-----------------------------------------------------------------------------------------------------------------------|:------:|:------:|:---------:|:------------:|
| TOOLS | Review | ✅ | ✅ | ✅ | ✅ |
| | ⮑ Incremental | ✅ | | | |
| | ⮑ [SOC2 Compliance](https://pr-agent-docs.codium.ai/tools/review/#soc2-ticket-compliance){:target="_blank"} 💎 | ✅ | ✅ | ✅ | ✅ |
| | Ask | ✅ | ✅ | ✅ | ✅ |
| | Describe | ✅ | ✅ | ✅ | ✅ |
| | ⮑ [Inline file summary](https://pr-agent-docs.codium.ai/tools/describe/#inline-file-summary){:target="_blank"} 💎 | ✅ | ✅ | | ✅ |
| | Improve | ✅ | ✅ | ✅ | ✅ |
| | ⮑ Extended | ✅ | ✅ | ✅ | ✅ |
| | [Custom Prompt](./tools/custom_prompt.md){:target="_blank"} 💎 | ✅ | ✅ | ✅ | ✅ |
| | Reflect and Review | ✅ | ✅ | ✅ | ✅ |
| | Update CHANGELOG.md | ✅ | ✅ | ✅ | |
| | Find Similar Issue | ✅ | | | |
| | [Add PR Documentation](./tools/documentation.md){:target="_blank"} 💎 | ✅ | ✅ | | ✅ |
| | [Generate Custom Labels](./tools/describe.md#handle-custom-labels-from-the-repos-labels-page-💎){:target="_blank"} 💎 | ✅ | ✅ | | ✅ |
| | [Analyze PR Components](./tools/analyze.md){:target="_blank"} 💎 | ✅ | ✅ | | ✅ |
| | | | | | |
| USAGE | CLI | ✅ | ✅ | ✅ | ✅ |
| | App / webhook | ✅ | ✅ | ✅ | ✅ |
| | Actions | ✅ | | | |
| | | | | |
| CORE | PR compression | ✅ | ✅ | ✅ | ✅ |
| | Repo language prioritization | ✅ | ✅ | ✅ | ✅ |
| | Adaptive and token-aware file patch fitting | ✅ | ✅ | ✅ | ✅ |
| | Multiple models support | ✅ | ✅ | ✅ | ✅ |
| | Incremental PR review | ✅ | | | |
| | [Static code analysis](./tools/analyze.md/){:target="_blank"} 💎 | ✅ | ✅ | ✅ | ✅ |
| | [Multiple configuration options](./usage-guide/configuration_options.md){:target="_blank"} 💎 | ✅ | ✅ | ✅ | ✅ |
💎 marks a feature available only in [PR-Agent Pro](https://www.codium.ai/pricing/){:target="_blank"}
## Example Results
<hr>
#### [/describe](https://github.com/Codium-ai/pr-agent/pull/530)
<figure markdown="1">
![/describe](https://www.codium.ai/images/pr_agent/describe_new_short_main.png){width=512}
</figure>
<hr>
#### [/review](https://github.com/Codium-ai/pr-agent/pull/732#issuecomment-1975099151)
<figure markdown="1">
![/review](https://www.codium.ai/images/pr_agent/review_new_short_main.png){width=512}
</figure>
<hr>
#### [/improve](https://github.com/Codium-ai/pr-agent/pull/732#issuecomment-1975099159)
<figure markdown="1">
![/improve](https://www.codium.ai/images/pr_agent/improve_new_short_main.png){width=512}
</figure>
<hr>
#### [/generate_labels](https://github.com/Codium-ai/pr-agent/pull/530)
<figure markdown="1">
![/generate_labels](https://www.codium.ai/images/pr_agent/geneare_custom_labels_main_short.png){width=300}
</figure>
<hr>
## How it Works
The following diagram illustrates PR-Agent tools and their flow:
![PR-Agent Tools](https://codium.ai/images/pr_agent/diagram-v0.9.png)
Check out the [PR Compression strategy](core-abilities/index.md) page for more details on how we convert a code diff to a manageable LLM prompt

View File

@ -0,0 +1,18 @@
[PR-Agent Pro](https://www.codium.ai/pricing/) is a hosted version of PR-Agent, provided by CodiumAI. It is available for a monthly fee, and provides the following benefits:
1. **Fully managed** - We take care of everything for you - hosting, models, regular updates, and more. Installation is as simple as signing up and adding the PR-Agent app to your GitHub\GitLab\BitBucket repo.
2. **Improved privacy** - No data will be stored or used to train models. PR-Agent Pro will employ zero data retention, and will use an OpenAI account with zero data retention.
3. **Improved support** - PR-Agent Pro users will receive priority support, and will be able to request new features and capabilities.
4. **Extra features** -In addition to the benefits listed above, PR-Agent Pro will emphasize more customization, and the usage of static code analysis, in addition to LLM logic, to improve results. It has the following additional tools and features:
- (Tool): [**Analyze PR components**](./tools/analyze.md/)
- (Tool): [**Custom Prompt Suggestions**](./tools/custom_prompt.md/)
- (Tool): [**Tests**](./tools/test.md/)
- (Tool): [**PR documentation**](./tools/documentation.md/)
- (Tool): [**Improve Component**](https://pr-agent-docs.codium.ai/tools/improve_component/)
- (Tool): [**Similar code search**](https://pr-agent-docs.codium.ai/tools/similar_code/)
- (Tool): [**CI feedback**](./tools/ci_feedback.md/)
- (Feature): [**Interactive triggering**](./usage-guide/automations_and_usage.md/#interactive-triggering)
- (Feature): [**SOC2 compliance check**](./tools/review.md/#soc2-ticket-compliance)
- (Feature): [**Custom labels**](./tools/describe.md/#handle-custom-labels-from-the-repos-labels-page)
- (Feature): [**Global and wiki configuration**](./usage-guide/configuration_options.md/#wiki-configuration-file)
- (Feature): [**Inline file summary**](https://pr-agent-docs.codium.ai/tools/describe/#inline-file-summary)

View File

@ -0,0 +1,19 @@
## Overview
The `analyze` tool combines advanced static code analysis with LLM capabilities to provide a comprehensive analysis of the PR code changes.
The tool scans the PR code changes, find the code components (methods, functions, classes) that changed, and enables to interactively generate tests, docs, code suggestions and similar code search for each component.
It can be invoked manually by commenting on any PR:
```
/analyze
```
## Example usage
An example result:
![Analyze 1](https://codium.ai/images/pr_agent/analyze_1.png){width=750}
**Notes**
- Language that are currently supported: Python, Java, C++, JavaScript, TypeScript, C#.

59
docs/docs/tools/ask.md Normal file
View File

@ -0,0 +1,59 @@
## Overview
The `ask` tool answers questions about the PR, based on the PR code changes. Make sure to be specific and clear in your questions.
It can be invoked manually by commenting on any PR:
```
/ask "..."
```
## Example usage
![Ask Comment](https://codium.ai/images/pr_agent/ask_comment.png){width=512}
![Ask](https://codium.ai/images/pr_agent/ask.png){width=512}
## Ask lines
You can run `/ask` on specific lines of code in the PR from the PR's diff view. The tool will answer questions based on the code changes in the selected lines.
- Click on the '+' sign next to the line number to select the line.
- To select multiple lines, click on the '+' sign of the first line and then hold and drag to select the rest of the lines.
- write `/ask "..."` in the comment box and press `Add single comment` button.
![Ask Line](https://codium.ai/images/pr_agent/Ask_line.png){width=512}
Note that the tool does not have "memory" of previous questions, and answers each question independently.
## Ask on images
You can also ask questions about images that appear in the comment, where the entire PR code will be used as context.
<br>
The basic syntax is:
```
/ask "..."
[Image](https://real_link_to_image)
```
where `https://real_link_to_image` is the direct link to the image.
Note that GitHub has a built-in mechanism of pasting images in comments. However, pasted image does not provide a direct link.
To get a direct link to an image, we recommend using the following scheme:
1) First, post a comment that contains **only** the image:
![Ask image1](https://codium.ai/images/pr_agent/ask_images1.png){width=512}
2) Quote reply to that comment:
![Ask image2](https://codium.ai/images/pr_agent/ask_images2.png){width=512}
3) In the screen opened, type the question below the image:
![Ask image3](https://codium.ai/images/pr_agent/ask_images3.png){width=512}
![Ask image4](https://codium.ai/images/pr_agent/ask_images4.png){width=512}
4) Post the comment, and receive the answer:
![Ask image5](https://codium.ai/images/pr_agent/ask_images5.png){width=512}
See a full video tutorial [here](https://codium.ai/images/pr_agent/ask_image_video.mov)

View File

@ -0,0 +1,39 @@
## Overview
The CI feedback tool (`/checks)` automatically triggers when a PR has a failed check.
The tool analyzes the failed checks and provides several feedbacks:
- Failed stage
- Failed test name
- Failure summary
- Relevant error logs
## Example usage
![Failed Check 1](https://www.codium.ai/images/pr_agent/failed_check1.png){width=768}
&rarr;
![Failed Check 2](https://www.codium.ai/images/pr_agent/failed_check2.png){width=768}
___
In addition to being automatically triggered, the tool can also be invoked manually by commenting on a PR:
```
/checks "https://github.com/{repo_name}/actions/runs/{run_number}/job/{job_number}"
```
where `{repo_name}` is the name of the repository, `{run_number}` is the run number of the failed check, and `{job_number}` is the job number of the failed check.
## Disabling the tool from running automatically
If you wish to disable the tool from running automatically, you can do so by adding the following configuration to the configuration file:
```
[checks]
enable_auto_checks_feedback = false
```
## Configuration options
- `enable_auto_checks_feedback` - if set to true, the tool will automatically provide feedback when a check is failed. Default is true.
- `excluded_checks_list` - a list of checks to exclude from the feedback, for example: ["check1", "check2"]. Default is an empty list.
- `persistent_comment` - if set to true, the tool will overwrite a previous checks comment with the new feedback. Default is true.
- `enable_help_text=true` - if set to true, the tool will provide a help message when a user comments "/checks" on a PR. Default is true.
- `final_update_message` - if `persistent_comment` is true and updating a previous checks message, the tool will also create a new message: "Persistent checks updated to latest commit". Default is true.

View File

@ -0,0 +1,60 @@
## Overview
The `generate_labels` tool scans the PR code changes, and given a list of labels and their descriptions, it automatically suggests labels that match the PR code changes.
It can be invoked manually by commenting on any PR:
```
/generate_labels
```
## Example usage
If we wish to add detect changes to SQL queries in a given PR, we can add the following custom label along with its description:
![Custom labels list](https://codium.ai/images/pr_agent/custom_labels_list.png){width=768}
When running the `generate_labels` tool on a PR that includes changes in SQL queries, it will automatically suggest the custom label:
![Custom labels published](https://codium.ai/images/pr_agent/custom_label_published.png){width=768}
Note that in addition to the dedicated tool `generate_labels`, the custom labels will also be used by the `describe` tool.
### How to enable custom labels
There are 3 ways to enable custom labels:
#### 1. CLI (local configuration file)
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
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 💎
> This feature is available only in PR-Agent Pro
* GitHub : `https://github.com/{owner}/{repo}/labels`, or click on the "Labels" tab in the issues or PRs page.
* GitLab : `https://gitlab.com/{owner}/{repo}/-/labels`, or click on "Manage" -> "Labels" on the left menu.
b. Add/edit the custom labels. It should be formatted as follows:
* Label name: The name of the custom label.
* Description: Start the description of with prefix `pr_agent:`, for example: `pr_agent: Description of when AI should suggest this label`.<br>
The description should be comprehensive and detailed, indicating when to add the desired label.
![Add native custom labels](https://codium.ai/images/pr_agent/add_native_custom_labels.png){width=880}
c. Now the custom labels will be included in the `generate_labels` tool.
> This feature is supported in GitHub and GitLab.
## Configuration options
- Change `enable_custom_labels` to True: This will turn off the default labels and enable the custom labels provided in the custom_labels.toml file.
- Add the custom labels. It should be formatted as follows:
```
[config]
enable_custom_labels=true
[custom_labels."Custom Label Name"]
description = "Description of when AI should suggest this label"
[custom_labels."Custom Label 2"]
description = "Description of when AI should suggest this label 2"
```

View File

@ -0,0 +1,58 @@
## Overview
The `custom_prompt` tool scans the PR code changes, and automatically generates suggestions for improving the PR code.
It shares similarities with the `improve` tool, but with one main difference: the `custom_prompt` tool will **only propose suggestions that follow specific guidelines defined by the prompt** in: `pr_custom_prompt.prompt` configuration.
The tool can be triggered [automatically](../usage-guide/automations_and_usage.md#github-app-automatic-tools-when-a-new-pr-is-opened) every time a new PR is opened, or can be invoked manually by commenting on a PR.
When commenting, use the following template:
```
/custom_prompt --pr_custom_prompt.prompt="
The code suggestions should focus only on the following:
- ...
- ...
"
```
With a [configuration file](../usage-guide/automations_and_usage.md#github-app), use the following template:
```
[pr_custom_prompt]
prompt="""\
The suggestions should focus only on the following:
-...
-...
"""
```
Remember - with this tool, you are the prompter. Be specific, clear, and concise in the instructions. Specify relevant aspects that you want the model to focus on. \
You might benefit from several trial-and-error iterations, until you get the correct prompt for your use case.
## Example usage
Here is an example of a possible prompt, defined in the configuration file:
```
[pr_custom_prompt]
prompt="""\
The code suggestions should focus only on the following:
- look for edge cases when implementing a new function
- make sure every variable has a meaningful name
- make sure the code is efficient
"""
```
(The instructions above are just an example. We want to emphasize that the prompt should be specific and clear, and be tailored to the needs of your project)
Results obtained with the prompt above:
![Custom prompt results](https://codium.ai/images/pr_agent/custom_suggestions_result.png){width=768}
## Configuration options
`prompt`: the prompt for the tool. It should be a multi-line string.
`num_code_suggestions`: number of code suggestions provided by the 'custom_prompt' tool. Default is 4.
`enable_help_text`: if set to true, the tool will display a help text in the comment. Default is true.

224
docs/docs/tools/describe.md Normal file
View File

@ -0,0 +1,224 @@
## Overview
The `describe` tool scans the PR code changes, and generates a description for the PR - title, type, summary, walkthrough and labels.
The tool can be triggered automatically every time a new PR is [opened](../usage-guide/automations_and_usage.md#github-app-automatic-tools-when-a-new-pr-is-opened), or it can be invoked manually by commenting on any PR:
```
/describe
```
## Example usage
### Manual triggering
Invoke the tool manually by commenting `/describe` on any PR:
![Describe comment](https://codium.ai/images/pr_agent/describe_comment.png){width=512}
After ~30 seconds, the tool will generate a description for the PR:
![Describe New](https://codium.ai/images/pr_agent/describe_new.png){width=512}
If you want to edit [configurations](#configuration-options), add the relevant ones to the command:
```
/describe --pr_description.some_config1=... --pr_description.some_config2=...
```
### Automatic triggering
To run the `describe` automatically when a PR is opened, define in a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/#wiki-configuration-file):
```
[github_app]
pr_commands = [
"/describe",
...
]
[pr_description]
publish_labels = ...
...
```
- The `pr_commands` lists commands that will be executed automatically when a PR is opened.
- The `[pr_description]` section contains the configurations for the `describe` tool you want to edit (if any).
## Configuration options
!!! example "Possible configurations"
<table>
<tr>
<td><b>publish_labels</b></td>
<td>If set to true, the tool will publish the labels to the PR. Default is true.</td>
</tr>
<tr>
<td><b>publish_description_as_comment</b></td>
<td>If set to true, the tool will publish the description as a comment to the PR. If false, it will overwrite the original description. Default is false.</td>
</tr>
<tr>
<td><b>publish_description_as_comment_persistent</b></td>
<td>If set to true and `publish_description_as_comment` is true, the tool will publish the description as a persistent comment to the PR. Default is true.</td>
</tr>
<tr>
<td><b>add_original_user_description</b></td>
<td>If set to true, the tool will add the original user description to the generated description. Default is true.</td>
</tr>
<tr>
<td><b>generate_ai_title</b></td>
<td>If set to true, the tool will also generate an AI title for the PR. Default is false.</td>
</tr>
<tr>
<td><b>extra_instructions</b></td>
<td>Optional extra instructions to the tool. For example: "focus on the changes in the file X. Ignore change in ..."</td>
</tr>
<tr>
<td><b>enable_pr_type</b></td>
<td>If set to false, it will not show the `PR type` as a text value in the description content. Default is true.</td>
</tr>
<tr>
<td><b>final_update_message</b></td>
<td>If set to true, it will add a comment message [`PR Description updated to latest commit...`](https://github.com/Codium-ai/pr-agent/pull/499#issuecomment-1837412176) after finishing calling `/describe`. Default is false.</td>
</tr>
<tr>
<td><b>enable_semantic_files_types</b></td>
<td>If set to true, "Changes walkthrough" section will be generated. Default is true.</td>
</tr>
<tr>
<td><b>collapsible_file_list</b></td>
<td>If set to true, the file list in the "Changes walkthrough" section will be collapsible. If set to "adaptive", the file list will be collapsible only if there are more than 8 files. Default is "adaptive".</td>
</tr>
<tr>
<td><b>enable_large_pr_handling</b></td>
<td>Pro feature. If set to true, in case of a large PR the tool will make several calls to the AI and combine them to be able to cover more files. Default is true.</td>
</tr>
<tr>
<td><b>enable_help_text</b></td>
<td>If set to true, the tool will display a help text in the comment. Default is false.</td>
</tr>
</table>
## Inline file summary 💎
This feature enables you to copy the `changes walkthrough` table to the "Files changed" tab, so you can quickly understand the changes in each file while reviewing the code changes (diff view).
To copy the `changes walkthrough` table to the "Files changed" tab, you can click on the checkbox that appears PR Description status message below the main PR Description:
![Add table checkbox](https://codium.ai/images/pr_agent/add_table_checkbox.png){width=512}
If you prefer to have the file summaries appear in the "Files changed" tab on every PR, change the `pr_description.inline_file_summary` parameter in the configuration file, possible values are:
- `'table'`: File changes walkthrough table will be displayed on the top of the "Files changed" tab, in addition to the "Conversation" tab.
![Diffview table](https://codium.ai/images/pr_agent/diffview-table.png){width=512}
- `true`: A collapsible file comment with changes title and a changes summary for each file in the PR.
![Diffview changes](https://codium.ai/images/pr_agent/diffview_changes.png){width=512}
- `false` (`default`): File changes walkthrough will be added only to the "Conversation" tab.
**Note**: that this feature is currently available only for GitHub.
## Markers template
To enable markers, set `pr_description.use_description_markers=true`.
Markers enable to easily integrate user's content and auto-generated content, with a template-like mechanism.
For example, if the PR original description was:
```
User content...
## PR Type:
pr_agent:type
## PR Description:
pr_agent:summary
## PR Walkthrough:
pr_agent:walkthrough
```
The marker `pr_agent:type` will be replaced with the PR type, `pr_agent:summary` will be replaced with the PR summary, and `pr_agent:walkthrough` will be replaced with the PR walkthrough.
![Describe markers before](https://codium.ai/images/pr_agent/describe_markers_before.png){width=512}
&rarr;
![Describe markers after](https://codium.ai/images/pr_agent/describe_markers_after.png){width=512}
**Configuration params**:
- `use_description_markers`: if set to true, the tool will use markers template. It replaces every marker of the form `pr_agent:marker_name` with the relevant content. Default is false.
- `include_generated_by_header`: if set to true, the tool will add a dedicated header: 'Generated by PR Agent at ...' to any automatic content. Default is true.
## Custom labels
The default labels of the describe tool are quite generic, since they are meant to be used in any repo: [`Bug fix`, `Tests`, `Enhancement`, `Documentation`, `Other`].
You can define custom labels that are relevant for your repo and use cases.
Custom labels can be defined in a [configuration file](https://pr-agent-docs.codium.ai/tools/custom_labels/#configuration-options), or directly in the repo's [labels page](#handle-custom-labels-from-the-repos-labels-page).
Make sure to provide proper title, and a detailed and well-phrased description for each label, so the tool will know when to suggest it.
Each label description should be a **conditional statement**, that indicates if to add the label to the PR or not, according to the PR content.
### Handle custom labels from a configuration file
Example for a custom labels configuration setup in a configuration file:
```
[config]
enable_custom_labels=true
[custom_labels."sql_changes"]
description = "Use when a PR contains changes to SQL queries"
[custom_labels."test"]
description = "use when a PR primarily contains new tests"
...
```
### Handle custom labels from the Repo's labels page 💎
You can also control the custom labels that will be suggested by the `describe` tool from the repo's labels page:
* GitHub : go to `https://github.com/{owner}/{repo}/labels` (or click on the "Labels" tab in the issues or PRs page)
* GitLab : go to `https://gitlab.com/{owner}/{repo}/-/labels` (or click on "Manage" -> "Labels" on the left menu)
Now add/edit the custom labels. they should be formatted as follows:
* Label name: The name of the custom label.
* Description: Start the description of with prefix `pr_agent:`, for example: `pr_agent: Description of when AI should suggest this label`.<br>
Examples for custom labels:
- `Main topic:performance` - pr_agent:The main topic of this PR is performance
- `New endpoint` - pr_agent:A new endpoint was added in this PR
- `SQL query` - pr_agent:A new SQL query was added in this PR
- `Dockerfile changes` - pr_agent:The PR contains changes in the Dockerfile
- ...
The description should be comprehensive and detailed, indicating when to add the desired label. For example:
![Add native custom labels](https://codium.ai/images/pr_agent/add_native_custom_labels.png){width=768}
## Usage Tips
!!! tip "Automation"
- When you first install PR-Agent app, the [default mode](../usage-guide/automations_and_usage.md#github-app) for the describe tool is:
```
pr_commands = ["/describe", ...]
```
meaning the `describe` tool will run automatically on every PR, with the default configurations.
- Markers are an alternative way to control the generated description, to give maximal control to the user. If you set:
```
pr_commands = ["/describe --pr_description.use_description_markers=true", ...]
```
the tool will replace every marker of the form `pr_agent:marker_name` in the PR description with the relevant content, where `marker_name` is one of the following:
* `type`: the PR type.
* `summary`: the PR summary.
* `walkthrough`: the PR walkthrough.
- Note that when markers are enabled, if the original PR description does not contain any markers, the tool will not alter the description at all.

View File

@ -0,0 +1,33 @@
## Overview
The `add_docs` tool scans the PR code changes, and automatically suggests documentation for any code components that changed in the PR (functions, classes, etc.).
It can be invoked manually by commenting on any PR:
```
/add_docs
```
## Example usage
Invoke the tool manually by commenting `/add_docs` on any PR:
![Docs command](https://codium.ai/images/pr_agent/docs_command.png){width=768}
The tool will generate documentation for all the components that changed in the PR:
![Docs component](https://codium.ai/images/pr_agent/docs_components.png){width=768}
![Docs single component](https://codium.ai/images/pr_agent/docs_single_component.png){width=768}
You can state a name of a specific component in the PR to get documentation only for that component:
```
/add_docs component_name
```
## Configuration options
- `docs_style`: The exact style of the documentation (for python docstring). you can choose between: `google`, `numpy`, `sphinx`, `restructuredtext`, `plain`. Default is `sphinx`.
- `extra_instructions`: Optional extra instructions to the tool. For example: "focus on the changes in the file X. Ignore change in ...".
**Notes**
- Language that are currently fully supported: Python, Java, C++, JavaScript, TypeScript, C#.
- This tool can also be triggered interactively by using the [`analyze`](./analyze.md) tool.

17
docs/docs/tools/help.md Normal file
View File

@ -0,0 +1,17 @@
## Overview
The `help` tool provides a list of all the available tools and their descriptions.
For PR-Agent Pro users, it also enables to trigger each tool by checking the relevant box.
It can be invoked manually by commenting on any PR:
```
/help
```
## Example usage
An example [result](https://github.com/Codium-ai/pr-agent/pull/546#issuecomment-1868524805):
![Help 1](https://codium.ai/images/pr_agent/help1.png){width=750}
&rarr;
![Analyze 2](https://codium.ai/images/pr_agent/help2.png){width=750}

195
docs/docs/tools/improve.md Normal file
View File

@ -0,0 +1,195 @@
## Overview
The `improve` tool scans the PR code changes, and automatically generates suggestions for improving the PR code.
The tool can be triggered automatically every time a new PR is [opened](../usage-guide/automations_and_usage.md#github-app-automatic-tools-when-a-new-pr-is-opened), or it can be invoked manually by commenting on any PR:
```
/improve
```
## Example usage
### Manual triggering
Invoke the tool manually by commenting `/improve` on any PR. The code suggestions by default are presented as a single comment:
![code suggestions as comment](https://codium.ai/images/pr_agent/code_suggestions_as_comment.png){width=512}
To edit [configurations](#configuration-options) related to the improve tool, use the following template:
```
/improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
```
For example, you can choose to present the suggestions as commitable code comments, by running the following command:
```
/improve --pr_code_suggestions.commitable_code_suggestions=true
```
![improve](https://codium.ai/images/pr_agent/improve.png){width=512}
Note that a single comment has a significantly smaller PR footprint. We recommend this mode for most cases.
Also note that collapsible are not supported in _Bitbucket_. Hence, the suggestions are presented there as code comments.
### Automatic triggering
To run the `improve` automatically when a PR is opened, define in a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/#wiki-configuration-file):
```
[github_app]
pr_commands = [
"/improve",
...
]
[pr_code_suggestions]
num_code_suggestions_per_chunk = ...
...
```
- The `pr_commands` lists commands that will be executed automatically when a PR is opened.
- The `[pr_code_suggestions]` section contains the configurations for the `improve` tool you want to edit (if any)
### Extended mode
An extended mode, which does not involve PR Compression and provides more comprehensive suggestions, can be invoked by commenting on any PR by setting:
```
[pr_code_suggestions]
auto_extended_mode=true
```
(This mode is true by default).
Note that the extended mode divides the PR code changes into chunks, up to the token limits, where each chunk is handled separately (might use multiple calls to GPT-4 for large PRs).
Hence, the total number of suggestions is proportional to the number of chunks, i.e., the size of the PR.
### Self-review
If you set in a configuration file:
```
[pr_code_suggestions]
demand_code_suggestions_self_review = true
```
The `improve` tool will add a checkbox below the suggestions, prompting user to acknowledge that they have reviewed the suggestions.
You can set the content of the checkbox text via:
```
[pr_code_suggestions]
code_suggestions_self_review_text = "... (your text here) ..."
```
![self_review_1](https://codium.ai/images/pr_agent/self_review_1.png){width=512}
💎 In addition, by setting:
```
[pr_code_suggestions]
approve_pr_on_self_review = true
```
the tool can automatically approve the PR when the user checks the self-review checkbox.
!!! tip "Demanding self-review from the PR author"
If you set the number of required reviewers for a PR to 2, this effectively means that the PR author must click the self-review checkbox before the PR can be merged (in addition to a human reviewer).
![self_review_2](https://codium.ai/images/pr_agent/self_review_2.png){width=512}
## Configuration options
!!! example "General options"
<table>
<tr>
<td><b>num_code_suggestions</b></td>
<td>Number of code suggestions provided by the 'improve' tool. Default is 4 for CLI, 0 for auto tools.</td>
</tr>
<tr>
<td><b>extra_instructions</b></td>
<td>Optional extra instructions to the tool. For example: "focus on the changes in the file X. Ignore change in ...".</td>
</tr>
<tr>
<td><b>rank_suggestions</b></td>
<td>If set to true, the tool will rank the suggestions, based on importance. Default is false.</td>
</tr>
<tr>
<td><b>commitable_code_suggestions</b></td>
<td>If set to true, the tool will display the suggestions as commitable code comments. Default is false.</td>
</tr>
<tr>
<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>
</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>
<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>
</tr>
<tr>
<td><b>apply_suggestions_checkbox</b></td>
<td> Enable the checkbox to create a committable suggestion. Default is true.</td>
</tr>
<tr>
<td><b>enable_help_text</b></td>
<td>If set to true, the tool will display a help text in the comment. Default is true.</td>
</tr>
</table>
!!! example "params for 'extended' mode"
<table>
<tr>
<td><b>auto_extended_mode</b></td>
<td>Enable extended mode automatically (no need for the --extended option). Default is true.</td>
</tr>
<tr>
<td><b>num_code_suggestions_per_chunk</b></td>
<td>Number of code suggestions provided by the 'improve' tool, per chunk. Default is 5.</td>
</tr>
<tr>
<td><b>rank_extended_suggestions</b></td>
<td>If set to true, the tool will rank the suggestions, based on importance. Default is true.</td>
</tr>
<tr>
<td><b>max_number_of_calls</b></td>
<td>Maximum number of chunks. Default is 5.</td>
</tr>
<tr>
<td><b>final_clip_factor</b></td>
<td>Factor to remove suggestions with low confidence. Default is 0.9.</td>
</tr>
</table>
## Usage Tips
!!! tip "Extra instructions"
Extra instructions are very important for the `improve` tool, since they enable you to guide the model to suggestions that are more relevant to the specific needs of the project.
Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify relevant aspects that you want the model to focus on.
Examples for extra instructions:
```
[pr_code_suggestions] # /improve #
extra_instructions="""\
Emphasize the following aspects:
- Does the code logic cover relevant edge cases?
- Is the code logic clear and easy to understand?
- Is the code logic efficient?
...
"""
```
Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.
!!! tip "Review vs. Improve tools comparison"
- The [review](https://pr-agent-docs.codium.ai/tools/review/) tool includes a section called 'Possible issues', that also provide feedback on the PR Code.
In this section, the model is instructed to focus **only** on [major bugs and issues](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/pr_reviewer_prompts.toml#L71).
- The `improve` tool, on the other hand, has a broader mandate, and in addition to bugs and issues, it can also give suggestions for improving code quality and making the code more efficient, readable, and maintainable (see [here](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/pr_code_suggestions_prompts.toml#L34)).
- Hence, if you are interested only in feedback about clear bugs, the `review` tool might suffice. If you want a more detailed feedback, including broader suggestions for improving the PR code, also enable the `improve` tool to run on each PR.
## A note on code suggestions quality
- While the current AI for code is getting better and better (GPT-4), it's not flawless. Not all the suggestions will be perfect, and a user should not accept all of them automatically. Critical reading and judgment are required.
- While mistakes of the AI are rare but can happen, a real benefit from the suggestions of the `improve` (and [`review`](https://pr-agent-docs.codium.ai/tools/review/)) tool is to catch, with high probability, **mistakes or bugs done by the PR author**, when they happen. So, it's a good practice to spend the needed ~30-60 seconds to review the suggestions, even if not all of them are always relevant.
- The hierarchical structure of the suggestions is designed to help the user to _quickly_ understand them, and to decide which ones are relevant and which are not:
- Only if the `Category` header is relevant, the user should move to the summarized suggestion description
- Only if the summarized suggestion description is relevant, the user should click on the collapsible, to read the full suggestion description with a code preview example.
In addition, we recommend to use the `extra_instructions` field to guide the model to suggestions that are more relevant to the specific needs of the project.
<br>
Consider also trying the [Custom Prompt Tool](./custom_prompt.md) 💎, that will **only** propose code suggestions that follow specific guidelines defined by user.

View File

@ -0,0 +1,29 @@
## Overview
The `improve_component` tool generates code suggestions for a specific code component that changed in the PR.
it can be invoked manually by commenting on any PR:
```
/improve_component component_name
```
To get a list of the components that changed in the PR and choose the relevant component interactively, use the [`analyze`](./analyze.md) tool.
## Example usage
Invoke the tool manually by commenting `/improve_component` on any PR:
![improve_component1](https://codium.ai/images/pr_agent/improve_component1.png){width=768}
The tool will generate code suggestions for the selected component (if no component is stated, it will generate code suggestions for the largest component):
![improve_component2](https://codium.ai/images/pr_agent/improve_component2.png){width=768}
**Notes**
- Language that are currently supported by the tool: Python, Java, C++, JavaScript, TypeScript, C#.
- This tool can also be triggered interactively by using the [`analyze`](./analyze.md) tool.
## Configuration options
- `num_code_suggestions`: number of code suggestions to provide. Default is 4
- `extra_instructions`: Optional extra instructions to the tool. For example: "focus on ...".
- `file`: in case there are several components with the same name, you can specify the relevant file.
- `class_name`: in case there are several methods with the same name in the same file, you can specify the relevant class name.

22
docs/docs/tools/index.md Normal file
View File

@ -0,0 +1,22 @@
# Tools
Here is a list of PR-Agent tools, each with a dedicated page that explains how to use it:
| Tool | Description |
|------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------|
| **[PR Description (`/describe`](./describe.md))** | Automatically generating PR description - title, type, summary, code walkthrough and labels |
| **[PR Review (`/review`](./review.md))** | Adjustable feedback about the PR, possible issues, security concerns, review effort and more |
| **[Code Suggestions (`/improve`](./improve.md))** | Code suggestions for improving the PR |
| **[Question Answering (`/ask ...`](./ask.md))** | Answering free-text questions about the PR, or on specific code lines |
| **[Update Changelog (`/update_changelog`](./update_changelog.md))** | Automatically updating the CHANGELOG.md file with the PR changes |
| **[Find Similar Issue (`/similar_issue`](./similar_issues.md))** | Automatically retrieves and presents similar issues |
| **[Help (`/help`](./help.md))** | Provides a list of all the available tools. Also enables to trigger them interactively (💎) |
| **💎 [Add Documentation (`/add_docs`](./documentation.md))** | Generates documentation to methods/functions/classes that changed in the PR |
| **💎 [Generate Custom Labels (`/generate_labels`](./custom_labels.md))** | Generates custom labels for the PR, based on specific guidelines defined by the user |
| **💎 [Analyze (`/analyze`](./analyze.md))** | Identify code components that changed in the PR, and enables to interactively generate tests, docs, and code suggestions for each component |
| **💎 [Custom Prompt (`/custom_prompt`](./custom_prompt.md))** | Automatically generates custom suggestions for improving the PR code, based on specific guidelines defined by the user |
| **💎 [Generate Tests (`/test component_name`](./test.md))** | Automatically generates unit tests for a selected component, based on the PR code changes |
| **💎 [Improve Component (`/improve_component component_name`](./improve_component.md))** | Generates code suggestions for a specific code component that changed in the PR |
| **💎 [CI Feedback (`/checks ci_job`](./ci_feedback.md))** | Automatically generates feedback and analysis for a failed CI job |
Note that the tools marked with 💎 are available only for PR-Agent Pro users.

261
docs/docs/tools/review.md Normal file
View File

@ -0,0 +1,261 @@
## Overview
The `review` tool scans the PR code changes, and generates a list of feedbacks about the PR, aiming to aid the reviewing process.
<br>
The tool can be triggered automatically every time a new PR is [opened](../usage-guide/automations_and_usage.md#github-app-automatic-tools-when-a-new-pr-is-opened), or can be invoked manually by commenting on any PR:
```
/review
```
Note that the main purpose of the `review` tool is to provide the **PR reviewer** with useful feedbacks and insights. The PR author, in contrast, may prefer to save time and focus on the output of the [improve](./improve.md) tool, which provides actionable code suggestions.
## Example usage
### Manual triggering
Invoke the tool manually by commenting `/review` on any PR:
![review comment](https://codium.ai/images/pr_agent/review_comment.png){width=512}
After ~30 seconds, the tool will generate a review for the PR:
![review](https://codium.ai/images/pr_agent/review3.png){width=512}
If you want to edit [configurations](#configuration-options), add the relevant ones to the command:
```
/review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
```
### Automatic triggering
To run the `review` automatically when a PR is opened, define in a [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/#wiki-configuration-file):
```
[github_app]
pr_commands = [
"/review",
...
]
[pr_reviewer]
num_code_suggestions = ...
...
```
- The `pr_commands` lists commands that will be executed automatically when a PR is opened.
- The `[pr_reviewer]` section contains the configurations for the `review` tool you want to edit (if any).
### Incremental Mode
Incremental review only considers changes since the last PR-Agent review. This can be useful when working on the PR in an iterative manner, and you want to focus on the changes since the last review instead of reviewing the entire PR again.
For invoking the incremental mode, the following command can be used:
```
/review -i
```
Note that the incremental mode is only available for GitHub.
![incremental review](https://codium.ai/images/pr_agent/incremental_review_2.png){width=512}
[//]: # (### PR Reflection)
[//]: # ()
[//]: # (By invoking:)
[//]: # (```)
[//]: # (/reflect_and_review)
[//]: # (```)
[//]: # (The tool will first ask the author questions about the PR, and will guide the review based on their answers.)
[//]: # ()
[//]: # (![reflection questions]&#40;https://codium.ai/images/pr_agent/reflection_questions.png&#41;{width=512})
[//]: # ()
[//]: # (![reflection answers]&#40;https://codium.ai/images/pr_agent/reflection_answers.png&#41;{width=512})
[//]: # ()
[//]: # (![reflection insights]&#40;https://codium.ai/images/pr_agent/reflection_insights.png&#41;{width=512})
## Configuration options
!!! example "General options"
<table>
<tr>
<td><b>num_code_suggestions</b></td>
<td>Number of code suggestions provided by the 'review' tool. For manual comments, default is 4. For PR-Agent app auto tools, default is 0, meaning no code suggestions will be provided by the review tool, unless you manually edit pr_commands.</td>
</tr>
<tr>
<td><b>inline_code_comments</b></td>
<td>If set to true, the tool will publish the code suggestions as comments on the code diff. Default is false.</td>
</tr>
<tr>
<td><b>persistent_comment</b></td>
<td>If set to true, the review comment will be persistent, meaning that every new review request will edit the previous one. Default is true.</td>
</tr>
<tr>
<td><b>extra_instructions</b></td>
<td>Optional extra instructions to the tool. For example: "focus on the changes in the file X. Ignore change in ...".</td>
</tr>
<tr>
<td><b>enable_help_text</b></td>
<td>If set to true, the tool will display a help text in the comment. Default is true.</td>
</tr>
</table>
!!! example "Enable\\disable specific sub-sections"
<table>
<tr>
<td><b>require_score_review</b></td>
<td>If set to true, the tool will add a section that scores the PR. Default is false.</td>
</tr>
<tr>
<td><b>require_tests_review</b></td>
<td>If set to true, the tool will add a section that checks if the PR contains tests. Default is true.</td>
</tr>
<tr>
<td><b>require_estimate_effort_to_review</b></td>
<td>If set to true, the tool will add a section that estimates the effort needed to review the PR. Default is true.</td>
</tr>
<tr>
<td><b>require_can_be_split_review</b></td>
<td>If set to true, the tool will add a section that checks if the PR contains several themes, and can be split into smaller PRs. Default is false.</td>
</tr>
<tr>
<td><b>require_security_review</b></td>
<td>If set to true, the tool will add a section that checks if the PR contains a possible security or vulnerability issue. Default is true.</td>
</tr>
</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>
<td><b>require_soc2_ticket</b></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>
</table>
!!! example "Adding PR labels"
You can enable\disable the `review` tool to add specific labels to the PR:
<table>
<tr>
<td><b>enable_review_labels_security</b></td>
<td>If set to true, the tool will publish a 'possible security issue' label if it detects a security issue. Default is true.</td>
</tr>
<tr>
<td><b>enable_review_labels_effort</b></td>
<td>If set to true, the tool will publish a 'Review effort [1-5]: x' label. Default is true.</td>
</tr>
</table>
!!! example "Auto-approval"
If enabled, the `review` tool can approve a PR when a specific comment, `/review auto_approve`, is invoked.
<table>
<tr>
<td><b>enable_auto_approval</b></td>
<td>If set to true, the tool will approve the PR when invoked with the 'auto_approve' command. Default is false. This flag can be changed only from configuration file.</td>
</tr>
<tr>
<td><b>maximal_review_effort</b></td>
<td>Maximal effort level for auto-approval. If the PR's estimated review effort is above this threshold, the auto-approval will not run. Default is 5.</td>
</tr>
</table>
## Usage Tips
!!! tip "General guidelines"
The `review` tool provides a collection of configurable feedbacks about a PR.
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:
`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.
!!! tip "Automation"
When you first install PR-Agent app, the [default mode](../usage-guide/automations_and_usage.md#github-app-automatic-tools-when-a-new-pr-is-opened) for the `review` tool is:
```
pr_commands = ["/review --pr_reviewer.num_code_suggestions=0", ...]
```
Meaning the `review` tool will run automatically on every PR, without providing code suggestions.
Edit this field to enable/disable the tool, or to change the used configurations.
!!! tip "Possible labels from the review tool"
The `review` tool can auto-generate two specific types of labels for a PR:
- a `possible security issue` label that detects if a possible [security issue](https://github.com/Codium-ai/pr-agent/blob/tr/user_description/pr_agent/settings/pr_reviewer_prompts.toml#L136) exists in the PR code (`enable_review_labels_security` flag)
- a `Review effort [1-5]: x` label, where x is the estimated effort to review the PR (`enable_review_labels_effort` flag)
Both modes are useful, and we recommended to enable them.
!!! tip "Extra instructions"
Extra instructions are important.
The `review` tool can be configured with extra instructions, which can be used to guide the model to a feedback tailored to the needs of your project.
Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify the relevant sub-tool, and the relevant aspects of the PR that you want to emphasize.
Examples for extra instructions:
```
[pr_reviewer]
extra_instructions="""\
In the code feedback section, emphasize the following:
- Does the code logic cover relevant edge cases?
- Is the code logic clear and easy to understand?
- Is the code logic efficient?
...
"""
```
Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.
!!! tip "Auto-approval"
PR-Agent can approve a PR when a specific comment is invoked.
To ensure safety, the auto-approval feature is disabled by default. To enable auto-approval, you need to actively set in a pre-defined configuration file the following:
```
[pr_reviewer]
enable_auto_approval = true
```
(this specific flag cannot be set with a command line argument, only in the configuration file, committed to the repository)
After enabling, by commenting on a PR:
```
/review auto_approve
```
PR-Agent will automatically approve the PR, and add a comment with the approval.
You can also enable auto-approval only if the PR meets certain requirements, such as that the `estimated_review_effort` label is equal or below a certain threshold, by adjusting the flag:
```
[pr_reviewer]
maximal_review_effort = 5
```
[//]: # (!!! tip "Code suggestions")
[//]: # ()
[//]: # ( If you set `num_code_suggestions`>0 , the `review` tool will also provide code suggestions.)
[//]: # ( )
[//]: # ( Notice If you are interested **only** in the code suggestions, it is recommended to use the [`improve`]&#40;./improve.md&#41; 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.)

View File

@ -0,0 +1,63 @@
## Overview
The similar code tool retrieves the most similar code components from inside the organization's codebase, or from open-source code.
For example:
`Global Search` for a method called `chat_completion`:
![similar code global](https://codium.ai/images/pr_agent/similar_code_global2.png){width=768}
PR-Agent will examine the code component and will extract the most relevant keywords to search for similar code:
- `extracted keywords`: the keywords that were extracted from the code by PR-Agent. the link will open a search page with the extracted keywords, to allow the user to modify the search if needed.
- `search context`: the context in which the search will be performed, organization's codebase or open-source code (Global).
- `similar code`: the most similar code components found. the link will open the code component in the relevant file.
- `relevant repositories`: the open-source repositories in which that are relevant to the searched code component and it's keywords.
Search result link example:
![code search result single](https://codium.ai/images/pr_agent/code_search_result_single.png){width=768}
`Organization Search`:
![similar code org](https://codium.ai/images/pr_agent/similar_code_org.png){width=768}
## How to use
### Manually
To invoke the `similar code` tool manually, comment on the PR:
```
/find_similar_component COMPONENT_NAME
```
Where `COMPONENT_NAME` should be the name of a code component in the PR (class, method, function).
If there is a name ambiguity, there are two configurations that will help the tool to find the correct component:
- `--pr_find_similar_component.file`: in case there are several components with the same name, you can specify the relevant file.
- `--pr_find_similar_component.class_name`: in case there are several methods with the same name in the same file, you can specify the relevant class name.
example:
```
/find_similar_component COMPONENT_NAME --pr_find_similar_component.file=FILE_NAME
```
### Automatically (via Analyze table)
It can be invoked automatically from the analyze table, can be accessed by:
```
/analyze
```
Choose the components you want to find similar code for, and click on the `similar` checkbox.
![analyze similar](https://codium.ai/images/pr_agent/analyze_similar.png){width=768}
If you are looking to search for similar code in the organization's codebase, you can click on the `Organization` checkbox, and it will invoke a new search command just for the organization's codebase.
![similar code global](https://codium.ai/images/pr_agent/similar_code_global.png){width=768}
## Configuration options
- `search_from_org`: if set to true, the tool will search for similar code in the organization's codebase. Default is false.
- `number_of_keywords`: number of keywords to use for the search. Default is 5.
- `number_of_results`: the maximum number of results to present. Default is 5.

View File

@ -0,0 +1,43 @@
## Overview
The similar issue tool retrieves the most similar issues to the current issue.
It can be invoked manually by commenting on any PR:
```
/similar_issue
```
## Example usage
![similar_issue_original_issue](https://codium.ai/images/pr_agent/similar_issue_original_issue.png){width=768}
![similar_issue_comment](https://codium.ai/images/pr_agent/similar_issue_comment.png){width=768}
![similar_issue](https://codium.ai/images/pr_agent/similar_issue.png){width=768}
Note that to perform retrieval, the `similar_issue` tool indexes all the repo previous issues (once).
**Select VectorDBs** by changing `pr_similar_issue` parameter in `configuration.toml` file
2 VectorDBs are available to switch in
1. LanceDB
2. Pinecone
To enable usage of the '**similar issue**' tool for Pinecone, you need to set the following keys in `.secrets.toml` (or in the relevant environment variables):
```
[pinecone]
api_key = "..."
environment = "..."
```
These parameters can be obtained by registering to [Pinecone](https://app.pinecone.io/?sessionType=signup/).
## How to use
- To invoke the 'similar issue' tool from **CLI**, run:
`python3 cli.py --issue_url=... similar_issue`
- To invoke the 'similar' issue tool via online usage, [comment](https://github.com/Codium-ai/pr-agent/issues/178#issuecomment-1716934893) on a PR:
`/similar_issue`
- You can also enable the 'similar issue' tool to run automatically when a new issue is opened, by adding it to the [pr_commands list in the github_app section](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L66)

36
docs/docs/tools/test.md Normal file
View File

@ -0,0 +1,36 @@
## Overview
By combining LLM abilities with static code analysis, the `test` tool generate tests for a selected component, based on the PR code changes.
It can be invoked manually by commenting on any PR:
```
/test component_name
```
where 'component_name' is the name of a specific component in the PR.
To get a list of the components that changed in the PR and choose the relevant component interactively, use the [`analyze`](./analyze.md) tool.
## Example usage
Invoke the tool manually by commenting `/test` on any PR:
![test1](https://codium.ai/images/pr_agent/test1.png){width=704}
The tool will generate tests for the selected component (if no component is stated, it will generate tests for largest component):
![test2](https://codium.ai/images/pr_agent/test2.png){width=768}
![test3](https://codium.ai/images/pr_agent/test3.png){width=768}
(Example taken from [here](https://github.com/Codium-ai/pr-agent/pull/598#issuecomment-1913679429)):
**Notes**
- Language that are currently supported by the tool: Python, Java, C++, JavaScript, TypeScript, C#.
- This tool can also be triggered interactively by using the [`analyze`](./analyze.md) tool.
## Configuration options
- `num_tests`: number of tests to generate. Default is 3.
- `testing_framework`: the testing framework to use. If not set, for Python it will use `pytest`, for Java it will use `JUnit`, for C++ it will use `Catch2`, and for JavaScript and TypeScript it will use `jest`.
- `avoid_mocks`: if set to true, the tool will try to avoid using mocks in the generated tests. Note that even if this option is set to true, the tool might still use mocks if it cannot generate a test without them. Default is true.
- `extra_instructions`: Optional extra instructions to the tool. For example: "use the following mock injection scheme: ...".
- `file`: in case there are several components with the same name, you can specify the relevant file.
- `class_name`: in case there are several methods with the same name in the same file, you can specify the relevant class name.
- `enable_help_text`: if set to true, the tool will add a help text to the PR comment. Default is true.

View File

@ -0,0 +1,19 @@
## Overview
The `update_changelog` tool automatically updates the CHANGELOG.md file with the PR changes.
It can be invoked manually by commenting on any PR:
```
/update_changelog
```
## Example usage
![update_changelog_comment](https://codium.ai/images/pr_agent/update_changelog_comment.png){width=768}
![update_changelog](https://codium.ai/images/pr_agent/update_changelog.png){width=768}
## Configuration options
Under the section `pr_update_changelog`, the [configuration file](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L50) contains options to customize the 'update changelog' tool:
- `push_changelog_changes`: whether to push the changes to CHANGELOG.md, or just print them. Default is false (print only).
- `extra_instructions`: Optional extra instructions to the tool. For example: "focus on the changes in the file X. Ignore change in ...

View File

@ -0,0 +1,254 @@
## Ignoring files from analysis
In some cases, you may want to exclude specific files or directories from the analysis performed by CodiumAI PR-Agent. This can be useful, for example, when you have files that are generated automatically or files that shouldn't be reviewed, like vendored code.
You can ignore files or folders using the following methods:
- `IGNORE.GLOB`
- `IGNORE.REGEX`
which you can edit to ignore files or folders based on glob or regex patterns.
### Example usage
Let's look at an example where we want to ignore all files with `.py` extension from the analysis.
To ignore Python files in a PR with online usage, comment on a PR:
`/review --ignore.glob="['*.py']"`
To ignore Python files in all PRs using `glob` pattern, set in a configuration file:
```
[ignore]
glob = ['*.py']
```
And to ignore Python files in all PRs using `regex` pattern, set in a configuration file:
```
[regex]
regex = ['.*\.py$']
```
## Extra instructions
All PR-Agent tools have a parameter called `extra_instructions`, that enables to add free-text extra instructions. Example usage:
```
/update_changelog --pr_update_changelog.extra_instructions="Make sure to update also the version ..."
```
## Working with large PRs
The default mode of CodiumAI is to have a single call per tool, using GPT-4, which has a token limit of 8000 tokens.
This mode provides a very good speed-quality-cost tradeoff, and can handle most PRs successfully.
When the PR is above the token limit, it employs a [PR Compression strategy](../core-abilities/index.md).
However, for very large PRs, or in case you want to emphasize quality over speed and cost, there are two possible solutions:
1) [Use a model](https://codium-ai.github.io/Docs-PR-Agent/usage-guide/#changing-a-model) with larger context, like GPT-32K, or claude-100K. This solution will be applicable for all the tools.
2) For the `/improve` tool, there is an ['extended' mode](https://codium-ai.github.io/Docs-PR-Agent/tools/#improve) (`/improve --extended`),
which divides the PR to chunks, and processes each chunk separately. With this mode, regardless of the model, no compression will be done (but for large PRs, multiple model calls may occur)
## Changing a model
See [here](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/algo/__init__.py) for the list of available models.
To use a different model than the default (GPT-4), you need to edit [configuration file](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L2).
For models and environments not from OPENAI, you might need to provide additional keys and other parameters. See below for instructions.
### Azure
To use Azure, set in your `.secrets.toml` (working from CLI), or in the GitHub `Settings > Secrets and variables` (working from GitHub App or GitHub Action):
```
[openai]
key = "" # your azure api key
api_type = "azure"
api_version = '2023-05-15' # Check Azure documentation for the current API version
api_base = "" # The base URL for your Azure OpenAI resource. e.g. "https://<your resource name>.openai.azure.com"
deployment_id = "" # The deployment name you chose when you deployed the engine
```
and set in your configuration file:
```
[config]
model="" # the OpenAI model you've deployed on Azure (e.g. gpt-3.5-turbo)
```
### Hugging Face
**Local**
You can run Hugging Face models locally through either [VLLM](https://docs.litellm.ai/docs/providers/vllm) or [Ollama](https://docs.litellm.ai/docs/providers/ollama)
E.g. to use a new Hugging Face model locally via Ollama, set:
```
[__init__.py]
MAX_TOKENS = {
"model-name-on-ollama": <max_tokens>
}
e.g.
MAX_TOKENS={
...,
"ollama/llama2": 4096
}
[config] # in configuration.toml
model = "ollama/llama2"
model_turbo = "ollama/llama2"
[ollama] # in .secrets.toml
api_base = ... # the base url for your Hugging Face inference endpoint
# e.g. if running Ollama locally, you may use:
api_base = "http://localhost:11434/"
```
### Inference Endpoints
To use a new model with Hugging Face Inference Endpoints, for example, set:
```
[__init__.py]
MAX_TOKENS = {
"model-name-on-huggingface": <max_tokens>
}
e.g.
MAX_TOKENS={
...,
"meta-llama/Llama-2-7b-chat-hf": 4096
}
[config] # in configuration.toml
model = "huggingface/meta-llama/Llama-2-7b-chat-hf"
model_turbo = "huggingface/meta-llama/Llama-2-7b-chat-hf"
[huggingface] # in .secrets.toml
key = ... # your Hugging Face api key
api_base = ... # the base url for your Hugging Face inference endpoint
```
(you can obtain a Llama2 key from [here](https://replicate.com/replicate/llama-2-70b-chat/api))
### Replicate
To use Llama2 model with Replicate, for example, set:
```
[config] # in configuration.toml
model = "replicate/llama-2-70b-chat:2c1608e18606fad2812020dc541930f2d0495ce32eee50074220b87300bc16e1"
model_turbo = "replicate/llama-2-70b-chat:2c1608e18606fad2812020dc541930f2d0495ce32eee50074220b87300bc16e1"
[replicate] # in .secrets.toml
key = ...
```
(you can obtain a Llama2 key from [here](https://replicate.com/replicate/llama-2-70b-chat/api))
Also, review the [AiHandler](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/algo/ai_handler.py) file for instructions on how to set keys for other models.
### Groq
To use Llama3 model with Groq, for example, set:
```
[config] # in configuration.toml
model = "llama3-70b-8192"
model_turbo = "llama3-70b-8192"
fallback_models = ["groq/llama3-70b-8192"]
[groq] # in .secrets.toml
key = ... # your Groq api key
```
(you can obtain a Groq key from [here](https://console.groq.com/keys))
### Vertex AI
To use Google's Vertex AI platform and its associated models (chat-bison/codechat-bison) set:
```
[config] # in configuration.toml
model = "vertex_ai/codechat-bison"
model_turbo = "vertex_ai/codechat-bison"
fallback_models="vertex_ai/codechat-bison"
[vertexai] # in .secrets.toml
vertex_project = "my-google-cloud-project"
vertex_location = ""
```
Your [application default credentials](https://cloud.google.com/docs/authentication/application-default-credentials) will be used for authentication so there is no need to set explicit credentials in most environments.
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.
### Anthropic
To use Anthropic models, set the relevant models in the configuration section of the configuration file:
```
[config]
model="anthropic/claude-3-opus-20240229"
model_turbo="anthropic/claude-3-opus-20240229"
fallback_models=["anthropic/claude-3-opus-20240229"]
```
And also set the api key in the .secrets.toml file:
```
[anthropic]
KEY = "..."
```
### Amazon Bedrock
To use Amazon Bedrock and its foundational models, add the below configuration:
```
[config] # in configuration.toml
model="bedrock/anthropic.claude-3-sonnet-20240229-v1:0"
model_turbo="bedrock/anthropic.claude-3-sonnet-20240229-v1:0"
fallback_models=["bedrock/anthropic.claude-v2:1"]
[aws] # in .secrets.toml
bedrock_region = "us-east-1"
```
Note that you have to add access to foundational models before using them. Please refer to [this document](https://docs.aws.amazon.com/bedrock/latest/userguide/setting-up.html) for more details.
If you are using the claude-3 model, please configure the following settings as there are parameters incompatible with claude-3.
```
[litellm]
drop_params = true
```
AWS session is automatically authenticated from your environment, but you can also explicitly set `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables.
## Patch Extra Lines
By default, around any change in your PR, git patch provides three lines of context above and below the change.
```
@@ -12,5 +12,5 @@ def func1():
code line that already existed in the file...
code line that already existed in the file...
code line that already existed in the file....
-code line that was removed in the PR
+new code line added in the PR
code line that already existed in the file...
code line that already existed in the file...
code line that already existed in the file...
```
For the `review`, `describe`, `ask` and `add_docs` tools, if the token budget allows, PR-Agent tries to increase the number of lines of context, via the parameter:
```
[config]
patch_extra_lines=3
```
Increasing this number provides more context to the model, but will also increase the token budget.
If the PR is too large (see [PR Compression strategy](https://github.com/Codium-ai/pr-agent/blob/main/PR_COMPRESSION.md)), PR-Agent automatically sets this number to 0, using the original git patch.
## Editing the prompts
The prompts for the various PR-Agent tools are defined in the `pr_agent/settings` folder.
In practice, the prompts are loaded and stored as a standard setting object.
Hence, editing them is similar to editing any other configuration value - just place the relevant key in `.pr_agent.toml`file, and override the default value.
For example, if you want to edit the prompts of the [describe](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/pr_description_prompts.toml) tool, you can add the following to your `.pr_agent.toml` file:
```
[pr_description_prompt]
system="""
...
"""
user="""
...
"""
```
Note that the new prompt will need to generate an output compatible with the relevant [post-process function](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/tools/pr_description.py#L137).

View File

@ -0,0 +1,223 @@
## Local repo (CLI)
When running from your locally cloned PR-Agent repo (CLI), your local configuration file will be used.
Examples of invoking the different tools via the CLI:
- **Review**: `python -m pr_agent.cli --pr_url=<pr_url> review`
- **Describe**: `python -m pr_agent.cli --pr_url=<pr_url> describe`
- **Improve**: `python -m pr_agent.cli --pr_url=<pr_url> improve`
- **Ask**: `python -m pr_agent.cli --pr_url=<pr_url> ask "Write me a poem about this PR"`
- **Reflect**: `python -m pr_agent.cli --pr_url=<pr_url> reflect`
- **Update Changelog**: `python -m pr_agent.cli --pr_url=<pr_url> update_changelog`
`<pr_url>` is the url of the relevant PR (for example: [#50](https://github.com/Codium-ai/pr-agent/pull/50)).
**Notes:**
(1) in addition to editing your local configuration file, you can also change any configuration value by adding it to the command line:
```
python -m pr_agent.cli --pr_url=<pr_url> /review --pr_reviewer.extra_instructions="focus on the file: ..."
```
(2) You can print results locally, without publishing them, by setting in `configuration.toml`:
```
[config]
publish_output=false
verbosity_level=2
```
This is useful for debugging or experimenting with different tools.
### Online usage
Online usage means invoking PR-Agent tools by [comments](https://github.com/Codium-ai/pr-agent/pull/229#issuecomment-1695021901) on a PR.
Commands for invoking the different tools via comments:
- **Review**: `/review`
- **Describe**: `/describe`
- **Improve**: `/improve`
- **Ask**: `/ask "..."`
- **Reflect**: `/reflect`
- **Update Changelog**: `/update_changelog`
To edit a specific configuration value, just add `--config_path=<value>` to any command.
For example, if you want to edit the `review` tool configurations, you can run:
```
/review --pr_reviewer.extra_instructions="..." --pr_reviewer.require_score_review=false
```
Any configuration value in [configuration file](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml) file can be similarly edited. Comment `/config` to see the list of available configurations.
## GitHub App
!!! note "Configurations for PR-Agent Pro"
PR-Agent Pro for GitHub is an App, hosted by CodiumAI. So all the instructions below are relevant also for PR-Agent Pro users.
Same goes for [GitLab webhook](#gitlab-webhook) and [BitBucket App](#bitbucket-app) sections.
### GitHub app automatic tools when a new PR is opened
The [github_app](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L108) section defines GitHub app specific configurations.
The configuration parameter `pr_commands` defines the list of tools that will be **run automatically** when a new PR is opened.
```
[github_app]
pr_commands = [
"/describe --pr_description.final_update_message=false",
"/review --pr_reviewer.num_code_suggestions=0",
"/improve",
]
```
This means that when a new PR is opened/reopened or marked as ready for review, PR-Agent will run the `describe`, `review` and `improve` tools.
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://codium-ai.github.io/Docs-PR-Agent/usage-guide/#configuration-options): **wiki**, **local**, or **global**.
For example, if your local `.pr_agent.toml` file contains:
```
[pr_description]
generate_ai_title = true
```
Every time you run the `describe` tool, including automatic runs, the PR title will be generated by the AI.
To cancel the automatic run of all the tools, set:
```
[github_app]
pr_commands = []
```
You can also disable automatic runs for PRs with specific titles, by setting the `ignore_pr_titles` parameter with the relevant regex. For example:
```
[github_app]
ignore_pr_title = ["^[Auto]", ".*ignore.*"]
```
will ignore PRs with titles that start with "Auto" or contain the word "ignore".
### GitHub app automatic tools for push actions (commits to an open PR)
In addition to running automatic tools when a PR is opened, the GitHub app can also respond to new code that is pushed to an open PR.
The configuration toggle `handle_push_trigger` can be used to enable this feature.
The configuration parameter `push_commands` defines the list of tools that will be **run automatically** when new code is pushed to the PR.
```
[github_app]
handle_push_trigger = true
push_commands = [
"/describe",
"/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 PR-Agent will run the `describe` and `review` tools, with the specified parameters.
## GitHub Action
`GitHub Action` is a different way to trigger PR-Agent tools, and uses a different configuration mechanism than `GitHub App`.<br>
You can configure settings for `GitHub Action` by adding environment variables under the env section in `.github/workflows/pr_agent.yml` file.
Specifically, start by setting the following environment variables:
```yaml
env:
OPENAI_KEY: ${{ secrets.OPENAI_KEY }} # Make sure to add your OpenAI key to your repo secrets
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Make sure to add your GitHub token to your repo secrets
github_action_config.auto_review: "true" # enable\disable auto review
github_action_config.auto_describe: "true" # enable\disable auto describe
github_action_config.auto_improve: "true" # enable\disable auto improve
```
`github_action_config.auto_review`, `github_action_config.auto_describe` and `github_action_config.auto_improve` are used to enable/disable automatic tools that run when a new PR is opened.
If not set, the default configuration is for all three tools to run automatically when a new PR is opened.
`github_action_config.enable_output` are used to enable/disable github actions [output parameter](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#outputs-for-docker-container-and-javascript-actions) (default is `true`).
Review result is output as JSON to `steps.{step-id}.outputs.review` property.
The JSON structure is equivalent to the yaml data structure defined in [pr_reviewer_prompts.toml](https://github.com/idubnori/pr-agent/blob/main/pr_agent/settings/pr_reviewer_prompts.toml).
Note that you can give additional config parameters by adding environment variables to `.github/workflows/pr_agent.yml`, or by using a `.pr_agent.toml` [configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/#global-configuration-file) in the root of your repo
For example, you can set an environment variable: `pr_description.publish_labels=false`, or add a `.pr_agent.toml` file with the following content:
```
[pr_description]
publish_labels = false
```
to prevent PR-Agent from publishing labels when running the `describe` tool.
## GitLab Webhook
After setting up a GitLab webhook, to control which commands will run automatically when a new MR is opened, you can set the `pr_commands` parameter in the configuration file, similar to the GitHub App:
```
[gitlab]
pr_commands = [
"/describe",
"/review --pr_reviewer.num_code_suggestions=0",
"/improve",
]
```
the GitLab webhook can also respond to new code that is pushed to an open MR.
The configuration toggle `handle_push_trigger` can be used to enable this feature.
The configuration parameter `push_commands` defines the list of tools that will be **run automatically** when new code is pushed to the MR.
```
[gitlab]
handle_push_trigger = true
push_commands = [
"/describe",
"/review --pr_reviewer.num_code_suggestions=0 --pr_reviewer.final_update_message=false",
]
```
Note that to use the 'handle_push_trigger' feature, you need to give the gitlab webhook also the "Push events" scope.
## BitBucket App
Similar to GitHub app, when running PR-Agent from BitBucket App, the default [configuration file](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml) from a pre-built docker will be initially loaded.
By uploading a local `.pr_agent.toml` file to the root of the repo's main branch, you can edit and customize any configuration parameter. Note that you need to upload `.pr_agent.toml` prior to creating a PR, in order for the configuration to take effect.
For example, if your local `.pr_agent.toml` file contains:
```
[pr_reviewer]
inline_code_comments = true
```
Each time you invoke a `/review` tool, it will use inline code comments.
### BitBucket Self-Hosted App automatic tools
To control which commands will run automatically when a new PR is opened, you can set the `pr_commands` parameter in the configuration file:
Specifically, set the following values:
```
[bitbucket_app]
pr_commands = [
"/review --pr_reviewer.num_code_suggestions=0",
"/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.
Since this platform only supports inline code suggestions, we want to limit the number of suggestions, and only present a limited number.
## Azure DevOps provider
To use Azure DevOps provider use the following settings in configuration.toml:
```
[config]
git_provider="azure"
```
Azure DevOps provider supports [PAT token](https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=Windows) or [DefaultAzureCredential](https://learn.microsoft.com/en-us/azure/developer/python/sdk/authentication-overview#authentication-in-server-environments) authentication.
PAT is faster to create, but has build in expiration date, and will use the user identity for API calls.
Using DefaultAzureCredential you can use managed identity or Service principle, which are more secure and will create separate ADO user identity (via AAD) to the agent.
If PAT was chosen, you can assign the value in .secrets.toml.
If DefaultAzureCredential was chosen, you can assigned the additional env vars like AZURE_CLIENT_SECRET directly,
or use managed identity/az cli (for local development) without any additional configuration.
in any case, 'org' value must be assigned in .secrets.toml:
```
[azure_devops]
org = "https://dev.azure.com/YOUR_ORGANIZATION/"
# pat = "YOUR_PAT_TOKEN" needed only if using PAT for authentication
```
### Azure DevOps Webhook
To control which commands will run automatically when a new PR is opened, you can set the `pr_commands` parameter in the configuration file, similar to the GitHub App:
```
[azure_devops_server]
pr_commands = [
"/describe",
"/review --pr_reviewer.num_code_suggestions=0",
"/improve",
]
```

View File

@ -0,0 +1,61 @@
The different tools and sub-tools used by CodiumAI PR-Agent are adjustable via the **[configuration file](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml)**.
In addition to general configuration options, each tool has its own configurations. For example, the `review` tool will use parameters from the [pr_reviewer](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L16) section in the configuration file.
See the [Tools Guide](https://codium-ai.github.io/Docs-PR-Agent/tools/) for a detailed description of the different tools and their configurations.
There are three ways to set persistent configurations:
1. Wiki configuration page 💎
2. Local configuration file
3. Global configuration file 💎
In terms of precedence, wiki configurations will override local configurations, and local configurations will override global configurations.
!!! tip "Tip1: edit only what you need"
Your configuration file should be minimal, and edit only the relevant values. Don't copy the entire configuration options, since it can lead to legacy problems when something changes.
!!! tip "Tip2: show relevant configurations"
If you set `config.output_relevant_configurations=true`, each tool will also output in a collapsible section its relevant configurations. This can be useful for debugging, or getting to know the configurations better.
## Wiki configuration file 💎
For GitHub and GitLab, with PR-Agent-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**.
![wiki_configuration](https://codium.ai/images/pr_agent/wiki_configuration.png){width=512}
Click [here](https://codium.ai/images/pr_agent/wiki_configuration_pr_agent.mp4) to see a short instructional video. We recommend surrounding the configuration content with triple-quotes, to allow better presentation when displayed in the wiki as markdown.
An example content:
```
[pr_description]
generate_ai_title=true
```
PR-Agent will know to remove the triple-quotes when reading the configuration content.
## Local configuration file
By uploading a local `.pr_agent.toml` file to the root of the repo's main branch, you can edit and customize any configuration parameter. Note that you need to upload `.pr_agent.toml` prior to creating a PR, in order for the configuration to take effect.
For example, if you set in `.pr_agent.toml`:
```
[pr_reviewer]
extra_instructions="""\
- instruction a
- instruction b
...
"""
```
Then you can give a list of extra instructions to the `review` tool.
## Global configuration file 💎
If you create a repo called `pr-agent-settings` in your **organization**, it's configuration file `.pr_agent.toml` will be used as a global configuration file for any other repo that belongs to the same organization.
Parameters from a local `.pr_agent.toml` file, in a specific repo, will override the global configuration parameters.
For example, in the GitHub organization `Codium-ai`:
- The repo [`https://github.com/Codium-ai/pr-agent-settings`](https://github.com/Codium-ai/pr-agent-settings/blob/main/.pr_agent.toml) contains a `.pr_agent.toml` file that serves as a global configuration file for all the repos in the GitHub organization `Codium-ai`.
- The repo [`https://github.com/Codium-ai/pr-agent`](https://github.com/Codium-ai/pr-agent/blob/main/.pr_agent.toml) inherits the global configuration file from `pr-agent-settings`.

View File

@ -0,0 +1,23 @@
# Usage guide
This page provides a detailed guide on how to use PR-Agent. It includes information on how to adjust PR-Agent configurations, define which tools will run automatically, manage mail notifications, and other advanced configurations.
- [Introduction](./introduction.md)
- [Configuration Options](./configuration_options.md)
- [Usage and Automation](./automations_and_usage.md)
- [Local Repo (CLI)](./automations_and_usage.md#local-repo-cli)
- [Online Usage](./automations_and_usage.md#online-usage)
- [GitHub App](./automations_and_usage.md#github-app)
- [GitHub Action](./automations_and_usage.md#github-action)
- [GitLab Webhook](./automations_and_usage.md#gitlab-webhook)
- [BitBucket App](./automations_and_usage.md#bitbucket-app)
- [Azure DevOps Provider](./automations_and_usage.md#azure-devops-provider)
- [Managing Mail Notifications](./mail_notifications.md)
- [Additional Configurations Walkthrough](./additional_configurations.md)
- [Ignoring files from analysis](./additional_configurations.md#ignoring-files-from-analysis)
- [Extra instructions](./additional_configurations.md#extra-instructions)
- [Working with large PRs](./additional_configurations.md#working-with-large-prs)
- [Changing a model](./additional_configurations.md#changing-a-model)
- [Patch Extra Lines](./additional_configurations.md#patch-extra-lines)
- [Editing the prompts](./additional_configurations.md#editing-the-prompts)

View File

@ -0,0 +1,18 @@
After [installation](https://pr-agent-docs.codium.ai/installation/), there are three basic ways to invoke CodiumAI PR-Agent:
1. Locally running a CLI command
2. Online usage - by [commenting](https://github.com/Codium-ai/pr-agent/pull/229#issuecomment-1695021901) on a PR
3. Enabling PR-Agent tools to run automatically when a new PR is opened
Specifically, CLI commands can be issued by invoking a pre-built [docker image](https://pr-agent-docs.codium.ai/installation/locally/#using-docker-image), or by invoking a [locally cloned repo](https://pr-agent-docs.codium.ai/installation/locally/#run-from-source).
For online usage, you will need to setup either a [GitHub App](https://pr-agent-docs.codium.ai/installation/github/#run-as-a-github-app), or a [GitHub Action](https://pr-agent-docs.codium.ai/installation/github/#run-as-a-github-action).
GitHub App and GitHub Action also enable to run PR-Agent specific tool automatically when a new PR is opened.
**git provider**: The [git_provider](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L5) field in the configuration file determines the GIT provider that will be used by PR-Agent. Currently, the following providers are supported:
`
"github", "gitlab", "bitbucket", "azure", "codecommit", "local", "gerrit"
`

View File

@ -0,0 +1,18 @@
Unfortunately, it is not possible in GitHub to disable mail notifications from a specific user.
If you are subscribed to notifications for a repo with PR-Agent, we recommend turning off notifications for PR comments, to avoid lengthy emails:
![notifications](https://codium.ai/images/pr_agent/notifications.png){width=512}
As an alternative, you can filter in your mail provider the notifications specifically from the PR-Agent bot, [see how](https://www.quora.com/How-can-you-filter-emails-for-specific-people-in-Gmail#:~:text=On%20the%20Filters%20and%20Blocked,the%20body%20of%20the%20email).
![filter_mail_notifications](https://codium.ai/images/pr_agent/filter_mail_notifications.png){width=512}
Another option to reduce the mail overload, yet still receive notifications on PR-Agent tools, is to disable the help collapsible section in PR-Agent bot comments.
This can done by setting `enable_help_text=false` for the relevant tool in the configuration file.
For example, to disable the help text for the `pr_reviewer` tool, set:
```
[pr_reviewer]
enable_help_text = false
```

139
docs/mkdocs.yml Normal file
View File

@ -0,0 +1,139 @@
site_name: PR-Agent Documentation
repo_url: https://github.com/Codium-ai/pr-agent
repo_name: Codium-ai/pr-agent
nav:
- Overview:
- 'index.md'
- 💎 PR-Agent Pro: 'overview/pr_agent_pro.md'
- Data Privacy: 'overview/data_privacy.md'
- Installation:
- 'installation/index.md'
- Locally: 'installation/locally.md'
- GitHub: 'installation/github.md'
- GitLab: 'installation/gitlab.md'
- BitBucket: 'installation/bitbucket.md'
- Azure DevOps: 'installation/azure.md'
- 💎 PR-Agent Pro: 'installation/pr_agent_pro.md'
- Usage Guide:
- 'usage-guide/index.md'
- Introduction: 'usage-guide/introduction.md'
- Configuration Options: 'usage-guide/configuration_options.md'
- Managing Mail Notifications: 'usage-guide/mail_notifications.md'
- Usage and Automation: 'usage-guide/automations_and_usage.md'
- Additional Configurations: 'usage-guide/additional_configurations.md'
- Tools:
- 'tools/index.md'
- Describe: 'tools/describe.md'
- Review: 'tools/review.md'
- Improve: 'tools/improve.md'
- Ask: 'tools/ask.md'
- Update Changelog: 'tools/update_changelog.md'
- Similar Issues: 'tools/similar_issues.md'
- Help: 'tools/help.md'
- 💎 Analyze: 'tools/analyze.md'
- 💎 Test: 'tools/test.md'
- 💎 Improve Component: 'tools/improve_component.md'
- 💎 Documentation: 'tools/documentation.md'
- 💎 Custom Labels: 'tools/custom_labels.md'
- 💎 Custom Prompt: 'tools/custom_prompt.md'
- 💎 CI Feedback: 'tools/ci_feedback.md'
- 💎 Similar Code: 'tools/similar_code.md'
- Core Abilities: 'core-abilities/index.md'
- Chrome Extension: 'chrome-extension/index.md'
- Code Fine-tuning Benchmark: 'finetuning_benchmark/index.md'
theme:
logo: assets/logo.svg
favicon: assets/favicon.ico
name: material
icon:
repo: fontawesome/brands/github
features:
- navigation.tabs
- navigation.expand
- navigation.path
- navigation.top
- navigation.tracking
- navigation.indexes
- search.suggest
- search.highlight
- content.tabs.link
- content.code.annotation
- content.code.copy
- content.tabs.link
language: en
custom_dir: overrides
palette:
- media: "(prefers-color-scheme)"
toggle:
icon: material/brightness-auto
name: Switch to light mode
- media: "(prefers-color-scheme: light)"
scheme: default
toggle:
icon: material/toggle-switch-off-outline
name: Switch to dark mode
primary: custom
accent: custom
- media: "(prefers-color-scheme: dark)"
scheme: slate
toggle:
icon: material/toggle-switch
name: Switch to light mode
primary: custom
accent: custom
plugins:
- social
- search
- glightbox
extra:
generator: false
social:
- icon: fontawesome/brands/github
link: https://github.com/Codium-ai
- icon: fontawesome/brands/discord
link: https://discord.com/invite/SgSxuQ65GF
- icon: fontawesome/brands/youtube
link: https://www.youtube.com/@Codium-AI
- icon: fontawesome/brands/linkedin
link: https://www.linkedin.com/company/codiumai
- icon: fontawesome/brands/twitter
link: https://twitter.com/CodiumAI
- icon: fontawesome/brands/instagram
link: https://www.instagram.com/codiumai/
analytics:
provider: custom
property: ${{ secrets.GOOGLE_ANALYTICS_ID }}
extra_css:
- css/custom.css
markdown_extensions:
- pymdownx.highlight:
anchor_linenums: true
- pymdownx.inlinehilite
- pymdownx.snippets
- admonition
- pymdownx.arithmatex:
generic: true
- footnotes
- pymdownx.details
- pymdownx.superfences
- pymdownx.mark
- md_in_html
- attr_list
- pymdownx.emoji:
emoji_index: !!python/name:material.extensions.emoji.twemoji
emoji_generator: !!python/name:material.extensions.emoji.to_svg
- toc:
title: On this page
toc_depth: 2
permalink: true
copyright: |
&copy; 2024 <a href="https://www.codium.ai/" target="_blank" rel="noopener">CodiumAI</a>

10
docs/overrides/main.html Normal file
View File

@ -0,0 +1,10 @@
{% extends "base.html" %}
{% block scripts %}
{{ super() }}
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5C9KZBM3"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
{% endblock %}

View File

@ -0,0 +1,115 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Footer</title>
<style>
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
font-size: 16px;
}
.wrapper {
background-color: #171518;
}
.container {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
color: white;
padding: 20px;
max-width: 61rem;
margin-left: auto;
margin-right: auto;
}
.footer-links, .social-icons {
padding: 0;
list-style-type: none;
display: flex;
justify-content: center;
gap: 20px;
align-items: center;
}
.footer-links a:hover, .social-icons a:hover {
color: #AEA1F1;
}
.social-icons svg {
width: 24px;
height: auto;
fill: white;
}
.footer-text {
width: 240px;
}
@media (max-width: 768px) {
.container {
flex-direction: column;
align-items: center;
text-align: center;
}
.footer-links, .social-icons, .footer-text {
width: 100%;
justify-content: center;
margin: 10px 0;
}
.footer-links {
order: 1;
}
.social-icons {
order: 2;
}
.footer-text {
order: 3;
}
}
</style>
</head>
<body>
<footer class="wrapper">
<div class="container">
<p class="footer-text">© 2024 <a href="https://www.codium.ai/" target="_blank" rel="noopener">CodiumAI</a></p>
<div class="footer-links">
<a href="https://codiumate-docs.codium.ai/">Codiumate</a>
<p>|</p>
<a href="https://alpha-codium-docs.codium.ai/">AlphaCodium</a>
</div>
<div class="social-icons">
<a href="https://github.com/Codium-ai" target="_blank" rel="noopener" title="github.com" class="social-link">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 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="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"></path></svg>
</a>
<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>
</a>
<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>
</a>
<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>
</a>
<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>
</a>
<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>
</a>
</div>
</div>
</footer>
</body>
</html>

View File

@ -0,0 +1,7 @@
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-5C9KZBM3');</script>
<!-- End Google Tag Manager -->

Binary file not shown.

Before

Width:  |  Height:  |  Size: 534 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

View File

@ -1,18 +1,25 @@
import logging
import os
import shlex
import tempfile
from functools import partial
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.utils import update_settings_from_args
from pr_agent.config_loader import get_settings
from pr_agent.git_providers import get_git_provider
from pr_agent.git_providers.utils import apply_repo_settings
from pr_agent.log import get_logger
from pr_agent.tools.pr_add_docs import PRAddDocs
from pr_agent.tools.pr_code_suggestions import PRCodeSuggestions
from pr_agent.tools.pr_config import PRConfig
from pr_agent.tools.pr_description import PRDescription
from pr_agent.tools.pr_generate_labels import PRGenerateLabels
from pr_agent.tools.pr_help_message import PRHelpMessage
from pr_agent.tools.pr_information_from_user import PRInformationFromUser
from pr_agent.tools.pr_line_questions import PR_LineQuestions
from pr_agent.tools.pr_questions import PRQuestions
from pr_agent.tools.pr_reviewer import PRReviewer
from pr_agent.tools.pr_similar_issue import PRSimilarIssue
from pr_agent.tools.pr_update_changelog import PRUpdateChangelog
from pr_agent.tools.pr_config import PRConfig
command2class = {
"auto_review": PRReviewer,
@ -27,56 +34,66 @@ command2class = {
"improve_code": PRCodeSuggestions,
"ask": PRQuestions,
"ask_question": PRQuestions,
"ask_line": PR_LineQuestions,
"update_changelog": PRUpdateChangelog,
"config": PRConfig,
"settings": PRConfig,
"help": PRHelpMessage,
"similar_issue": PRSimilarIssue,
"add_docs": PRAddDocs,
"generate_labels": PRGenerateLabels,
}
commands = list(command2class.keys())
class PRAgent:
def __init__(self):
pass
def __init__(self, ai_handler: partial[BaseAiHandler,] = LiteLLMAIHandler):
self.ai_handler = ai_handler # will be initialized in run_action
self.forbidden_cli_args = ['enable_auto_approval']
async def handle_request(self, pr_url, request, notify=None) -> bool:
# First, apply repo specific settings if exists
if get_settings().config.use_repo_settings_file:
repo_settings_file = None
try:
git_provider = get_git_provider()(pr_url)
repo_settings = git_provider.get_repo_settings()
if repo_settings:
repo_settings_file = None
fd, repo_settings_file = tempfile.mkstemp(suffix='.toml')
os.write(fd, repo_settings)
get_settings().load_file(repo_settings_file)
finally:
if repo_settings_file:
try:
os.remove(repo_settings_file)
except Exception as e:
logging.error(f"Failed to remove temporary settings file {repo_settings_file}", e)
apply_repo_settings(pr_url)
# Then, apply user specific settings if exists
request = request.replace("'", "\\'")
lexer = shlex.shlex(request, posix=True)
lexer.whitespace_split = True
action, *args = list(lexer)
if isinstance(request, str):
request = request.replace("'", "\\'")
lexer = shlex.shlex(request, posix=True)
lexer.whitespace_split = True
action, *args = list(lexer)
else:
action, *args = request
if args:
for forbidden_arg in self.forbidden_cli_args:
for arg in args:
if forbidden_arg in arg:
get_logger().error(
f"CLI argument for param '{forbidden_arg}' is forbidden. Use instead a configuration file."
)
return False
args = update_settings_from_args(args)
action = action.lstrip("/").lower()
if action == "reflect_and_review" and not get_settings().pr_reviewer.ask_and_reflect:
action = "review"
if action == "answer":
if notify:
notify()
await PRReviewer(pr_url, is_answer=True, args=args).run()
elif action == "auto_review":
await PRReviewer(pr_url, is_auto=True, args=args).run()
elif action in command2class:
if notify:
notify()
await command2class[action](pr_url, args=args).run()
else:
if action not in command2class:
get_logger().debug(f"Unknown command: {action}")
return False
return True
with get_logger().contextualize(command=action):
get_logger().info("PR-Agent request handler started", analytics=True)
if action == "reflect_and_review":
get_settings().pr_reviewer.ask_and_reflect = True
if action == "answer":
if notify:
notify()
await PRReviewer(pr_url, is_answer=True, args=args, ai_handler=self.ai_handler).run()
elif action == "auto_review":
await PRReviewer(pr_url, is_auto=True, args=args, ai_handler=self.ai_handler).run()
elif action in command2class:
if notify:
notify()
await command2class[action](pr_url, ai_handler=self.ai_handler, args=args).run()
else:
return False
return True

View File

@ -1,14 +1,47 @@
MAX_TOKENS = {
'gpt-3.5-turbo': 4000,
'text-embedding-ada-002': 8000,
'gpt-3.5-turbo': 16000,
'gpt-3.5-turbo-0125': 16000,
'gpt-3.5-turbo-0613': 4000,
'gpt-3.5-turbo-0301': 4000,
'gpt-3.5-turbo-1106': 16000,
'gpt-3.5-turbo-16k': 16000,
'gpt-3.5-turbo-16k-0613': 16000,
'gpt-4': 8000,
'gpt-4-0613': 8000,
'gpt-4-32k': 32000,
'gpt-4-1106-preview': 128000, # 128K, but may be limited by config.max_model_tokens
'gpt-4-0125-preview': 128000, # 128K, but may be limited by config.max_model_tokens
'gpt-4o': 128000, # 128K, but may be limited by config.max_model_tokens
'gpt-4o-2024-05-13': 128000, # 128K, but may be limited by config.max_model_tokens
'gpt-4-turbo-preview': 128000, # 128K, but may be limited by config.max_model_tokens
'gpt-4-turbo-2024-04-09': 128000, # 128K, but may be limited by config.max_model_tokens
'gpt-4-turbo': 128000, # 128K, but may be limited by config.max_model_tokens
'claude-instant-1': 100000,
'claude-2': 100000,
'command-nightly': 4096,
'replicate/llama-2-70b-chat:2c1608e18606fad2812020dc541930f2d0495ce32eee50074220b87300bc16e1': 4096,
'meta-llama/Llama-2-7b-chat-hf': 4096,
'vertex_ai/codechat-bison': 6144,
'vertex_ai/codechat-bison-32k': 32000,
'vertex_ai/claude-3-haiku@20240307': 100000,
'vertex_ai/claude-3-sonnet@20240229': 100000,
'vertex_ai/claude-3-opus@20240229': 100000,
'vertex_ai/claude-3-5-sonnet@20240620': 100000,
'vertex_ai/gemini-1.5-pro': 1048576,
'codechat-bison': 6144,
'codechat-bison-32k': 32000,
'anthropic.claude-instant-v1': 100000,
'anthropic.claude-v1': 100000,
'anthropic.claude-v2': 100000,
'anthropic/claude-3-opus-20240229': 100000,
'anthropic/claude-3-5-sonnet-20240620': 100000,
'bedrock/anthropic.claude-instant-v1': 100000,
'bedrock/anthropic.claude-v2': 100000,
'bedrock/anthropic.claude-v2:1': 100000,
'bedrock/anthropic.claude-3-sonnet-20240229-v1:0': 100000,
'bedrock/anthropic.claude-3-haiku-20240307-v1:0': 100000,
'bedrock/anthropic.claude-3-5-sonnet-20240620-v1:0': 100000,
'groq/llama3-8b-8192': 8192,
'groq/llama3-70b-8192': 8192,
'ollama/llama3': 4096,
}

View File

@ -1,115 +0,0 @@
import logging
import litellm
import openai
from litellm import acompletion
from openai.error import APIError, RateLimitError, Timeout, TryAgain
from retry import retry
from pr_agent.config_loader import get_settings
OPENAI_RETRIES = 5
class AiHandler:
"""
This class handles interactions with the OpenAI API for chat completions.
It initializes the API key and other settings from a configuration file,
and provides a method for performing chat completions using the OpenAI ChatCompletion API.
"""
def __init__(self):
"""
Initializes the OpenAI API key and other settings from a configuration file.
Raises a ValueError if the OpenAI key is missing.
"""
try:
openai.api_key = get_settings().openai.key
litellm.openai_key = get_settings().openai.key
litellm.debugger = get_settings().config.litellm_debugger
self.azure = False
if get_settings().get("OPENAI.ORG", None):
litellm.organization = get_settings().openai.org
if get_settings().get("OPENAI.API_TYPE", None):
if get_settings().openai.api_type == "azure":
self.azure = True
litellm.azure_key = get_settings().openai.key
if get_settings().get("OPENAI.API_VERSION", None):
litellm.api_version = get_settings().openai.api_version
if get_settings().get("OPENAI.API_BASE", None):
litellm.api_base = get_settings().openai.api_base
if get_settings().get("ANTHROPIC.KEY", None):
litellm.anthropic_key = get_settings().anthropic.key
if get_settings().get("COHERE.KEY", None):
litellm.cohere_key = get_settings().cohere.key
if get_settings().get("REPLICATE.KEY", None):
litellm.replicate_key = get_settings().replicate.key
if get_settings().get("REPLICATE.KEY", None):
litellm.replicate_key = get_settings().replicate.key
if get_settings().get("HUGGINGFACE.KEY", None):
litellm.huggingface_key = get_settings().huggingface.key
except AttributeError as e:
raise ValueError("OpenAI key is required") from e
@property
def deployment_id(self):
"""
Returns the deployment ID for the OpenAI API.
"""
return get_settings().get("OPENAI.DEPLOYMENT_ID", None)
@retry(exceptions=(APIError, Timeout, TryAgain, AttributeError, RateLimitError),
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):
"""
Performs a chat completion using the OpenAI ChatCompletion API.
Retries in case of API errors or timeouts.
Args:
model (str): The model to use for chat completion.
temperature (float): The temperature parameter for chat completion.
system (str): The system message for chat completion.
user (str): The user message for chat completion.
Returns:
tuple: A tuple containing the response and finish reason from the API.
Raises:
TryAgain: If the API response is empty or there are no choices in the response.
APIError: If there is an error during OpenAI inference.
Timeout: If there is a timeout during OpenAI inference.
TryAgain: If there is an attribute error during OpenAI inference.
"""
try:
deployment_id = self.deployment_id
if get_settings().config.verbosity_level >= 2:
logging.debug(
f"Generating completion with {model}"
f"{(' from deployment ' + deployment_id) if deployment_id else ''}"
)
response = await acompletion(
model=model,
deployment_id=deployment_id,
messages=[
{"role": "system", "content": system},
{"role": "user", "content": user}
],
temperature=temperature,
azure=self.azure,
force_timeout=get_settings().config.ai_timeout
)
except (APIError, Timeout, TryAgain) as e:
logging.error("Error during OpenAI inference: ", e)
raise
except (RateLimitError) as e:
logging.error("Rate limit error during OpenAI inference: ", e)
raise
except (Exception) as e:
logging.error("Unknown error during OpenAI inference: ", e)
raise TryAgain from e
if response is None or len(response["choices"]) == 0:
raise TryAgain
resp = response["choices"][0]['message']['content']
finish_reason = response["choices"][0]["finish_reason"]
print(resp, finish_reason)
return resp, finish_reason

View File

@ -0,0 +1,28 @@
from abc import ABC, abstractmethod
class BaseAiHandler(ABC):
"""
This class defines the interface for an AI handler to be used by the PR Agents.
"""
@abstractmethod
def __init__(self):
pass
@property
@abstractmethod
def deployment_id(self):
pass
@abstractmethod
async def chat_completion(self, model: str, system: str, user: str, temperature: float = 0.2, img_path: str = None):
"""
This method should be implemented to return a chat completion from the AI model.
Args:
model (str): the name of the model to use for the chat completion
system (str): the system message string to use for the chat completion
user (str): the user message string to use for the chat completion
temperature (float): the temperature to use for the chat completion
"""
pass

View File

@ -0,0 +1,73 @@
try:
from langchain_openai import ChatOpenAI, AzureChatOpenAI
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
pass
from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler
from pr_agent.config_loader import get_settings
from pr_agent.log import get_logger
from openai import APIError, RateLimitError, Timeout
from retry import retry
import functools
OPENAI_RETRIES = 5
class LangChainOpenAIHandler(BaseAiHandler):
def __init__(self):
# Initialize OpenAIHandler specific attributes here
super().__init__()
self.azure = get_settings().get("OPENAI.API_TYPE", "").lower() == "azure"
try:
if self.azure:
# using a partial function so we can set the deployment_id later to support fallback_deployments
# but still need to access the other settings now so we can raise a proper exception if they're missing
self._chat = functools.partial(
lambda **kwargs: AzureChatOpenAI(**kwargs),
openai_api_key=get_settings().openai.key,
openai_api_base=get_settings().openai.api_base,
openai_api_version=get_settings().openai.api_version,
)
else:
# for llms that compatible with openai, should use custom api base
openai_api_base = get_settings().get("OPENAI.API_BASE", None)
if openai_api_base is None or len(openai_api_base) == 0:
self._chat = ChatOpenAI(openai_api_key=get_settings().openai.key)
else:
self._chat = ChatOpenAI(openai_api_key=get_settings().openai.key, openai_api_base=openai_api_base)
except AttributeError as e:
if getattr(e, "name"):
raise ValueError(f"OpenAI {e.name} is required") from e
else:
raise e
def chat(self, messages: list, model: str, temperature: float):
if self.azure:
# we must set the deployment_id only here (instead of the __init__ method) to support fallback_deployments
return self._chat.invoke(input = messages, model=model, temperature=temperature, deployment_name=self.deployment_id)
else:
return self._chat.invoke(input = messages, model=model, temperature=temperature)
@property
def deployment_id(self):
"""
Returns the deployment ID for the OpenAI API.
"""
return get_settings().get("OPENAI.DEPLOYMENT_ID", None)
@retry(exceptions=(APIError, Timeout, AttributeError, RateLimitError),
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):
try:
messages = [SystemMessage(content=system), HumanMessage(content=user)]
# get a chat completion from the formatted messages
resp = self.chat(messages, model=model, temperature=temperature)
finish_reason = "completed"
return resp.content, finish_reason
except (Exception) as e:
get_logger().error("Unknown error during OpenAI inference: ", e)
raise e

View File

@ -0,0 +1,166 @@
import os
import requests
import boto3
import litellm
import openai
from litellm import acompletion
from tenacity import retry, retry_if_exception_type, stop_after_attempt
from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler
from pr_agent.config_loader import get_settings
from pr_agent.log import get_logger
OPENAI_RETRIES = 5
class LiteLLMAIHandler(BaseAiHandler):
"""
This class handles interactions with the OpenAI API for chat completions.
It initializes the API key and other settings from a configuration file,
and provides a method for performing chat completions using the OpenAI ChatCompletion API.
"""
def __init__(self):
"""
Initializes the OpenAI API key and other settings from a configuration file.
Raises a ValueError if the OpenAI key is missing.
"""
self.azure = False
self.api_base = None
self.repetition_penalty = None
if get_settings().get("OPENAI.KEY", None):
openai.api_key = get_settings().openai.key
litellm.openai_key = get_settings().openai.key
elif 'OPENAI_API_KEY' not in os.environ:
litellm.api_key = "dummy_key"
if get_settings().get("aws.AWS_ACCESS_KEY_ID"):
assert get_settings().aws.AWS_SECRET_ACCESS_KEY and get_settings().aws.AWS_REGION_NAME, "AWS credentials are incomplete"
os.environ["AWS_ACCESS_KEY_ID"] = get_settings().aws.AWS_ACCESS_KEY_ID
os.environ["AWS_SECRET_ACCESS_KEY"] = get_settings().aws.AWS_SECRET_ACCESS_KEY
os.environ["AWS_REGION_NAME"] = get_settings().aws.AWS_REGION_NAME
if get_settings().get("litellm.use_client"):
litellm_token = get_settings().get("litellm.LITELLM_TOKEN")
assert litellm_token, "LITELLM_TOKEN is required"
os.environ["LITELLM_TOKEN"] = litellm_token
litellm.use_client = True
if get_settings().get("LITELLM.DROP_PARAMS", None):
litellm.drop_params = get_settings().litellm.drop_params
if get_settings().get("OPENAI.ORG", None):
litellm.organization = get_settings().openai.org
if get_settings().get("OPENAI.API_TYPE", None):
if get_settings().openai.api_type == "azure":
self.azure = True
litellm.azure_key = get_settings().openai.key
if get_settings().get("OPENAI.API_VERSION", None):
litellm.api_version = get_settings().openai.api_version
if get_settings().get("OPENAI.API_BASE", None):
litellm.api_base = get_settings().openai.api_base
if get_settings().get("ANTHROPIC.KEY", None):
litellm.anthropic_key = get_settings().anthropic.key
if get_settings().get("COHERE.KEY", None):
litellm.cohere_key = get_settings().cohere.key
if get_settings().get("GROQ.KEY", None):
litellm.api_key = get_settings().groq.key
if get_settings().get("REPLICATE.KEY", None):
litellm.replicate_key = get_settings().replicate.key
if get_settings().get("HUGGINGFACE.KEY", None):
litellm.huggingface_key = get_settings().huggingface.key
if get_settings().get("HUGGINGFACE.API_BASE", None) and 'huggingface' in get_settings().config.model:
litellm.api_base = get_settings().huggingface.api_base
self.api_base = get_settings().huggingface.api_base
if get_settings().get("OLLAMA.API_BASE", None):
litellm.api_base = get_settings().ollama.api_base
self.api_base = get_settings().ollama.api_base
if get_settings().get("HUGGINGFACE.REPETITION_PENALTY", None):
self.repetition_penalty = float(get_settings().huggingface.repetition_penalty)
if get_settings().get("VERTEXAI.VERTEX_PROJECT", None):
litellm.vertex_project = get_settings().vertexai.vertex_project
litellm.vertex_location = get_settings().get(
"VERTEXAI.VERTEX_LOCATION", None
)
def prepare_logs(self, response, system, user, resp, finish_reason):
response_log = response.dict().copy()
response_log['system'] = system
response_log['user'] = user
response_log['output'] = resp
response_log['finish_reason'] = finish_reason
if hasattr(self, 'main_pr_language'):
response_log['main_pr_language'] = self.main_pr_language
else:
response_log['main_pr_language'] = 'unknown'
return response_log
@property
def deployment_id(self):
"""
Returns the deployment ID for the OpenAI API.
"""
return get_settings().get("OPENAI.DEPLOYMENT_ID", None)
@retry(
retry=retry_if_exception_type((openai.APIError, openai.APIConnectionError, openai.APITimeoutError)), # No retry on RateLimitError
stop=stop_after_attempt(OPENAI_RETRIES)
)
async def chat_completion(self, model: str, system: str, user: str, temperature: float = 0.2, img_path: str = None):
try:
resp, finish_reason = None, None
deployment_id = self.deployment_id
if self.azure:
model = 'azure/' + model
messages = [{"role": "system", "content": system}, {"role": "user", "content": user}]
if img_path:
try:
# check if the image link is alive
r = requests.head(img_path, allow_redirects=True)
if r.status_code == 404:
error_msg = f"The image link is not [alive](img_path).\nPlease repost the original image as a comment, and send the question again with 'quote reply' (see [instructions](https://pr-agent-docs.codium.ai/tools/ask/#ask-on-images-using-the-pr-code-as-context))."
get_logger().error(error_msg)
return f"{error_msg}", "error"
except Exception as e:
get_logger().error(f"Error fetching image: {img_path}", e)
return f"Error fetching image: {img_path}", "error"
messages[1]["content"] = [{"type": "text", "text": messages[1]["content"]},
{"type": "image_url", "image_url": {"url": img_path}}]
kwargs = {
"model": model,
"deployment_id": deployment_id,
"messages": messages,
"temperature": temperature,
"force_timeout": get_settings().config.ai_timeout,
"api_base": self.api_base,
}
if self.repetition_penalty:
kwargs["repetition_penalty"] = self.repetition_penalty
get_logger().debug("Prompts", artifact={"system": system, "user": user})
if get_settings().config.verbosity_level >= 2:
get_logger().info(f"\nSystem prompt:\n{system}")
get_logger().info(f"\nUser prompt:\n{user}")
response = await acompletion(**kwargs)
except (openai.APIError, openai.APITimeoutError) as e:
get_logger().error("Error during OpenAI inference: ", e)
raise
except (openai.RateLimitError) as e:
get_logger().error("Rate limit error during OpenAI inference: ", e)
raise
except (Exception) as e:
get_logger().error("Unknown error during OpenAI inference: ", e)
raise openai.APIError from e
if response is None or len(response["choices"]) == 0:
raise openai.APIError
else:
resp = response["choices"][0]['message']['content']
finish_reason = response["choices"][0]["finish_reason"]
get_logger().debug(f"\nAI response:\n{resp}")
# log the full response for debugging
response_log = self.prepare_logs(response, system, user, resp, finish_reason)
get_logger().debug("Full_response", artifact=response_log)
# for CLI debugging
if get_settings().config.verbosity_level >= 2:
get_logger().info(f"\nAI response:\n{resp}")
return resp, finish_reason

View File

@ -0,0 +1,68 @@
from pr_agent.algo.ai_handlers.base_ai_handler import BaseAiHandler
import openai
from openai.error import APIError, RateLimitError, Timeout, TryAgain
from retry import retry
from pr_agent.config_loader import get_settings
from pr_agent.log import get_logger
OPENAI_RETRIES = 5
class OpenAIHandler(BaseAiHandler):
def __init__(self):
# Initialize OpenAIHandler specific attributes here
try:
super().__init__()
openai.api_key = get_settings().openai.key
if get_settings().get("OPENAI.ORG", None):
openai.organization = get_settings().openai.org
if get_settings().get("OPENAI.API_TYPE", None):
if get_settings().openai.api_type == "azure":
self.azure = True
openai.azure_key = get_settings().openai.key
if get_settings().get("OPENAI.API_VERSION", None):
openai.api_version = get_settings().openai.api_version
if get_settings().get("OPENAI.API_BASE", None):
openai.api_base = get_settings().openai.api_base
except AttributeError as e:
raise ValueError("OpenAI key is required") from e
@property
def deployment_id(self):
"""
Returns the deployment ID for the OpenAI API.
"""
return get_settings().get("OPENAI.DEPLOYMENT_ID", None)
@retry(exceptions=(APIError, Timeout, TryAgain, AttributeError, RateLimitError),
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):
try:
deployment_id = self.deployment_id
get_logger().info("System: ", system)
get_logger().info("User: ", user)
messages = [{"role": "system", "content": system}, {"role": "user", "content": user}]
chat_completion = await openai.ChatCompletion.acreate(
model=model,
deployment_id=deployment_id,
messages=messages,
temperature=temperature,
)
resp = chat_completion["choices"][0]['message']['content']
finish_reason = chat_completion["choices"][0]["finish_reason"]
usage = chat_completion.get("usage")
get_logger().info("AI response", response=resp, messages=messages, finish_reason=finish_reason,
model=model, usage=usage)
return resp, finish_reason
except (APIError, Timeout, TryAgain) as e:
get_logger().error("Error during OpenAI inference: ", e)
raise
except (RateLimitError) as e:
get_logger().error("Rate limit error during OpenAI inference: ", e)
raise
except (Exception) as e:
get_logger().error("Unknown error during OpenAI inference: ", e)
raise TryAgain from e

View File

@ -0,0 +1,45 @@
import fnmatch
import re
from pr_agent.config_loader import get_settings
def filter_ignored(files, platform = 'github'):
"""
Filter out files that match the ignore patterns.
"""
try:
# load regex patterns, and translate glob patterns to regex
patterns = get_settings().ignore.regex
if isinstance(patterns, str):
patterns = [patterns]
glob_setting = get_settings().ignore.glob
if isinstance(glob_setting, str): # --ignore.glob=[.*utils.py], --ignore.glob=.*utils.py
glob_setting = glob_setting.strip('[]').split(",")
patterns += [fnmatch.translate(glob) for glob in glob_setting]
# compile all valid patterns
compiled_patterns = []
for r in patterns:
try:
compiled_patterns.append(re.compile(r))
except re.error:
pass
# keep filenames that _don't_ match the ignore regex
if files and isinstance(files, list):
for r in compiled_patterns:
if platform == 'github':
files = [f for f in files if (f.filename and not r.match(f.filename))]
elif platform == 'bitbucket':
files = [f for f in files if (f.new.path and not r.match(f.new.path))]
elif platform == 'gitlab':
files = [f for f in files if (f['new_path'] and not r.match(f['new_path']))]
elif platform == 'azure':
files = [f for f in files if not r.match(f)]
except Exception as e:
print(f"Could not filter file list: {e}")
return files

View File

@ -1,8 +1,10 @@
from __future__ import annotations
import logging
import re
from pr_agent.config_loader import get_settings
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
from pr_agent.log import get_logger
def extend_patch(original_file_str, patch_str, num_lines) -> str:
@ -21,7 +23,10 @@ def extend_patch(original_file_str, patch_str, num_lines) -> str:
return patch_str
if type(original_file_str) == bytes:
original_file_str = original_file_str.decode('utf-8')
try:
original_file_str = original_file_str.decode('utf-8')
except UnicodeDecodeError:
return ""
original_lines = original_file_str.splitlines()
patch_lines = patch_str.splitlines()
@ -40,12 +45,16 @@ def extend_patch(original_file_str, patch_str, num_lines) -> str:
extended_patch_lines.extend(
original_lines[start1 + size1 - 1:start1 + size1 - 1 + num_lines])
res = list(match.groups())
for i in range(len(res)):
if res[i] is None:
res[i] = 0
try:
start1, size1, start2, size2 = map(int, match.groups()[:4])
start1, size1, start2, size2 = map(int, res[:4])
except: # '@@ -0,0 +1 @@' case
start1, size1, size2 = map(int, match.groups()[:3])
start1, size1, size2 = map(int, res[:3])
start2 = 0
section_header = match.groups()[4]
section_header = res[4]
extended_start1 = max(1, start1 - num_lines)
extended_size1 = size1 + (start1 - extended_start1) + num_lines
extended_start2 = max(1, start2 - num_lines)
@ -59,7 +68,7 @@ def extend_patch(original_file_str, patch_str, num_lines) -> str:
extended_patch_lines.append(line)
except Exception as e:
if get_settings().config.verbosity_level >= 2:
logging.error(f"Failed to extend patch: {e}")
get_logger().error(f"Failed to extend patch: {e}")
return patch_str
# finish previous hunk
@ -110,7 +119,7 @@ def omit_deletion_hunks(patch_lines) -> str:
def handle_patch_deletions(patch: str, original_file_content_str: str,
new_file_content_str: str, file_name: str) -> str:
new_file_content_str: str, file_name: str, edit_type: EDIT_TYPE = EDIT_TYPE.UNKNOWN) -> str:
"""
Handle entire file or deletion patches.
@ -127,17 +136,17 @@ def handle_patch_deletions(patch: str, original_file_content_str: str,
str: The modified patch with deletion hunks omitted.
"""
if not new_file_content_str:
if not new_file_content_str and (edit_type == EDIT_TYPE.DELETED or edit_type == EDIT_TYPE.UNKNOWN):
# logic for handling deleted files - don't show patch, just show that the file was deleted
if get_settings().config.verbosity_level > 0:
logging.info(f"Processing file: {file_name}, minimizing deletion file")
get_logger().info(f"Processing file: {file_name}, minimizing deletion file")
patch = None # file was deleted
else:
patch_lines = patch.splitlines()
patch_new = omit_deletion_hunks(patch_lines)
if patch != patch_new:
if get_settings().config.verbosity_level > 0:
logging.info(f"Processing file: {file_name}, hunks were deleted")
get_logger().info(f"Processing file: {file_name}, hunks were deleted")
patch = patch_new
return patch
@ -175,7 +184,7 @@ __old hunk__
...
"""
patch_with_lines_str = f"\n\n## {file.filename}\n"
patch_with_lines_str = f"\n\n## file: '{file.filename.strip()}'\n"
patch_lines = patch.splitlines()
RE_HUNK_HEADER = re.compile(
r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@[ ]?(.*)")
@ -196,21 +205,26 @@ __old hunk__
if new_content_lines:
if prev_header_line:
patch_with_lines_str += f'\n{prev_header_line}\n'
patch_with_lines_str += '__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):
patch_with_lines_str += f"{start2 + i} {line_new}\n"
if old_content_lines:
patch_with_lines_str += '__old hunk__\n'
patch_with_lines_str = patch_with_lines_str.rstrip()+'\n__old hunk__\n'
for line_old in old_content_lines:
patch_with_lines_str += f"{line_old}\n"
new_content_lines = []
old_content_lines = []
if match:
prev_header_line = header_line
res = list(match.groups())
for i in range(len(res)):
if res[i] is None:
res[i] = 0
try:
start1, size1, start2, size2 = map(int, match.groups()[:4])
start1, size1, start2, size2 = map(int, res[:4])
except: # '@@ -0,0 +1 @@' case
start1, size1, size2 = map(int, match.groups()[:3])
start1, size1, size2 = map(int, res[:3])
start2 = 0
elif line.startswith('+'):
@ -225,12 +239,68 @@ __old hunk__
if match and new_content_lines:
if new_content_lines:
patch_with_lines_str += f'\n{header_line}\n'
patch_with_lines_str += '\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):
patch_with_lines_str += f"{start2 + i} {line_new}\n"
if old_content_lines:
patch_with_lines_str += '\n__old hunk__\n'
patch_with_lines_str = patch_with_lines_str.rstrip() + '\n__old hunk__\n'
for line_old in old_content_lines:
patch_with_lines_str += f"{line_old}\n"
return patch_with_lines_str.rstrip()
def extract_hunk_lines_from_patch(patch: str, file_name, line_start, line_end, side) -> tuple[str, str]:
patch_with_lines_str = f"\n\n## file: '{file_name.strip()}'\n\n"
selected_lines = ""
patch_lines = patch.splitlines()
RE_HUNK_HEADER = re.compile(
r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@[ ]?(.*)")
match = None
start1, size1, start2, size2 = -1, -1, -1, -1
skip_hunk = False
selected_lines_num = 0
for line in patch_lines:
if 'no newline at end of file' in line.lower():
continue
if line.startswith('@@'):
skip_hunk = False
selected_lines_num = 0
header_line = line
match = RE_HUNK_HEADER.match(line)
res = list(match.groups())
for i in range(len(res)):
if res[i] is None:
res[i] = 0
try:
start1, size1, start2, size2 = map(int, res[:4])
except: # '@@ -0,0 +1 @@' case
start1, size1, size2 = map(int, res[:3])
start2 = 0
# check if line range is in this hunk
if side.lower() == 'left':
# check if line range is in this hunk
if not (start1 <= line_start <= start1 + size1):
skip_hunk = True
continue
elif side.lower() == 'right':
if not (start2 <= line_start <= start2 + size2):
skip_hunk = True
continue
patch_with_lines_str += f'\n{header_line}\n'
elif not skip_hunk:
if side.lower() == 'right' and line_start <= start2 + selected_lines_num <= line_end:
selected_lines += line + '\n'
if side.lower() == 'left' and start1 <= selected_lines_num + start1 <= line_end:
selected_lines += line + '\n'
patch_with_lines_str += line + '\n'
if not line.startswith('-'): # currently we don't support /ask line for deleted lines
selected_lines_num += 1
return patch_with_lines_str.rstrip(), selected_lines.rstrip()

View File

@ -3,20 +3,22 @@ from typing import Dict
from pr_agent.config_loader import get_settings
language_extension_map_org = get_settings().language_extension_map_org
language_extension_map = {k.lower(): v for k, v in language_extension_map_org.items()}
# Bad Extensions, source: https://github.com/EleutherAI/github-downloader/blob/345e7c4cbb9e0dc8a0615fd995a08bf9d73b3fe6/download_repo_text.py # noqa: E501
bad_extensions = get_settings().bad_extensions.default
if get_settings().config.use_extra_bad_extensions:
bad_extensions += get_settings().bad_extensions.extra
def filter_bad_extensions(files):
return [f for f in files if f.filename is not None and is_valid_file(f.filename)]
# Bad Extensions, source: https://github.com/EleutherAI/github-downloader/blob/345e7c4cbb9e0dc8a0615fd995a08bf9d73b3fe6/download_repo_text.py # noqa: E501
bad_extensions = get_settings().bad_extensions.default
if get_settings().config.use_extra_bad_extensions:
bad_extensions += get_settings().bad_extensions.extra
return [f for f in files if f.filename is not None and is_valid_file(f.filename, bad_extensions)]
def is_valid_file(filename):
def is_valid_file(filename, bad_extensions=None):
if not bad_extensions:
bad_extensions = get_settings().bad_extensions.default
if get_settings().config.use_extra_bad_extensions:
bad_extensions += get_settings().bad_extensions.extra
return filename.split('.')[-1] not in bad_extensions
@ -29,6 +31,8 @@ def sort_files_by_main_languages(languages: Dict, files: list):
# languages_sorted = sorted(languages, key=lambda x: x[1], reverse=True)
# get all extensions for the languages
main_extensions = []
language_extension_map_org = get_settings().language_extension_map_org
language_extension_map = {k.lower(): v for k, v in language_extension_map_org.items()}
for language in languages_sorted_list:
if language.lower() in language_extension_map:
main_extensions.append(language_extension_map[language.lower()])
@ -42,6 +46,11 @@ def sort_files_by_main_languages(languages: Dict, files: list):
files_sorted = []
rest_files = {}
# if no languages detected, put all files in the "Other" category
if not languages:
files_sorted = [({"language": "Other", "files": list(files_filtered)})]
return files_sorted
main_extensions_flat = []
for ext in main_extensions:
main_extensions_flat.extend(ext)

View File

@ -1,86 +1,180 @@
from __future__ import annotations
import difflib
import logging
import re
import traceback
from typing import Any, Callable, List, Tuple
from typing import Callable, List, Tuple
from github import RateLimitExceededException
from pr_agent.algo import MAX_TOKENS
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.token_handler import TokenHandler, get_token_encoder
from pr_agent.algo.file_filter import filter_ignored
from pr_agent.algo.token_handler import TokenHandler
from pr_agent.algo.utils import get_max_tokens, clip_tokens, ModelType
from pr_agent.config_loader import get_settings
from pr_agent.git_providers.git_provider import FilePatchInfo, 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
DELETED_FILES_ = "Deleted files:\n"
MORE_MODIFIED_FILES_ = "More modified files:\n"
MORE_MODIFIED_FILES_ = "Additional modified files (insufficient token budget to process):\n"
OUTPUT_BUFFER_TOKENS_SOFT_THRESHOLD = 1000
OUTPUT_BUFFER_TOKENS_HARD_THRESHOLD = 600
PATCH_EXTRA_LINES = 3
ADDED_FILES_ = "Additional added files (insufficient token budget to process):\n"
def get_pr_diff(git_provider: GitProvider, token_handler: TokenHandler, model: str,
add_line_numbers_to_hunks: bool = False, disable_extra_lines: bool = False) -> str:
"""
Returns a string with the diff of the pull request, applying diff minimization techniques if needed.
OUTPUT_BUFFER_TOKENS_SOFT_THRESHOLD = 1500
OUTPUT_BUFFER_TOKENS_HARD_THRESHOLD = 1000
Args:
git_provider (GitProvider): An object of the GitProvider class representing the Git provider used for the pull
request.
token_handler (TokenHandler): An object of the TokenHandler class used for handling tokens in the context of the
pull request.
model (str): The name of the model used for tokenization.
add_line_numbers_to_hunks (bool, optional): A boolean indicating whether to add line numbers to the hunks in the
diff. Defaults to False.
disable_extra_lines (bool, optional): A boolean indicating whether to disable the extension of each patch with
extra lines of context. Defaults to False.
Returns:
str: A string with the diff of the pull request, applying diff minimization techniques if needed.
"""
def get_pr_diff(git_provider: GitProvider, token_handler: TokenHandler,
model: str,
add_line_numbers_to_hunks: bool = False,
disable_extra_lines: bool = False,
large_pr_handling=False,
return_remaining_files=False):
if disable_extra_lines:
global PATCH_EXTRA_LINES
PATCH_EXTRA_LINES = 0
else:
PATCH_EXTRA_LINES = get_settings().config.patch_extra_lines
try:
diff_files = git_provider.get_diff_files()
diff_files_original = git_provider.get_diff_files()
except RateLimitExceededException as e:
logging.error(f"Rate limit exceeded for git provider API. original message {e}")
get_logger().error(f"Rate limit exceeded for git provider API. original message {e}")
raise
diff_files = filter_ignored(diff_files_original)
if diff_files != diff_files_original:
try:
get_logger().info(f"Filtered out {len(diff_files_original) - len(diff_files)} files")
new_names = set([a.filename for a in diff_files])
orig_names = set([a.filename for a in diff_files_original])
get_logger().info(f"Filtered out files: {orig_names - new_names}")
except Exception as e:
pass
# get pr languages
pr_languages = sort_files_by_main_languages(git_provider.get_languages(), diff_files)
if pr_languages:
try:
get_logger().info(f"PR main language: {pr_languages[0]['language']}")
except Exception as e:
pass
# generate a standard diff string, with patch extension
patches_extended, total_tokens, patches_extended_tokens = pr_generate_extended_diff(pr_languages, token_handler,
add_line_numbers_to_hunks)
patches_extended, total_tokens, patches_extended_tokens = pr_generate_extended_diff(
pr_languages, token_handler, add_line_numbers_to_hunks, patch_extra_lines=PATCH_EXTRA_LINES)
# if we are under the limit, return the full diff
if total_tokens + OUTPUT_BUFFER_TOKENS_SOFT_THRESHOLD < MAX_TOKENS[model]:
if total_tokens + OUTPUT_BUFFER_TOKENS_SOFT_THRESHOLD < get_max_tokens(model):
get_logger().info(f"Tokens: {total_tokens}, total tokens under limit: {get_max_tokens(model)}, "
f"returning full diff.")
return "\n".join(patches_extended)
# if we are over the limit, start pruning
patches_compressed, modified_file_names, deleted_file_names = \
pr_generate_compressed_diff(pr_languages, token_handler, model, add_line_numbers_to_hunks)
get_logger().info(f"Tokens: {total_tokens}, total tokens over limit: {get_max_tokens(model)}, "
f"pruning diff.")
patches_compressed_list, total_tokens_list, deleted_files_list, remaining_files_list, file_dict, files_in_patches_list = \
pr_generate_compressed_diff(pr_languages, token_handler, model, add_line_numbers_to_hunks, large_pr_handling)
if large_pr_handling and len(patches_compressed_list) > 1:
get_logger().info(f"Large PR handling mode, and found {len(patches_compressed_list)} patches with original diff.")
return "" # return empty string, as we generate multiple patches with a different prompt
# return the first patch
patches_compressed = patches_compressed_list[0]
total_tokens_new = total_tokens_list[0]
files_in_patch = files_in_patches_list[0]
# Insert additional information about added, modified, and deleted files if there is enough space
max_tokens = get_max_tokens(model) - OUTPUT_BUFFER_TOKENS_HARD_THRESHOLD
curr_token = total_tokens_new # == token_handler.count_tokens(final_diff)+token_handler.prompt_tokens
final_diff = "\n".join(patches_compressed)
if modified_file_names:
modified_list_str = MORE_MODIFIED_FILES_ + "\n".join(modified_file_names)
delta_tokens = 10
added_list_str = modified_list_str = deleted_list_str = ""
unprocessed_files = []
# generate the added, modified, and deleted files lists
if (max_tokens - curr_token) > delta_tokens:
for filename, file_values in file_dict.items():
if filename in files_in_patch:
continue
if file_values['edit_type'] == EDIT_TYPE.ADDED:
unprocessed_files.append(filename)
if not added_list_str:
added_list_str = ADDED_FILES_ + f"\n{filename}"
else:
added_list_str = added_list_str + f"\n{filename}"
elif file_values['edit_type'] == EDIT_TYPE.MODIFIED or EDIT_TYPE.RENAMED:
unprocessed_files.append(filename)
if not modified_list_str:
modified_list_str = MORE_MODIFIED_FILES_ + f"\n{filename}"
else:
modified_list_str = modified_list_str + f"\n{filename}"
elif file_values['edit_type'] == EDIT_TYPE.DELETED:
# unprocessed_files.append(filename) # not needed here, because the file was deleted, so no need to process it
if not deleted_list_str:
deleted_list_str = DELETED_FILES_ + f"\n{filename}"
else:
deleted_list_str = deleted_list_str + f"\n{filename}"
# prune the added, modified, and deleted files lists, and add them to the final diff
added_list_str = clip_tokens(added_list_str, max_tokens - curr_token)
if added_list_str:
final_diff = final_diff + "\n\n" + added_list_str
curr_token += token_handler.count_tokens(added_list_str) + 2
modified_list_str = clip_tokens(modified_list_str, max_tokens - curr_token)
if modified_list_str:
final_diff = final_diff + "\n\n" + modified_list_str
if deleted_file_names:
deleted_list_str = DELETED_FILES_ + "\n".join(deleted_file_names)
curr_token += token_handler.count_tokens(modified_list_str) + 2
deleted_list_str = clip_tokens(deleted_list_str, max_tokens - curr_token)
if deleted_list_str:
final_diff = final_diff + "\n\n" + deleted_list_str
return final_diff
get_logger().debug(f"After pruning, added_list_str: {added_list_str}, modified_list_str: {modified_list_str}, "
f"deleted_list_str: {deleted_list_str}")
if not return_remaining_files:
return final_diff
else:
return final_diff, remaining_files_list
def get_pr_diff_multiple_patchs(git_provider: GitProvider, token_handler: TokenHandler, model: str,
add_line_numbers_to_hunks: bool = False, disable_extra_lines: bool = False):
try:
diff_files_original = git_provider.get_diff_files()
except RateLimitExceededException as e:
get_logger().error(f"Rate limit exceeded for git provider API. original message {e}")
raise
diff_files = filter_ignored(diff_files_original)
if diff_files != diff_files_original:
try:
get_logger().info(f"Filtered out {len(diff_files_original) - len(diff_files)} files")
new_names = set([a.filename for a in diff_files])
orig_names = set([a.filename for a in diff_files_original])
get_logger().info(f"Filtered out files: {orig_names - new_names}")
except Exception as e:
pass
# get pr languages
pr_languages = sort_files_by_main_languages(git_provider.get_languages(), diff_files)
if pr_languages:
try:
get_logger().info(f"PR main language: {pr_languages[0]['language']}")
except Exception as e:
pass
patches_compressed_list, total_tokens_list, deleted_files_list, remaining_files_list, file_dict, files_in_patches_list = \
pr_generate_compressed_diff(pr_languages, token_handler, model, add_line_numbers_to_hunks, large_pr_handling=True)
return patches_compressed_list, total_tokens_list, deleted_files_list, remaining_files_list, file_dict, files_in_patches_list
def pr_generate_extended_diff(pr_languages: list,
token_handler: TokenHandler,
add_line_numbers_to_hunks: bool) -> Tuple[list, int, list]:
add_line_numbers_to_hunks: bool,
patch_extra_lines: int = 0) -> Tuple[list, int, list]:
"""
Generate a standard diff string with patch extension, while counting the number of tokens used and applying diff
minimization techniques if needed.
@ -102,7 +196,10 @@ def pr_generate_extended_diff(pr_languages: list,
continue
# extend each patch with extra lines of context
extended_patch = extend_patch(original_file_content_str, patch, num_lines=PATCH_EXTRA_LINES)
extended_patch = extend_patch(original_file_content_str, patch, num_lines=patch_extra_lines)
if not extended_patch:
get_logger().warning(f"Failed to extend patch for file: {file.filename}")
continue
full_extended_patch = f"\n\n## {file.filename}\n\n{extended_patch}\n"
if add_line_numbers_to_hunks:
@ -118,40 +215,17 @@ def pr_generate_extended_diff(pr_languages: list,
def pr_generate_compressed_diff(top_langs: list, token_handler: TokenHandler, model: str,
convert_hunks_to_line_numbers: bool) -> Tuple[list, list, list]:
"""
Generate a compressed diff string for a pull request, using diff minimization techniques to reduce the number of
tokens used.
Args:
top_langs (list): A list of dictionaries representing the languages used in the pull request and their
corresponding files.
token_handler (TokenHandler): An object of the TokenHandler class used for handling tokens in the context of the
pull request.
model (str): The model used for tokenization.
convert_hunks_to_line_numbers (bool): A boolean indicating whether to convert hunks to line numbers in the diff.
Returns:
Tuple[list, list, list]: A tuple containing the following lists:
- patches: A list of compressed diff patches for each file in the pull request.
- modified_files_list: A list of file names that were skipped due to large patch size.
- deleted_files_list: A list of file names that were deleted in the pull request.
Minimization techniques to reduce the number of tokens:
0. Start from the largest diff patch to smaller ones
1. Don't use extend context lines around diff
2. Minimize deleted files
3. Minimize deleted hunks
4. Minimize all remaining files when you reach token limit
"""
patches = []
modified_files_list = []
convert_hunks_to_line_numbers: bool,
large_pr_handling: bool) -> Tuple[list, list, list, list, dict, list]:
deleted_files_list = []
# sort each one of the languages in top_langs by the number of tokens in the diff
sorted_files = []
for lang in top_langs:
sorted_files.extend(sorted(lang['files'], key=lambda x: x.tokens, reverse=True))
total_tokens = token_handler.prompt_tokens
# generate patches for each file, and count tokens
file_dict = {}
for file in sorted_files:
original_file_content_str = file.base_file
new_file_content_str = file.head_file
@ -161,60 +235,105 @@ def pr_generate_compressed_diff(top_langs: list, token_handler: TokenHandler, mo
# removing delete-only hunks
patch = handle_patch_deletions(patch, original_file_content_str,
new_file_content_str, file.filename)
new_file_content_str, file.filename, file.edit_type)
if patch is None:
if not deleted_files_list:
total_tokens += token_handler.count_tokens(DELETED_FILES_)
deleted_files_list.append(file.filename)
total_tokens += token_handler.count_tokens(file.filename) + 1
if file.filename not in deleted_files_list:
deleted_files_list.append(file.filename)
continue
if convert_hunks_to_line_numbers:
patch = convert_to_hunks_with_lines_numbers(patch, file)
new_patch_tokens = token_handler.count_tokens(patch)
file_dict[file.filename] = {'patch': patch, 'tokens': new_patch_tokens, 'edit_type': file.edit_type}
max_tokens_model = get_max_tokens(model)
# first iteration
files_in_patches_list = []
remaining_files_list = [file.filename for file in sorted_files]
patches_list =[]
total_tokens_list = []
total_tokens, patches, remaining_files_list, files_in_patch_list = generate_full_patch(convert_hunks_to_line_numbers, file_dict,
max_tokens_model, remaining_files_list, token_handler)
patches_list.append(patches)
total_tokens_list.append(total_tokens)
files_in_patches_list.append(files_in_patch_list)
# additional iterations (if needed)
if large_pr_handling:
NUMBER_OF_ALLOWED_ITERATIONS = get_settings().pr_description.max_ai_calls - 1 # one more call is to summarize
for i in range(NUMBER_OF_ALLOWED_ITERATIONS-1):
if remaining_files_list:
total_tokens, patches, remaining_files_list, files_in_patch_list = generate_full_patch(convert_hunks_to_line_numbers,
file_dict,
max_tokens_model,
remaining_files_list, token_handler)
if patches:
patches_list.append(patches)
total_tokens_list.append(total_tokens)
files_in_patches_list.append(files_in_patch_list)
else:
break
return patches_list, total_tokens_list, deleted_files_list, remaining_files_list, file_dict, files_in_patches_list
def generate_full_patch(convert_hunks_to_line_numbers, file_dict, max_tokens_model,remaining_files_list_prev, token_handler):
total_tokens = token_handler.prompt_tokens # initial tokens
patches = []
remaining_files_list_new = []
files_in_patch_list = []
for filename, data in file_dict.items():
if filename not in remaining_files_list_prev:
continue
patch = data['patch']
new_patch_tokens = data['tokens']
edit_type = data['edit_type']
# Hard Stop, no more tokens
if total_tokens > MAX_TOKENS[model] - OUTPUT_BUFFER_TOKENS_HARD_THRESHOLD:
logging.warning(f"File was fully skipped, no more tokens: {file.filename}.")
if total_tokens > max_tokens_model - OUTPUT_BUFFER_TOKENS_HARD_THRESHOLD:
get_logger().warning(f"File was fully skipped, no more tokens: {filename}.")
continue
# If the patch is too large, just show the file name
if total_tokens + new_patch_tokens > MAX_TOKENS[model] - OUTPUT_BUFFER_TOKENS_SOFT_THRESHOLD:
if total_tokens + new_patch_tokens > max_tokens_model - OUTPUT_BUFFER_TOKENS_SOFT_THRESHOLD:
# Current logic is to skip the patch if it's too large
# TODO: Option for alternative logic to remove hunks from the patch to reduce the number of tokens
# until we meet the requirements
if get_settings().config.verbosity_level >= 2:
logging.warning(f"Patch too large, minimizing it, {file.filename}")
if not modified_files_list:
total_tokens += token_handler.count_tokens(MORE_MODIFIED_FILES_)
modified_files_list.append(file.filename)
total_tokens += token_handler.count_tokens(file.filename) + 1
get_logger().warning(f"Patch too large, skipping it, {filename}")
remaining_files_list_new.append(filename)
continue
if patch:
if not convert_hunks_to_line_numbers:
patch_final = f"## {file.filename}\n\n{patch}\n"
patch_final = f"\n\n## file: '{filename.strip()}\n\n{patch.strip()}\n'"
else:
patch_final = patch
patch_final = "\n\n" + patch.strip()
patches.append(patch_final)
total_tokens += token_handler.count_tokens(patch_final)
files_in_patch_list.append(filename)
if get_settings().config.verbosity_level >= 2:
logging.info(f"Tokens: {total_tokens}, last filename: {file.filename}")
return patches, modified_files_list, deleted_files_list
get_logger().info(f"Tokens: {total_tokens}, last filename: {filename}")
return total_tokens, patches, remaining_files_list_new, files_in_patch_list
async def retry_with_fallback_models(f: Callable):
all_models = _get_all_models()
async def retry_with_fallback_models(f: Callable, model_type: ModelType = ModelType.REGULAR):
all_models = _get_all_models(model_type)
all_deployments = _get_all_deployments(all_models)
# try each (model, deployment_id) pair until one is successful, otherwise raise exception
for i, (model, deployment_id) in enumerate(zip(all_models, all_deployments)):
try:
get_logger().debug(
f"Generating prediction with {model}"
f"{(' from deployment ' + deployment_id) if deployment_id else ''}"
)
get_settings().set("openai.deployment_id", deployment_id)
return await f(model)
except Exception as e:
logging.warning(
except:
get_logger().warning(
f"Failed to generate prediction with {model}"
f"{(' from deployment ' + deployment_id) if deployment_id else ''}: "
f"{traceback.format_exc()}"
@ -223,8 +342,11 @@ async def retry_with_fallback_models(f: Callable):
raise # Re-raise the last exception
def _get_all_models() -> List[str]:
model = get_settings().config.model
def _get_all_models(model_type: ModelType = ModelType.REGULAR) -> List[str]:
if model_type == ModelType.TURBO:
model = get_settings().config.model_turbo
else:
model = get_settings().config.model
fallback_models = get_settings().config.fallback_models
if not isinstance(fallback_models, list):
fallback_models = [m.strip() for m in fallback_models.split(",")]
@ -247,99 +369,6 @@ def _get_all_deployments(all_models: List[str]) -> List[str]:
return all_deployments
def find_line_number_of_relevant_line_in_file(diff_files: List[FilePatchInfo],
relevant_file: str,
relevant_line_in_file: str) -> Tuple[int, int]:
"""
Find the line number and absolute position of a relevant line in a file.
Args:
diff_files (List[FilePatchInfo]): A list of FilePatchInfo objects representing the patches of files.
relevant_file (str): The name of the file where the relevant line is located.
relevant_line_in_file (str): The content of the relevant line.
Returns:
Tuple[int, int]: A tuple containing the line number and absolute position of the relevant line in the file.
"""
position = -1
absolute_position = -1
re_hunk_header = re.compile(
r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@[ ]?(.*)")
for file in diff_files:
if file.filename.strip() == relevant_file:
patch = file.patch
patch_lines = patch.splitlines()
# try to find the line in the patch using difflib, with some margin of error
matches_difflib: list[str | Any] = difflib.get_close_matches(relevant_line_in_file,
patch_lines, n=3, cutoff=0.93)
if len(matches_difflib) == 1 and matches_difflib[0].startswith('+'):
relevant_line_in_file = matches_difflib[0]
delta = 0
start1, size1, start2, size2 = 0, 0, 0, 0
for i, line in enumerate(patch_lines):
if line.startswith('@@'):
delta = 0
match = re_hunk_header.match(line)
start1, size1, start2, size2 = map(int, match.groups()[:4])
elif not line.startswith('-'):
delta += 1
if relevant_line_in_file in line and line[0] != '-':
position = i
absolute_position = start2 + delta - 1
break
if position == -1 and relevant_line_in_file[0] == '+':
no_plus_line = relevant_line_in_file[1:].lstrip()
for i, line in enumerate(patch_lines):
if line.startswith('@@'):
delta = 0
match = re_hunk_header.match(line)
start1, size1, start2, size2 = map(int, match.groups()[:4])
elif not line.startswith('-'):
delta += 1
if no_plus_line in line and line[0] != '-':
# The model might add a '+' to the beginning of the relevant_line_in_file even if originally
# it's a context line
position = i
absolute_position = start2 + delta - 1
break
return position, absolute_position
def clip_tokens(text: str, max_tokens: int) -> str:
"""
Clip the number of tokens in a string to a maximum number of tokens.
Args:
text (str): The string to clip.
max_tokens (int): The maximum number of tokens allowed in the string.
Returns:
str: The clipped string.
"""
if not text:
return text
try:
encoder = get_token_encoder()
num_input_tokens = len(encoder.encode(text))
if num_input_tokens <= max_tokens:
return text
num_chars = len(text)
chars_per_token = num_chars / num_input_tokens
num_output_chars = int(chars_per_token * max_tokens)
clipped_text = text[:num_output_chars]
return clipped_text
except Exception as e:
logging.warning(f"Failed to clip tokens: {e}")
return text
def get_pr_multi_diffs(git_provider: GitProvider,
token_handler: TokenHandler,
model: str,
@ -347,25 +376,27 @@ def get_pr_multi_diffs(git_provider: GitProvider,
"""
Retrieves the diff files from a Git provider, sorts them by main language, and generates patches for each file.
The patches are split into multiple groups based on the maximum number of tokens allowed for the given model.
Args:
git_provider (GitProvider): An object that provides access to Git provider APIs.
token_handler (TokenHandler): An object that handles tokens in the context of a pull request.
model (str): The name of the model.
max_calls (int, optional): The maximum number of calls to retrieve diff files. Defaults to 5.
Returns:
List[str]: A list of final diff strings, split into multiple groups based on the maximum number of tokens allowed for the given model.
Raises:
RateLimitExceededException: If the rate limit for the Git provider API is exceeded.
"""
try:
diff_files = git_provider.get_diff_files()
except RateLimitExceededException as e:
logging.error(f"Rate limit exceeded for git provider API. original message {e}")
get_logger().error(f"Rate limit exceeded for git provider API. original message {e}")
raise
diff_files = filter_ignored(diff_files)
# Sort files by main language
pr_languages = sort_files_by_main_languages(git_provider.get_languages(), diff_files)
@ -374,6 +405,13 @@ def get_pr_multi_diffs(git_provider: GitProvider,
for lang in pr_languages:
sorted_files.extend(sorted(lang['files'], key=lambda x: x.tokens, reverse=True))
# try first a single run with standard diff string, with patch extension, and no deletions
patches_extended, total_tokens, patches_extended_tokens = pr_generate_extended_diff(
pr_languages, token_handler, add_line_numbers_to_hunks=True)
if total_tokens + OUTPUT_BUFFER_TOKENS_SOFT_THRESHOLD < get_max_tokens(model):
return ["\n".join(patches_extended)]
patches = []
final_diff_list = []
total_tokens = token_handler.prompt_tokens
@ -381,7 +419,7 @@ def get_pr_multi_diffs(git_provider: GitProvider,
for file in sorted_files:
if call_number > max_calls:
if get_settings().config.verbosity_level >= 2:
logging.info(f"Reached max calls ({max_calls})")
get_logger().info(f"Reached max calls ({max_calls})")
break
original_file_content_str = file.base_file
@ -391,26 +429,47 @@ def get_pr_multi_diffs(git_provider: GitProvider,
continue
# Remove delete-only hunks
patch = handle_patch_deletions(patch, original_file_content_str, new_file_content_str, file.filename)
patch = handle_patch_deletions(patch, original_file_content_str, new_file_content_str, file.filename, file.edit_type)
if patch is None:
continue
patch = convert_to_hunks_with_lines_numbers(patch, file)
new_patch_tokens = token_handler.count_tokens(patch)
if patch and (total_tokens + new_patch_tokens > MAX_TOKENS[model] - OUTPUT_BUFFER_TOKENS_SOFT_THRESHOLD):
if patch and (token_handler.prompt_tokens + new_patch_tokens) > get_max_tokens(
model) - OUTPUT_BUFFER_TOKENS_SOFT_THRESHOLD:
if get_settings().config.get('large_patch_policy', 'skip') == 'skip':
get_logger().warning(f"Patch too large, skipping: {file.filename}")
continue
elif get_settings().config.get('large_patch_policy') == 'clip':
delta_tokens = get_max_tokens(model) - OUTPUT_BUFFER_TOKENS_SOFT_THRESHOLD - token_handler.prompt_tokens
patch_clipped = clip_tokens(patch, delta_tokens, delete_last_line=True, num_input_tokens=new_patch_tokens)
new_patch_tokens = token_handler.count_tokens(patch_clipped)
if patch_clipped and (token_handler.prompt_tokens + new_patch_tokens) > get_max_tokens(
model) - OUTPUT_BUFFER_TOKENS_SOFT_THRESHOLD:
get_logger().warning(f"Patch too large, skipping: {file.filename}")
continue
else:
get_logger().info(f"Clipped large patch for file: {file.filename}")
patch = patch_clipped
else:
get_logger().warning(f"Patch too large, skipping: {file.filename}")
continue
if patch and (total_tokens + new_patch_tokens > get_max_tokens(model) - OUTPUT_BUFFER_TOKENS_SOFT_THRESHOLD):
final_diff = "\n".join(patches)
final_diff_list.append(final_diff)
patches = []
total_tokens = token_handler.prompt_tokens
call_number += 1
if get_settings().config.verbosity_level >= 2:
logging.info(f"Call number: {call_number}")
get_logger().info(f"Call number: {call_number}")
if patch:
patches.append(patch)
total_tokens += new_patch_tokens
if get_settings().config.verbosity_level >= 2:
logging.info(f"Tokens: {total_tokens}, last filename: {file.filename}")
get_logger().info(f"Tokens: {total_tokens}, last filename: {file.filename}")
# Add the last chunk
if patches:

View File

@ -1,12 +1,25 @@
from jinja2 import Environment, StrictUndefined
from tiktoken import encoding_for_model, get_encoding
from pr_agent.config_loader import get_settings
from threading import Lock
def get_token_encoder():
return encoding_for_model(get_settings().config.model) if "gpt" in get_settings().config.model else get_encoding(
"cl100k_base")
class TokenEncoder:
_encoder_instance = None
_model = None
_lock = Lock() # Create a lock object
@classmethod
def get_token_encoder(cls):
model = get_settings().config.model
if cls._encoder_instance is None or model != cls._model: # Check without acquiring the lock for performance
with cls._lock: # Lock acquisition to ensure thread safety
if cls._encoder_instance is None or model != cls._model:
cls._model = model
cls._encoder_instance = encoding_for_model(cls._model) if "gpt" in cls._model else get_encoding(
"cl100k_base")
return cls._encoder_instance
class TokenHandler:
"""
@ -21,7 +34,7 @@ class TokenHandler:
method.
"""
def __init__(self, pr, vars: dict, system, user):
def __init__(self, pr=None, vars: dict = {}, system="", user=""):
"""
Initializes the TokenHandler object.
@ -31,8 +44,9 @@ class TokenHandler:
- system: The system string.
- user: The user string.
"""
self.encoder = get_token_encoder()
self.prompt_tokens = self._get_system_user_tokens(pr, self.encoder, vars, system, user)
self.encoder = TokenEncoder.get_token_encoder()
if pr is not None:
self.prompt_tokens = self._get_system_user_tokens(pr, self.encoder, vars, system, user)
def _get_system_user_tokens(self, pr, encoder, vars: dict, system, user):
"""

23
pr_agent/algo/types.py Normal file
View File

@ -0,0 +1,23 @@
from dataclasses import dataclass
from enum import Enum
class EDIT_TYPE(Enum):
ADDED = 1
DELETED = 2
MODIFIED = 3
RENAMED = 4
UNKNOWN = 5
@dataclass
class FilePatchInfo:
base_file: str
head_file: str
patch: str
filename: str
tokens: int = -1
edit_type: EDIT_TYPE = EDIT_TYPE.UNKNOWN
old_filename: str = None
num_plus_lines: int = -1
num_minus_lines: int = -1

View File

@ -2,15 +2,31 @@ from __future__ import annotations
import difflib
import json
import logging
import os
import re
import textwrap
import time
from datetime import datetime
from typing import Any, List
from enum import Enum
from typing import Any, List, Tuple
import yaml
from starlette_context import context
from pr_agent.algo import MAX_TOKENS
from pr_agent.algo.token_handler import TokenEncoder
from pr_agent.config_loader import get_settings, global_settings
from pr_agent.algo.types import FilePatchInfo
from pr_agent.log import get_logger
class ModelType(str, Enum):
REGULAR = "regular"
TURBO = "turbo"
class PRReviewHeader(str, Enum):
REGULAR = "## PR Reviewer Guide"
INCREMENTAL = "## Incremental PR Reviewer Guide"
def get_setting(key: str) -> Any:
@ -20,80 +36,310 @@ def get_setting(key: str) -> Any:
except Exception:
return global_settings.get(key, None)
def convert_to_markdown(output_data: dict) -> str:
def emphasize_header(text: str, only_markdown=False) -> str:
try:
# Finding the position of the first occurrence of ": "
colon_position = text.find(": ")
# Splitting the string and wrapping the first part in <strong> tags
if colon_position != -1:
# Everything before the colon (inclusive) is wrapped in <strong> tags
if only_markdown:
transformed_string = f"**{text[:colon_position + 1]}**\n" + text[colon_position + 1:]
else:
transformed_string = "<strong>" + text[:colon_position + 1] + "</strong>" +'<br>' + text[colon_position + 1:]
else:
# If there's no ": ", return the original string
transformed_string = text
return transformed_string
except Exception as e:
get_logger().exception(f"Failed to emphasize header: {e}")
return text
def unique_strings(input_list: List[str]) -> List[str]:
if not input_list or not isinstance(input_list, list):
return input_list
seen = set()
unique_list = []
for item in input_list:
if item not in seen:
unique_list.append(item)
seen.add(item)
return unique_list
def convert_to_markdown_v2(output_data: dict, gfm_supported: bool = True, incremental_review=None) -> str:
"""
Convert a dictionary of data into markdown format.
Args:
output_data (dict): A dictionary containing data to be converted to markdown format.
Returns:
str: The markdown formatted text generated from the input dictionary.
"""
markdown_text = ""
"""
emojis = {
"Main theme": "🎯",
"PR summary": "📝",
"Type of PR": "📌",
"Can be split": "🔀",
"Possible issues": "",
"Key issues to review": "",
"Score": "🏅",
"Relevant tests added": "🧪",
"Unrelated changes": "⚠️",
"Relevant tests": "🧪",
"Focused PR": "",
"Relevant ticket": "🎫",
"Security concerns": "🔒",
"General suggestions": "💡",
"Insights from user's answers": "📝",
"Code feedback": "🤖",
"Estimated effort to review [1-5]": "⏱️",
}
markdown_text = ""
if not incremental_review:
markdown_text += f"{PRReviewHeader.REGULAR.value} 🔍\n\n"
else:
markdown_text += f"{PRReviewHeader.INCREMENTAL.value} 🔍\n\n"
markdown_text += f"⏮️ Review for commits since previous PR-Agent review {incremental_review}.\n\n"
if not output_data or not output_data.get('review', {}):
return ""
for key, value in output_data.items():
if value is None or value == '' or value == {}:
continue
if isinstance(value, dict):
markdown_text += f"## {key}\n\n"
markdown_text += convert_to_markdown(value)
elif isinstance(value, list):
emoji = emojis.get(key, "")
if key.lower() == 'code feedback':
markdown_text += f"\n\n- **<details><summary> { emoji } Code feedback:**</summary>\n\n"
if gfm_supported:
markdown_text += "<table>\n"
for key, value in output_data['review'].items():
if value is None or value == '' or value == {} or value == []:
if key.lower() != 'can_be_split':
continue
key_nice = key.replace('_', ' ').capitalize()
emoji = emojis.get(key_nice, "")
if 'Estimated effort to review' in key_nice:
key_nice = 'Estimated effort to review'
if value.isnumeric():
value_int = int(value)
else:
markdown_text += f"- {emoji} **{key}:**\n\n"
for item in value:
if isinstance(item, dict) and key.lower() == 'code feedback':
markdown_text += parse_code_suggestion(item)
elif item:
markdown_text += f" - {item}\n"
if key.lower() == 'code feedback':
markdown_text += "</details>\n\n"
elif value != 'n/a':
emoji = emojis.get(key, "")
markdown_text += f"- {emoji} **{key}:** {value}\n"
try:
value_int = int(value.split(',')[0])
except ValueError:
continue
blue_bars = '🔵' * value_int
white_bars = '' * (5 - value_int)
value = f"{value_int} {blue_bars}{white_bars}"
if gfm_supported:
markdown_text += f"<tr><td>"
markdown_text += f"{emoji}&nbsp;<strong>{key_nice}</strong>: {value}"
markdown_text += f"</td></tr>\n"
else:
markdown_text += f"### {emoji} {key_nice}: {value}\n\n"
elif 'relevant tests' in key_nice.lower():
value = value.strip().lower()
if gfm_supported:
markdown_text += f"<tr><td>"
if is_value_no(value):
markdown_text += f"{emoji}&nbsp;<strong>No relevant tests</strong>"
else:
markdown_text += f"{emoji}&nbsp;<strong>PR contains tests</strong>"
markdown_text += f"</td></tr>\n"
else:
if gfm_supported:
markdown_text += f"<tr><td>"
if is_value_no(value):
markdown_text += f"{emoji}&nbsp;<strong>No relevant tests</strong>"
else:
markdown_text += f"{emoji}&nbsp;<strong>PR contains tests</strong>"
else:
if is_value_no(value):
markdown_text += f'### {emoji} No relevant tests\n\n'
else:
markdown_text += f"### PR contains tests\n\n"
elif 'security concerns' in key_nice.lower():
if gfm_supported:
markdown_text += f"<tr><td>"
if is_value_no(value):
markdown_text += f"{emoji}&nbsp;<strong>No security concerns identified</strong>"
else:
markdown_text += f"{emoji}&nbsp;<strong>Security concerns</strong><br><br>\n\n"
value = emphasize_header(value.strip())
markdown_text += f"{value}"
markdown_text += f"</td></tr>\n"
else:
if is_value_no(value):
markdown_text += f'### {emoji} No security concerns identified\n\n'
else:
markdown_text += f"### {emoji} Security concerns\n\n"
value = emphasize_header(value.strip())
markdown_text += f"{value}\n\n"
elif 'can be split' in key_nice.lower():
if gfm_supported:
markdown_text += f"<tr><td>"
markdown_text += process_can_be_split(emoji, value)
markdown_text += f"</td></tr>\n"
elif 'key issues to review' in key_nice.lower():
value = value.strip()
if is_value_no(value):
if gfm_supported:
markdown_text += f"<tr><td>"
markdown_text += f"{emoji}&nbsp;<strong>No key issues to review</strong>"
markdown_text += f"</td></tr>\n"
else:
markdown_text += f"### {emoji} No key issues to review\n\n"
else:
issues = value.split('\n- ')
for i, _ in enumerate(issues):
issues[i] = issues[i].strip().strip('-').strip()
issues = unique_strings(issues) # remove duplicates
if gfm_supported:
markdown_text += f"<tr><td>"
markdown_text += f"{emoji}&nbsp;<strong>{key_nice}</strong><br><br>\n\n"
else:
markdown_text += f"### {emoji} Key issues to review:\n\n"
for i, issue in enumerate(issues):
if not issue:
continue
issue = emphasize_header(issue, only_markdown=True)
markdown_text += f"{issue}\n\n"
if gfm_supported:
markdown_text += f"</td></tr>\n"
else:
if gfm_supported:
markdown_text += f"<tr><td>"
markdown_text += f"{emoji}&nbsp;<strong>{key_nice}</strong>: {value}"
markdown_text += f"</td></tr>\n"
else:
markdown_text += f"### {emoji} {key_nice}: {value}\n\n"
if gfm_supported:
markdown_text += "</table>\n"
if 'code_feedback' in output_data:
if gfm_supported:
markdown_text += f"\n\n"
markdown_text += f"<details><summary> <strong>Code feedback:</strong></summary>\n\n"
markdown_text += "<hr>"
else:
markdown_text += f"\n\n### Code feedback:\n\n"
for i, value in enumerate(output_data['code_feedback']):
if value is None or value == '' or value == {} or value == []:
continue
markdown_text += parse_code_suggestion(value, i, gfm_supported)+"\n\n"
if markdown_text.endswith('<hr>'):
markdown_text= markdown_text[:-4]
if gfm_supported:
markdown_text += f"</details>"
return markdown_text
def parse_code_suggestion(code_suggestions: dict) -> str:
def process_can_be_split(emoji, value):
try:
# key_nice = "Can this PR be split?"
key_nice = "Multiple PR themes"
markdown_text = ""
if not value or isinstance(value, list) and len(value) == 1:
value = "No"
# markdown_text += f"<tr><td> {emoji}&nbsp;<strong>{key_nice}</strong></td><td>\n\n{value}\n\n</td></tr>\n"
# markdown_text += f"### {emoji} No multiple PR themes\n\n"
markdown_text += f"{emoji} <strong>No multiple PR themes</strong>\n\n"
else:
markdown_text += f"{emoji} <strong>{key_nice}</strong><br><br>\n\n"
for i, split in enumerate(value):
title = split.get('title', '')
relevant_files = split.get('relevant_files', [])
markdown_text += f"<details><summary>\nSub-PR theme: <b>{title}</b></summary>\n\n"
markdown_text += f"___\n\nRelevant files:\n\n"
for file in relevant_files:
markdown_text += f"- {file}\n"
markdown_text += f"___\n\n"
markdown_text += f"</details>\n\n"
# markdown_text += f"#### Sub-PR theme: {title}\n\n"
# markdown_text += f"Relevant files:\n\n"
# for file in relevant_files:
# markdown_text += f"- {file}\n"
# markdown_text += "\n"
# number_of_splits = len(value)
# markdown_text += f"<tr><td rowspan={number_of_splits}> {emoji}&nbsp;<strong>{key_nice}</strong></td>\n"
# for i, split in enumerate(value):
# title = split.get('title', '')
# relevant_files = split.get('relevant_files', [])
# if i == 0:
# markdown_text += f"<td><details><summary>\nSub-PR theme:<br><strong>{title}</strong></summary>\n\n"
# markdown_text += f"<hr>\n"
# markdown_text += f"Relevant files:\n"
# markdown_text += f"<ul>\n"
# for file in relevant_files:
# markdown_text += f"<li>{file}</li>\n"
# markdown_text += f"</ul>\n\n</details></td></tr>\n"
# else:
# markdown_text += f"<tr>\n<td><details><summary>\nSub-PR theme:<br><strong>{title}</strong></summary>\n\n"
# markdown_text += f"<hr>\n"
# markdown_text += f"Relevant files:\n"
# markdown_text += f"<ul>\n"
# for file in relevant_files:
# markdown_text += f"<li>{file}</li>\n"
# markdown_text += f"</ul>\n\n</details></td></tr>\n"
except Exception as e:
get_logger().exception(f"Failed to process can be split: {e}")
return ""
return markdown_text
def parse_code_suggestion(code_suggestion: dict, i: int = 0, gfm_supported: bool = True) -> str:
"""
Convert a dictionary of data into markdown format.
Args:
code_suggestions (dict): A dictionary containing data to be converted to markdown format.
code_suggestion (dict): A dictionary containing data to be converted to markdown format.
Returns:
str: A string containing the markdown formatted text generated from the input dictionary.
"""
markdown_text = ""
for sub_key, sub_value in code_suggestions.items():
if isinstance(sub_value, dict): # "code example"
markdown_text += f" - **{sub_key}:**\n"
for code_key, code_value in sub_value.items(): # 'before' and 'after' code
code_str = f"```\n{code_value}\n```"
code_str_indented = textwrap.indent(code_str, ' ')
markdown_text += f" - **{code_key}:**\n{code_str_indented}\n"
else:
if "relevant file" in sub_key.lower():
markdown_text += f"\n - **{sub_key}:** {sub_value}\n"
if gfm_supported and 'relevant_line' in code_suggestion:
markdown_text += '<table>'
for sub_key, sub_value in code_suggestion.items():
try:
if sub_key.lower() == 'relevant_file':
relevant_file = sub_value.strip('`').strip('"').strip("'")
markdown_text += f"<tr><td>relevant file</td><td>{relevant_file}</td></tr>"
# continue
elif sub_key.lower() == 'suggestion':
markdown_text += (f"<tr><td>{sub_key} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>"
f"<td>\n\n<strong>\n\n{sub_value.strip()}\n\n</strong>\n</td></tr>")
elif sub_key.lower() == 'relevant_line':
markdown_text += f"<tr><td>relevant line</td>"
sub_value_list = sub_value.split('](')
relevant_line = sub_value_list[0].lstrip('`').lstrip('[')
if len(sub_value_list) > 1:
link = sub_value_list[1].rstrip(')').strip('`')
markdown_text += f"<td><a href='{link}'>{relevant_line}</a></td>"
else:
markdown_text += f"<td>{relevant_line}</td>"
markdown_text += "</tr>"
except Exception as e:
get_logger().exception(f"Failed to parse code suggestion: {e}")
pass
markdown_text += '</table>'
markdown_text += "<hr>"
else:
for sub_key, sub_value in code_suggestion.items():
if isinstance(sub_key, str):
sub_key = sub_key.rstrip()
if isinstance(sub_value,str):
sub_value = sub_value.rstrip()
if isinstance(sub_value, dict): # "code example"
markdown_text += f" - **{sub_key}:**\n"
for code_key, code_value in sub_value.items(): # 'before' and 'after' code
code_str = f"```\n{code_value}\n```"
code_str_indented = textwrap.indent(code_str, ' ')
markdown_text += f" - **{code_key}:**\n{code_str_indented}\n"
else:
markdown_text += f" **{sub_key}:** {sub_value}\n"
if "relevant_file" in sub_key.lower():
markdown_text += f"\n - **{sub_key}:** {sub_value} \n"
else:
markdown_text += f" **{sub_key}:** {sub_value} \n"
if "relevant_line" not in sub_key.lower(): # nicer presentation
# markdown_text = markdown_text.rstrip('\n') + "\\\n" # works for gitlab
markdown_text = markdown_text.rstrip('\n') + " \n" # works for gitlab and bitbucker
markdown_text += "\n"
markdown_text += "\n"
return markdown_text
@ -149,7 +395,7 @@ def try_fix_json(review, max_iter=10, code_suggestions=False):
iter_count += 1
if not valid_json:
logging.error("Unable to decode JSON response from AI")
get_logger().error("Unable to decode JSON response from AI")
data = {}
return data
@ -168,7 +414,7 @@ def fix_json_escape_char(json_message=None):
Raises:
None
"""
"""
try:
result = json.loads(json_message)
except Exception as e:
@ -195,12 +441,12 @@ def convert_str_to_datetime(date_str):
Example:
>>> convert_str_to_datetime('Mon, 01 Jan 2022 12:00:00 UTC')
datetime.datetime(2022, 1, 1, 12, 0, 0)
"""
"""
datetime_format = '%a, %d %b %Y %H:%M:%S %Z'
return datetime.strptime(date_str, datetime_format)
def load_large_diff(filename, new_file_content_str: str, original_file_content_str: str) -> str:
def load_large_diff(filename, new_file_content_str: str, original_file_content_str: str, show_warning: bool = True) -> str:
"""
Generate a patch for a modified file by comparing the original content of the file with the new content provided as
input.
@ -219,8 +465,8 @@ def load_large_diff(filename, new_file_content_str: str, original_file_content_s
try:
diff = difflib.unified_diff(original_file_content_str.splitlines(keepends=True),
new_file_content_str.splitlines(keepends=True))
if get_settings().config.verbosity_level >= 2:
logging.warning(f"File was modified, but no patch was found. Manually creating patch: {filename}.")
if get_settings().config.verbosity_level >= 2 and show_warning:
get_logger().warning(f"File was modified, but no patch was found. Manually creating patch: {filename}.")
patch = ''.join(diff)
except Exception:
pass
@ -251,13 +497,13 @@ def update_settings_from_args(args: List[str]) -> List[str]:
arg = arg.strip('-').strip()
vals = arg.split('=', 1)
if len(vals) != 2:
if len(vals) > 2: # --extended is a valid argument
logging.error(f'Invalid argument format: {arg}')
if len(vals) > 2: # --extended is a valid argument
get_logger().error(f'Invalid argument format: {arg}')
other_args.append(arg)
continue
key, value = _fix_key_value(*vals)
get_settings().set(key, value)
logging.info(f'Updated setting {key} to: "{value}"')
get_logger().info(f'Updated setting {key} to: "{value}"')
else:
other_args.append(arg)
return other_args
@ -269,28 +515,372 @@ def _fix_key_value(key: str, value: str):
try:
value = yaml.safe_load(value)
except Exception as e:
logging.error(f"Failed to parse YAML for config override {key}={value}", exc_info=e)
get_logger().debug(f"Failed to parse YAML for config override {key}={value}", exc_info=e)
return key, value
def load_yaml(review_text: str) -> dict:
review_text = review_text.removeprefix('```yaml').rstrip('`')
def load_yaml(response_text: str, keys_fix_yaml: List[str] = [], first_key="", last_key="") -> dict:
response_text = response_text.removeprefix('```yaml').rstrip('`')
try:
data = yaml.safe_load(review_text)
data = yaml.safe_load(response_text)
except Exception as e:
logging.error(f"Failed to parse AI prediction: {e}")
data = try_fix_yaml(review_text)
get_logger().error(f"Failed 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)
return data
def try_fix_yaml(review_text: str) -> dict:
review_text_lines = review_text.split('\n')
data = {}
for i in range(1, len(review_text_lines)):
review_text_lines_tmp = '\n'.join(review_text_lines[:-i])
def try_fix_yaml(response_text: str,
keys_fix_yaml: List[str] = [],
first_key="",
last_key="",) -> dict:
response_text_lines = response_text.split('\n')
keys_yaml = ['relevant line:', 'suggestion content:', 'relevant file:', 'existing code:', 'improved code:']
keys_yaml = keys_yaml + keys_fix_yaml
# first fallback - try to convert 'relevant line: ...' to relevant line: |-\n ...'
response_text_lines_copy = response_text_lines.copy()
for i in range(0, len(response_text_lines_copy)):
for key in keys_yaml:
if key in response_text_lines_copy[i] and not '|-' in response_text_lines_copy[i]:
response_text_lines_copy[i] = response_text_lines_copy[i].replace(f'{key}',
f'{key} |-\n ')
try:
data = yaml.safe_load('\n'.join(response_text_lines_copy))
get_logger().info(f"Successfully parsed AI prediction after adding |-\n")
return data
except:
get_logger().info(f"Failed to parse AI prediction after adding |-\n")
# second fallback - try to extract only range from first ```yaml to ```
snippet_pattern = r'```(yaml)?[\s\S]*?```'
snippet = re.search(snippet_pattern, '\n'.join(response_text_lines_copy))
if snippet:
snippet_text = snippet.group()
try:
data = yaml.load(review_text_lines_tmp, Loader=yaml.SafeLoader)
logging.info(f"Successfully parsed AI prediction after removing {i} lines")
break
data = yaml.safe_load(snippet_text.removeprefix('```yaml').rstrip('`'))
get_logger().info(f"Successfully parsed AI prediction after extracting yaml snippet with second fallback")
return data
except:
pass
return data
# third fallback - try to remove leading and trailing curly brackets
response_text_copy = response_text.strip().rstrip().removeprefix('{').removesuffix('}').rstrip(':\n')
try:
data = yaml.safe_load(response_text_copy)
get_logger().info(f"Successfully parsed AI prediction after removing curly brackets")
return data
except:
pass
# forth fallback - try to extract yaml snippet by 'first_key' and 'last_key'
# note that 'last_key' can be in practice a key that is not the last key in the yaml snippet.
# it just needs to be some inner key, so we can look for newlines after it
if first_key and last_key:
index_start = response_text.find(f"\n{first_key}:")
if index_start == -1:
index_start = response_text.find(f"{first_key}:")
index_last_code = response_text.rfind(f"{last_key}:")
index_end = response_text.find("\n\n", index_last_code) # look for newlines after last_key
if index_end == -1:
index_end = len(response_text)
response_text_copy = response_text[index_start:index_end].strip().strip('```yaml').strip('`').strip()
try:
data = yaml.safe_load(response_text_copy)
get_logger().info(f"Successfully parsed AI prediction after extracting yaml snippet")
return data
except:
pass
# fifth fallback - try to remove last lines
data = {}
for i in range(1, len(response_text_lines)):
response_text_lines_tmp = '\n'.join(response_text_lines[:-i])
try:
data = yaml.safe_load(response_text_lines_tmp)
get_logger().info(f"Successfully parsed AI prediction after removing {i} lines")
return data
except:
pass
def set_custom_labels(variables, git_provider=None):
if not get_settings().config.enable_custom_labels:
return
labels = get_settings().get('custom_labels', {})
if not labels:
# set default labels
labels = ['Bug fix', 'Tests', 'Bug fix with tests', 'Enhancement', 'Documentation', 'Other']
labels_list = "\n - ".join(labels) if labels else ""
labels_list = f" - {labels_list}" if labels_list else ""
variables["custom_labels"] = labels_list
return
# Set custom labels
variables["custom_labels_class"] = "class Label(str, Enum):"
counter = 0
labels_minimal_to_labels_dict = {}
for k, v in labels.items():
description = "'" + v['description'].strip('\n').replace('\n', '\\n') + "'"
# variables["custom_labels_class"] += f"\n {k.lower().replace(' ', '_')} = '{k}' # {description}"
variables["custom_labels_class"] += f"\n {k.lower().replace(' ', '_')} = {description}"
labels_minimal_to_labels_dict[k.lower().replace(' ', '_')] = k
counter += 1
variables["labels_minimal_to_labels_dict"] = labels_minimal_to_labels_dict
def get_user_labels(current_labels: List[str] = None):
"""
Only keep labels that has been added by the user
"""
try:
if current_labels is None:
current_labels = []
user_labels = []
for label in current_labels:
if label.lower() in ['bug fix', 'tests', 'enhancement', 'documentation', 'other']:
continue
if get_settings().config.enable_custom_labels:
if label in get_settings().custom_labels:
continue
user_labels.append(label)
if user_labels:
get_logger().debug(f"Keeping user labels: {user_labels}")
except Exception as e:
get_logger().exception(f"Failed to get user labels: {e}")
return current_labels
return user_labels
def get_max_tokens(model):
settings = get_settings()
if model in MAX_TOKENS:
max_tokens_model = MAX_TOKENS[model]
else:
raise Exception(f"MAX_TOKENS must be set for model {model} in ./pr_agent/algo/__init__.py")
if settings.config.max_model_tokens:
max_tokens_model = min(settings.config.max_model_tokens, max_tokens_model)
# get_logger().debug(f"limiting max tokens to {max_tokens_model}")
return max_tokens_model
def clip_tokens(text: str, max_tokens: int, add_three_dots=True, num_input_tokens=None, delete_last_line=False) -> str:
"""
Clip the number of tokens in a string to a maximum number of tokens.
Args:
text (str): The string to clip.
max_tokens (int): The maximum number of tokens allowed in the string.
add_three_dots (bool, optional): A boolean indicating whether to add three dots at the end of the clipped
Returns:
str: The clipped string.
"""
if not text:
return text
try:
if num_input_tokens is None:
encoder = TokenEncoder.get_token_encoder()
num_input_tokens = len(encoder.encode(text))
if num_input_tokens <= max_tokens:
return text
if max_tokens < 0:
return ""
# calculate the number of characters to keep
num_chars = len(text)
chars_per_token = num_chars / num_input_tokens
factor = 0.9 # reduce by 10% to be safe
num_output_chars = int(factor * chars_per_token * max_tokens)
# clip the text
if num_output_chars > 0:
clipped_text = text[:num_output_chars]
if delete_last_line:
clipped_text = clipped_text.rsplit('\n', 1)[0]
if add_three_dots:
clipped_text += "\n...(truncated)"
else: # if the text is empty
clipped_text = ""
return clipped_text
except Exception as e:
get_logger().warning(f"Failed to clip tokens: {e}")
return text
def replace_code_tags(text):
"""
Replace odd instances of ` with <code> and even instances of ` with </code>
"""
parts = text.split('`')
for i in range(1, len(parts), 2):
parts[i] = '<code>' + parts[i] + '</code>'
return ''.join(parts)
def find_line_number_of_relevant_line_in_file(diff_files: List[FilePatchInfo],
relevant_file: str,
relevant_line_in_file: str,
absolute_position: int = None) -> Tuple[int, int]:
position = -1
if absolute_position is None:
absolute_position = -1
re_hunk_header = re.compile(
r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@[ ]?(.*)")
for file in diff_files:
if file.filename and (file.filename.strip() == relevant_file):
patch = file.patch
patch_lines = patch.splitlines()
delta = 0
start1, size1, start2, size2 = 0, 0, 0, 0
if absolute_position != -1: # matching absolute to relative
for i, line in enumerate(patch_lines):
# new hunk
if line.startswith('@@'):
delta = 0
match = re_hunk_header.match(line)
start1, size1, start2, size2 = map(int, match.groups()[:4])
elif not line.startswith('-'):
delta += 1
#
absolute_position_curr = start2 + delta - 1
if absolute_position_curr == absolute_position:
position = i
break
else:
# try to find the line in the patch using difflib, with some margin of error
matches_difflib: list[str | Any] = difflib.get_close_matches(relevant_line_in_file,
patch_lines, n=3, cutoff=0.93)
if len(matches_difflib) == 1 and matches_difflib[0].startswith('+'):
relevant_line_in_file = matches_difflib[0]
for i, line in enumerate(patch_lines):
if line.startswith('@@'):
delta = 0
match = re_hunk_header.match(line)
start1, size1, start2, size2 = map(int, match.groups()[:4])
elif not line.startswith('-'):
delta += 1
if relevant_line_in_file in line and line[0] != '-':
position = i
absolute_position = start2 + delta - 1
break
if position == -1 and relevant_line_in_file[0] == '+':
no_plus_line = relevant_line_in_file[1:].lstrip()
for i, line in enumerate(patch_lines):
if line.startswith('@@'):
delta = 0
match = re_hunk_header.match(line)
start1, size1, start2, size2 = map(int, match.groups()[:4])
elif not line.startswith('-'):
delta += 1
if no_plus_line in line and line[0] != '-':
# The model might add a '+' to the beginning of the relevant_line_in_file even if originally
# it's a context line
position = i
absolute_position = start2 + delta - 1
break
return position, absolute_position
def validate_and_await_rate_limit(rate_limit_status=None, git_provider=None, get_rate_limit_status_func=None):
if git_provider and not rate_limit_status:
rate_limit_status = {'resources': git_provider.github_client.get_rate_limit().raw_data}
if not rate_limit_status:
rate_limit_status = get_rate_limit_status_func()
# validate that the rate limit is not exceeded
is_rate_limit = False
for key, value in rate_limit_status['resources'].items():
if value['remaining'] == 0:
print(f"key: {key}, value: {value}")
is_rate_limit = True
sleep_time_sec = value['reset'] - datetime.now().timestamp()
sleep_time_hour = sleep_time_sec / 3600.0
print(f"Rate limit exceeded. Sleeping for {sleep_time_hour} hours")
if sleep_time_sec > 0:
time.sleep(sleep_time_sec+1)
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):
try:
if not get_settings().get('github_action_config.enable_output', False):
return
key_data = output_data.get(key_name, {})
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
print(f"{key_name}={json.dumps(key_data, indent=None, ensure_ascii=False)}", file=fh)
except Exception as e:
get_logger().error(f"Failed to write to GitHub Action output: {e}")
return
def show_relevant_configurations(relevant_section: str) -> str:
forbidden_keys = ['ai_disclaimer', 'ai_disclaimer_title', 'ANALYTICS_FOLDER', 'secret_provider',
'trial_prefix_message', 'no_eligible_message', 'identity_provider', 'ALLOWED_REPOS','APP_NAME']
markdown_text = ""
markdown_text += "\n<hr>\n<details> <summary><strong>🛠️ Relevant configurations:</strong></summary> \n\n"
markdown_text +="<br>These are the relevant [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml) for this tool:\n\n"
markdown_text += f"**[config**]\n```yaml\n\n"
for key, value in get_settings().config.items():
if key in forbidden_keys:
continue
markdown_text += f"{key}: {value}\n"
markdown_text += "\n```\n"
markdown_text += f"\n**[{relevant_section}]**\n```yaml\n\n"
for key, value in get_settings().get(relevant_section, {}).items():
if key in forbidden_keys:
continue
markdown_text += f"{key}: {value}\n"
markdown_text += "\n```"
markdown_text += "\n</details>\n"
return markdown_text
def is_value_no(value):
if value is None:
return True
value_str = str(value).strip().lower()
if value_str == 'no' or value_str == 'none' or value_str == 'false':
return True
return False

View File

@ -1,50 +1,80 @@
import argparse
import asyncio
import logging
import os
from pr_agent.agent.pr_agent import PRAgent, commands
from pr_agent.config_loader import get_settings
from pr_agent.log import setup_logger
log_level = os.environ.get("LOG_LEVEL", "INFO")
setup_logger(log_level)
def run(inargs=None):
def set_parser():
parser = argparse.ArgumentParser(description='AI based pull request analyzer', usage=
"""\
Usage: cli.py --pr-url=<URL on supported git hosting service> <command> [<args>].
For example:
- cli.py --pr_url=... review
- cli.py --pr_url=... describe
- cli.py --pr_url=... improve
- cli.py --pr_url=... ask "write me a poem about this PR"
- cli.py --pr_url=... reflect
"""\
Usage: cli.py --pr-url=<URL on supported git hosting service> <command> [<args>].
For example:
- cli.py --pr_url=... review
- cli.py --pr_url=... describe
- cli.py --pr_url=... improve
- cli.py --pr_url=... ask "write me a poem about this PR"
- cli.py --pr_url=... reflect
- cli.py --issue_url=... similar_issue
Supported commands:
-review / review_pr - Add a review that includes a summary of the PR and specific suggestions for improvement.
Supported commands:
- review / review_pr - Add a review that includes a summary of the PR and specific suggestions for improvement.
-ask / ask_question [question] - Ask a question about the PR.
- ask / ask_question [question] - Ask a question about the PR.
-describe / describe_pr - Modify the PR title and description based on the PR's contents.
- describe / describe_pr - Modify the PR title and description based on the PR's contents.
-improve / improve_code - Suggest improvements to the code in the PR as pull request comments ready to commit.
Extended mode ('improve --extended') employs several calls, and provides a more thorough feedback
- improve / improve_code - Suggest improvements to the code in the PR as pull request comments ready to commit.
Extended mode ('improve --extended') employs several calls, and provides a more thorough feedback
-reflect - Ask the PR author questions about the PR.
- reflect - Ask the PR author questions about the PR.
-update_changelog - Update the changelog based on the PR's contents.
- update_changelog - Update the changelog based on the PR's contents.
- add_docs
- generate_labels
Configuration:
To edit any configuration parameter from 'configuration.toml', just add -config_path=<value>.
For example: 'python cli.py --pr_url=... review --pr_reviewer.extra_instructions="focus on the file: ..."'
""")
parser.add_argument('--pr_url', type=str, help='The URL of the PR to review', required=True)
Configuration:
To edit any configuration parameter from 'configuration.toml', just add -config_path=<value>.
For example: 'python cli.py --pr_url=... review --pr_reviewer.extra_instructions="focus on the file: ..."'
""")
parser.add_argument('--pr_url', type=str, help='The URL of the PR to review', default=None)
parser.add_argument('--issue_url', type=str, help='The URL of the Issue to review', default=None)
parser.add_argument('command', type=str, help='The', choices=commands, default='review')
parser.add_argument('rest', nargs=argparse.REMAINDER, default=[])
args = parser.parse_args(inargs)
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
return parser
def run_command(pr_url, command):
# Preparing the command
run_command_str = f"--pr_url={pr_url} {command.lstrip('/')}"
args = set_parser().parse_args(run_command_str.split())
# Run the command. Feedback will appear in GitHub PR comments
run(args=args)
def run(inargs=None, args=None):
parser = set_parser()
if not args:
args = parser.parse_args(inargs)
if not args.pr_url and not args.issue_url:
parser.print_help()
return
command = args.command.lower()
get_settings().set("CONFIG.CLI_MODE", True)
result = asyncio.run(PRAgent().handle_request(args.pr_url, command + " " + " ".join(args.rest)))
if args.issue_url:
result = asyncio.run(PRAgent().handle_request(args.issue_url, [command] + args.rest))
else:
result = asyncio.run(PRAgent().handle_request(args.pr_url, [command] + args.rest))
if not result:
parser.print_help()

23
pr_agent/cli_pip.py Normal file
View File

@ -0,0 +1,23 @@
from pr_agent import cli
from pr_agent.config_loader import get_settings
def main():
# Fill in the following values
provider = "github" # GitHub provider
user_token = "..." # GitHub user token
openai_key = "..." # OpenAI key
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?"')
# Setting the configurations
get_settings().set("CONFIG.git_provider", provider)
get_settings().set("openai.key", openai_key)
get_settings().set("github.user_token", user_token)
# Run the command. Feedback will appear in GitHub PR comments
cli.run_command(pr_url, command)
if __name__ == '__main__':
main()

View File

@ -14,20 +14,35 @@ global_settings = Dynaconf(
settings_files=[join(current_dir, f) for f in [
"settings/.secrets.toml",
"settings/configuration.toml",
"settings/ignore.toml",
"settings/language_extensions.toml",
"settings/pr_reviewer_prompts.toml",
"settings/pr_questions_prompts.toml",
"settings/pr_line_questions_prompts.toml",
"settings/pr_description_prompts.toml",
"settings/pr_code_suggestions_prompts.toml",
"settings/pr_code_suggestions_reflect_prompts.toml",
"settings/pr_sort_code_suggestions_prompts.toml",
"settings/pr_information_from_user_prompts.toml",
"settings/pr_update_changelog_prompts.toml",
"settings_prod/.secrets.toml"
"settings/pr_custom_labels.toml",
"settings/pr_add_docs.toml",
"settings_prod/.secrets.toml",
"settings/custom_labels.toml"
]]
)
def get_settings():
"""
Retrieves the current settings.
This function attempts to fetch the settings from the starlette_context's context object. If it fails,
it defaults to the global settings defined outside of this function.
Returns:
Dynaconf: The current settings object, either from the context or the global default.
"""
try:
return context["settings"]
except Exception:
@ -35,7 +50,7 @@ def get_settings():
# Add local configuration from pyproject.toml of the project being reviewed
def _find_repository_root() -> Path:
def _find_repository_root() -> Optional[Path]:
"""
Identify project root directory by recursively searching for the .git directory in the parent directories.
"""
@ -55,7 +70,7 @@ def _find_pyproject() -> Optional[Path]:
"""
repo_root = _find_repository_root()
if repo_root:
pyproject = _find_repository_root() / "pyproject.toml"
pyproject = repo_root / "pyproject.toml"
return pyproject if pyproject.is_file() else None
return None

View File

@ -1,23 +1,27 @@
from pr_agent.config_loader import get_settings
from pr_agent.git_providers.bitbucket_provider import BitbucketProvider
from pr_agent.git_providers.bitbucket_server_provider import BitbucketServerProvider
from pr_agent.git_providers.codecommit_provider import CodeCommitProvider
from pr_agent.git_providers.git_provider import GitProvider
from pr_agent.git_providers.github_provider import GithubProvider
from pr_agent.git_providers.gitlab_provider import GitLabProvider
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 = {
'github': GithubProvider,
'gitlab': GitLabProvider,
'bitbucket': BitbucketProvider,
'bitbucket_server': BitbucketServerProvider,
'azure': AzureDevopsProvider,
'codecommit': CodeCommitProvider,
'local' : LocalGitProvider,
'local': LocalGitProvider,
'gerrit': GerritProvider,
}
def get_git_provider():
try:
provider_id = get_settings().config.git_provider
@ -26,3 +30,33 @@ def get_git_provider():
if provider_id not in _GIT_PROVIDERS:
raise ValueError(f"Unknown git provider: {provider_id}")
return _GIT_PROVIDERS[provider_id]
def get_git_provider_with_context(pr_url) -> GitProvider:
"""
Get a GitProvider instance for the given PR URL. If the GitProvider instance is already in the context, return it.
"""
is_context_env = None
try:
is_context_env = context.get("settings", None)
except Exception:
pass # we are not in a context environment (CLI)
# check if context["git_provider"]["pr_url"] exists
if is_context_env and context.get("git_provider", {}).get("pr_url", {}):
git_provider = context["git_provider"]["pr_url"]
# possibly check if the git_provider is still valid, or if some reset is needed
# ...
return git_provider
else:
try:
provider_id = get_settings().config.git_provider
if provider_id not in _GIT_PROVIDERS:
raise ValueError(f"Unknown git provider: {provider_id}")
git_provider = _GIT_PROVIDERS[provider_id](pr_url)
if is_context_env:
context["git_provider"] = {pr_url: git_provider}
return git_provider
except Exception as e:
raise ValueError(f"Failed to get git provider for {pr_url}") from e

View File

@ -1,32 +1,50 @@
import json
import logging
import os
from typing import Optional, Tuple
from urllib.parse import urlparse
import os
from ..algo.file_filter import filter_ignored
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 pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
AZURE_DEVOPS_AVAILABLE = True
ADO_APP_CLIENT_DEFAULT_ID = "499b84ac-1321-427f-aa17-267ca6975798/.default"
MAX_PR_DESCRIPTION_AZURE_LENGTH = 4000-1
try:
# noinspection PyUnresolvedReferences
from msrest.authentication import BasicAuthentication
# noinspection PyUnresolvedReferences
from azure.devops.connection import Connection
from azure.devops.v7_1.git.models import Comment, CommentThread, GitVersionDescriptor, GitPullRequest
# noinspection PyUnresolvedReferences
from azure.identity import DefaultAzureCredential
# noinspection PyUnresolvedReferences
from azure.devops.v7_1.git.models import (
Comment,
CommentThread,
GitVersionDescriptor,
GitPullRequest,
GitPullRequestIterationChanges,
)
except ImportError:
AZURE_DEVOPS_AVAILABLE = False
from ..algo.pr_processing import clip_tokens
from ..config_loader import get_settings
from ..algo.utils import load_large_diff
from ..algo.language_handler import is_valid_file
from .git_provider import EDIT_TYPE, FilePatchInfo
class AzureDevopsProvider(GitProvider):
class AzureDevopsProvider:
def __init__(self, pr_url: Optional[str] = None, incremental: Optional[bool] = False):
def __init__(
self, pr_url: Optional[str] = None, incremental: Optional[bool] = False
):
if not AZURE_DEVOPS_AVAILABLE:
raise ImportError("Azure DevOps provider is not available. Please install the required dependencies.")
raise ImportError(
"Azure DevOps provider is not available. Please install the required dependencies."
)
self.azure_devops_client = self._get_azure_devops_client()
self.diff_files = None
self.workspace_slug = None
self.repo_slug = None
self.repo = None
@ -37,8 +55,134 @@ class AzureDevopsProvider:
if pr_url:
self.set_pr(pr_url)
def publish_code_suggestions(self, code_suggestions: list) -> bool:
"""
Publishes code suggestions as comments on the PR.
"""
post_parameters_list = []
for suggestion in code_suggestions:
body = suggestion['body']
relevant_file = suggestion['relevant_file']
relevant_lines_start = suggestion['relevant_lines_start']
relevant_lines_end = suggestion['relevant_lines_end']
if not relevant_lines_start or relevant_lines_start == -1:
if get_settings().config.verbosity_level >= 2:
get_logger().exception(
f"Failed to publish code suggestion, relevant_lines_start is {relevant_lines_start}")
continue
if relevant_lines_end < relevant_lines_start:
if get_settings().config.verbosity_level >= 2:
get_logger().exception(f"Failed to publish code suggestion, "
f"relevant_lines_end is {relevant_lines_end} and "
f"relevant_lines_start is {relevant_lines_start}")
continue
if relevant_lines_end > relevant_lines_start:
post_parameters = {
"body": body,
"path": relevant_file,
"line": relevant_lines_end,
"start_line": relevant_lines_start,
"start_side": "RIGHT",
}
else: # API is different for single line comments
post_parameters = {
"body": body,
"path": relevant_file,
"line": relevant_lines_start,
"side": "RIGHT",
}
post_parameters_list.append(post_parameters)
try:
for post_parameters in post_parameters_list:
comment = Comment(content=post_parameters["body"], comment_type=1)
thread = CommentThread(comments=[comment],
thread_context={
"filePath": post_parameters["path"],
"rightFileStart": {
"line": post_parameters["start_line"],
"offset": 1,
},
"rightFileEnd": {
"line": post_parameters["line"],
"offset": 1,
},
})
self.azure_devops_client.create_thread(
comment_thread=thread,
project=self.workspace_slug,
repository_id=self.repo_slug,
pull_request_id=self.pr_num
)
if get_settings().config.verbosity_level >= 2:
get_logger().info(
f"Published code suggestion on {self.pr_num} at {post_parameters['path']}"
)
return True
except Exception as e:
if get_settings().config.verbosity_level >= 2:
get_logger().error(f"Failed to publish code suggestion, error: {e}")
return False
def get_pr_description_full(self) -> str:
return self.pr.description
def edit_comment(self, comment, body: str):
try:
self.azure_devops_client.update_comment(
repository_id=self.repo_slug,
pull_request_id=self.pr_num,
thread_id=comment["thread_id"],
comment_id=comment["comment_id"],
comment=Comment(content=body),
project=self.workspace_slug,
)
except Exception as e:
get_logger().exception(f"Failed to edit comment, error: {e}")
def remove_comment(self, comment):
try:
self.azure_devops_client.delete_comment(
repository_id=self.repo_slug,
pull_request_id=self.pr_num,
thread_id=comment["thread_id"],
comment_id=comment["comment_id"],
project=self.workspace_slug,
)
except Exception as e:
get_logger().exception(f"Failed to remove comment, error: {e}")
def publish_labels(self, pr_types):
try:
for pr_type in pr_types:
self.azure_devops_client.create_pull_request_label(
label={"name": pr_type},
project=self.workspace_slug,
repository_id=self.repo_slug,
pull_request_id=self.pr_num,
)
except Exception as e:
get_logger().exception(f"Failed to publish labels, error: {e}")
def get_pr_labels(self, update=False):
try:
labels = self.azure_devops_client.get_pull_request_labels(
project=self.workspace_slug,
repository_id=self.repo_slug,
pull_request_id=self.pr_num,
)
return [label.name for label in labels]
except Exception as e:
get_logger().exception(f"Failed to get labels, error: {e}")
return []
def is_supported(self, capability: str) -> bool:
if capability in ['get_issue_comments', 'create_inline_comment', 'publish_inline_comments', 'get_labels', 'remove_initial_comment']:
if capability in [
"get_issue_comments",
]:
return False
return True
@ -48,87 +192,185 @@ class AzureDevopsProvider:
def get_repo_settings(self):
try:
contents = self.azure_devops_client.get_item_content(repository_id=self.repo_slug,
project=self.workspace_slug, download=False,
include_content_metadata=False, include_content=True,
path=".pr_agent.toml")
return contents
contents = self.azure_devops_client.get_item_content(
repository_id=self.repo_slug,
project=self.workspace_slug,
download=False,
include_content_metadata=False,
include_content=True,
path=".pr_agent.toml",
)
return list(contents)[0]
except Exception as e:
logging.exception("get repo settings error")
if get_settings().config.verbosity_level >= 2:
get_logger().error(f"Failed to get repo settings, error: {e}")
return ""
def get_files(self):
files = []
for i in self.azure_devops_client.get_pull_request_commits(project=self.workspace_slug,
repository_id=self.repo_slug,
pull_request_id=self.pr_num):
changes_obj = self.azure_devops_client.get_changes(project=self.workspace_slug,
repository_id=self.repo_slug, commit_id=i.commit_id)
for i in self.azure_devops_client.get_pull_request_commits(
project=self.workspace_slug,
repository_id=self.repo_slug,
pull_request_id=self.pr_num,
):
changes_obj = self.azure_devops_client.get_changes(
project=self.workspace_slug,
repository_id=self.repo_slug,
commit_id=i.commit_id,
)
for c in changes_obj.changes:
files.append(c['item']['path'])
files.append(c["item"]["path"])
return list(set(files))
def get_diff_files(self) -> list[FilePatchInfo]:
try:
if self.diff_files:
return self.diff_files
base_sha = self.pr.last_merge_target_commit
head_sha = self.pr.last_merge_source_commit
commits = self.azure_devops_client.get_pull_request_commits(project=self.workspace_slug,
repository_id=self.repo_slug,
pull_request_id=self.pr_num)
# Get PR iterations
iterations = self.azure_devops_client.get_pull_request_iterations(
repository_id=self.repo_slug,
pull_request_id=self.pr_num,
project=self.workspace_slug
)
changes = None
if iterations:
iteration_id = iterations[-1].id # Get the last iteration (most recent changes)
# Get changes for the iteration
changes = self.azure_devops_client.get_pull_request_iteration_changes(
repository_id=self.repo_slug,
pull_request_id=self.pr_num,
iteration_id=iteration_id,
project=self.workspace_slug
)
diff_files = []
diffs = []
diff_types = {}
if changes:
for change in changes.change_entries:
item = change.additional_properties.get('item', {})
path = item.get('path', None)
if path:
diffs.append(path)
diff_types[path] = change.additional_properties.get('changeType', 'Unknown')
for c in commits:
changes_obj = self.azure_devops_client.get_changes(project=self.workspace_slug,
repository_id=self.repo_slug, commit_id=c.commit_id)
for i in changes_obj.changes:
diffs.append(i['item']['path'])
diff_types[i['item']['path']] = i['changeType']
# wrong implementation - gets all the files that were changed in any commit in the PR
# commits = self.azure_devops_client.get_pull_request_commits(
# project=self.workspace_slug,
# repository_id=self.repo_slug,
# pull_request_id=self.pr_num,
# )
#
# diff_files = []
# diffs = []
# diff_types = {}
diffs = list(set(diffs))
# for c in commits:
# changes_obj = self.azure_devops_client.get_changes(
# project=self.workspace_slug,
# repository_id=self.repo_slug,
# commit_id=c.commit_id,
# )
# for i in changes_obj.changes:
# if i["item"]["gitObjectType"] == "tree":
# continue
# diffs.append(i["item"]["path"])
# diff_types[i["item"]["path"]] = i["changeType"]
#
# diffs = list(set(diffs))
diffs_original = diffs
diffs = filter_ignored(diffs_original, 'azure')
if diffs_original != diffs:
try:
get_logger().info(f"Filtered out [ignore] files for pull request:", extra=
{"files": diffs_original, # diffs is just a list of names
"filtered_files": diffs})
except Exception:
pass
invalid_files_names = []
for file in diffs:
if not is_valid_file(file):
invalid_files_names.append(file)
continue
version = GitVersionDescriptor(version=head_sha.commit_id, version_type='commit')
new_file_content_str = self.azure_devops_client.get_item(repository_id=self.repo_slug,
path=file,
project=self.workspace_slug,
version_descriptor=version,
download=False,
include_content=True)
version = GitVersionDescriptor(
version=head_sha.commit_id, version_type="commit"
)
try:
new_file_content_str = self.azure_devops_client.get_item(
repository_id=self.repo_slug,
path=file,
project=self.workspace_slug,
version_descriptor=version,
download=False,
include_content=True,
)
new_file_content_str = new_file_content_str.content
new_file_content_str = new_file_content_str.content
except Exception as error:
get_logger().error(f"Failed to retrieve new file content of {file} at version {version}. Error: {str(error)}")
# get_logger().error(
# "Failed to retrieve new file content of %s at version %s. Error: %s",
# file,
# version,
# str(error),
# )
new_file_content_str = ""
edit_type = EDIT_TYPE.MODIFIED
if diff_types[file] == 'add':
if diff_types[file] == "add":
edit_type = EDIT_TYPE.ADDED
elif diff_types[file] == 'delete':
elif diff_types[file] == "delete":
edit_type = EDIT_TYPE.DELETED
elif diff_types[file] == 'rename':
elif diff_types[file] == "rename":
edit_type = EDIT_TYPE.RENAMED
version = GitVersionDescriptor(version=base_sha.commit_id, version_type='commit')
original_file_content_str = self.azure_devops_client.get_item(repository_id=self.repo_slug,
path=file,
project=self.workspace_slug,
version_descriptor=version,
download=False,
include_content=True)
original_file_content_str = original_file_content_str.content
version = GitVersionDescriptor(
version=base_sha.commit_id, version_type="commit"
)
try:
original_file_content_str = self.azure_devops_client.get_item(
repository_id=self.repo_slug,
path=file,
project=self.workspace_slug,
version_descriptor=version,
download=False,
include_content=True,
)
original_file_content_str = original_file_content_str.content
except Exception as error:
get_logger().error(f"Failed to retrieve original file content of {file} at version {version}. Error: {str(error)}")
original_file_content_str = ""
patch = load_large_diff(file, new_file_content_str, original_file_content_str)
patch = load_large_diff(
file, new_file_content_str, original_file_content_str, show_warning=False
).rstrip()
diff_files.append(FilePatchInfo(original_file_content_str, new_file_content_str,
patch=patch,
filename=file,
edit_type=edit_type))
# count number of lines added and removed
patch_lines = patch.splitlines(keepends=True)
num_plus_lines = len([line for line in patch_lines if line.startswith('+')])
num_minus_lines = len([line for line in patch_lines if line.startswith('-')])
diff_files.append(
FilePatchInfo(
original_file_content_str,
new_file_content_str,
patch=patch,
filename=file,
edit_type=edit_type,
num_plus_lines=num_plus_lines,
num_minus_lines=num_minus_lines,
)
)
get_logger().info(f"Invalid files: {invalid_files_names}")
self.diff_files = diff_files
return diff_files
@ -136,70 +378,145 @@ class AzureDevopsProvider:
print(f"Error: {str(e)}")
return []
def publish_comment(self, pr_comment: str, is_temporary: bool = False):
def publish_comment(self, pr_comment: str, is_temporary: bool = False, thread_context=None):
comment = Comment(content=pr_comment)
thread = CommentThread(comments=[comment])
thread_response = self.azure_devops_client.create_thread(comment_thread=thread, project=self.workspace_slug,
repository_id=self.repo_slug,
pull_request_id=self.pr_num)
thread = CommentThread(comments=[comment], thread_context=thread_context, status=1)
thread_response = self.azure_devops_client.create_thread(
comment_thread=thread,
project=self.workspace_slug,
repository_id=self.repo_slug,
pull_request_id=self.pr_num,
)
response = {"thread_id": thread_response.id, "comment_id": thread_response.comments[0].id}
if is_temporary:
self.temp_comments.append({'thread_id': thread_response.id, 'comment_id': comment.id})
self.temp_comments.append(response)
return response
def publish_description(self, pr_title: str, pr_body: str):
if len(pr_body) > MAX_PR_DESCRIPTION_AZURE_LENGTH:
usage_guide_text='<details> <summary><strong>✨ Describe tool usage guide:</strong></summary><hr>'
ind = pr_body.find(usage_guide_text)
if ind != -1:
pr_body = pr_body[:ind]
if len(pr_body) > MAX_PR_DESCRIPTION_AZURE_LENGTH:
changes_walkthrough_text = '## **Changes walkthrough**'
ind = pr_body.find(changes_walkthrough_text)
if ind != -1:
pr_body = pr_body[:ind]
if len(pr_body) > MAX_PR_DESCRIPTION_AZURE_LENGTH:
trunction_message = " ... (description truncated due to length limit)"
pr_body = pr_body[:MAX_PR_DESCRIPTION_AZURE_LENGTH - len(trunction_message)] + trunction_message
get_logger().warning("PR description was truncated due to length limit")
try:
updated_pr = GitPullRequest()
updated_pr.title = pr_title
updated_pr.description = pr_body
self.azure_devops_client.update_pull_request(project=self.workspace_slug,
repository_id=self.repo_slug,
pull_request_id=self.pr_num,
git_pull_request_to_update=updated_pr)
self.azure_devops_client.update_pull_request(
project=self.workspace_slug,
repository_id=self.repo_slug,
pull_request_id=self.pr_num,
git_pull_request_to_update=updated_pr,
)
except Exception as e:
logging.exception(f"Could not update pull request {self.pr_num} description: {e}")
get_logger().exception(
f"Could not update pull request {self.pr_num} description: {e}"
)
def remove_initial_comment(self):
return "" # not implemented yet
try:
for comment in self.temp_comments:
self.remove_comment(comment)
except Exception as e:
get_logger().exception(f"Failed to remove temp comments, error: {e}")
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
raise NotImplementedError("Azure DevOps provider does not support publishing inline comment yet")
self.publish_inline_comments([self.create_inline_comment(body, relevant_file, relevant_line_in_file)])
def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
raise NotImplementedError("Azure DevOps provider does not support creating inline comments yet")
def publish_inline_comments(self, comments: list[dict]):
raise NotImplementedError("Azure DevOps provider does not support publishing inline comments yet")
def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str,
absolute_position: int = None):
position, absolute_position = find_line_number_of_relevant_line_in_file(self.get_diff_files(),
relevant_file.strip('`'),
relevant_line_in_file,
absolute_position)
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}")
subject_type = "FILE"
else:
subject_type = "LINE"
path = relevant_file.strip()
return dict(body=body, path=path, position=position, absolute_position=absolute_position) if subject_type == "LINE" else {}
def publish_inline_comments(self, comments: list[dict], disable_fallback: bool = False):
overall_success = True
for comment in comments:
try:
self.publish_comment(comment["body"],
thread_context={
"filePath": comment["path"],
"rightFileStart": {
"line": comment["absolute_position"],
"offset": comment["position"],
},
"rightFileEnd": {
"line": comment["absolute_position"],
"offset": comment["position"],
},
})
if get_settings().config.verbosity_level >= 2:
get_logger().info(
f"Published code suggestion on {self.pr_num} at {comment['path']}"
)
except Exception as e:
if get_settings().config.verbosity_level >= 2:
get_logger().error(f"Failed to publish code suggestion, error: {e}")
overall_success = False
return overall_success
def get_title(self):
return self.pr.title
def get_languages(self):
languages = []
files = self.azure_devops_client.get_items(project=self.workspace_slug, repository_id=self.repo_slug,
recursion_level="Full", include_content_metadata=True,
include_links=False, download=False)
files = self.azure_devops_client.get_items(
project=self.workspace_slug,
repository_id=self.repo_slug,
recursion_level="Full",
include_content_metadata=True,
include_links=False,
download=False,
)
for f in files:
if f.git_object_type == 'blob':
if f.git_object_type == "blob":
file_name, file_extension = os.path.splitext(f.path)
languages.append(file_extension[1:])
extension_counts = {}
for ext in languages:
if ext != '':
if ext != "":
extension_counts[ext] = extension_counts.get(ext, 0) + 1
total_extensions = sum(extension_counts.values())
extension_percentages = {ext: (count / total_extensions) * 100 for ext, count in extension_counts.items()}
extension_percentages = {
ext: (count / total_extensions) * 100
for ext, count in extension_counts.items()
}
return extension_percentages
def get_pr_branch(self):
pr_info = self.azure_devops_client.get_pull_request_by_id(project=self.workspace_slug,
pull_request_id=self.pr_num)
source_branch = pr_info.source_ref_name.split('/')[-1]
pr_info = self.azure_devops_client.get_pull_request_by_id(
project=self.workspace_slug, pull_request_id=self.pr_num
)
source_branch = pr_info.source_ref_name.split("/")[-1]
return source_branch
def get_pr_description(self):
def get_pr_description(self, *, full: bool = True) -> str:
max_tokens = get_settings().get("CONFIG.MAX_DESCRIPTION_TOKENS", None)
if max_tokens:
return clip_tokens(self.pr.description, max_tokens)
@ -209,28 +526,26 @@ class AzureDevopsProvider:
return 0
def get_issue_comments(self):
raise NotImplementedError("Azure DevOps provider does not support issue comments yet")
raise NotImplementedError(
"Azure DevOps provider does not support issue comments yet"
)
def add_eyes_reaction(self, issue_comment_id: int) -> Optional[int]:
def add_eyes_reaction(self, issue_comment_id: int, disable_eyes: bool = False) -> Optional[int]:
return True
def remove_reaction(self, issue_comment_id: int, reaction_id: int) -> bool:
return True
def get_issue_comments(self):
raise NotImplementedError("Azure DevOps provider does not support issue comments yet")
@staticmethod
def _parse_pr_url(pr_url: str) -> Tuple[str, int]:
def _parse_pr_url(pr_url: str) -> Tuple[str, str, int]:
parsed_url = urlparse(pr_url)
if 'azure.com' not in parsed_url.netloc:
raise ValueError("The provided URL is not a valid Azure DevOps URL")
path_parts = parsed_url.path.strip("/").split("/")
path_parts = parsed_url.path.strip('/').split('/')
if len(path_parts) < 6 or path_parts[4] != 'pullrequest':
raise ValueError("The provided URL does not appear to be a Azure DevOps PR URL")
if len(path_parts) < 6 or path_parts[4] != "pullrequest":
raise ValueError(
"The provided URL does not appear to be a Azure DevOps PR URL"
)
workspace_slug = path_parts[1]
repo_slug = path_parts[3]
@ -241,15 +556,32 @@ class AzureDevopsProvider:
return workspace_slug, repo_slug, pr_number
def _get_azure_devops_client(self):
try:
pat = get_settings().azure_devops.pat
org = get_settings().azure_devops.org
except AttributeError as e:
raise ValueError(
"Azure DevOps PAT token is required ") from e
@staticmethod
def _get_azure_devops_client():
org = get_settings().azure_devops.get("org", None)
pat = get_settings().azure_devops.get("pat", None)
credentials = BasicAuthentication('', pat)
if not org:
raise ValueError("Azure DevOps organization is required")
if pat:
auth_token = pat
else:
try:
# try to use azure default credentials
# see https://learn.microsoft.com/en-us/python/api/overview/azure/identity-readme?view=azure-python
# for usage and env var configuration of user-assigned managed identity, local machine auth etc.
get_logger().info("No PAT found in settings, trying to use Azure Default Credentials.")
credentials = DefaultAzureCredential()
accessToken = credentials.get_token(ADO_APP_CLIENT_DEFAULT_ID)
auth_token = accessToken.token
except Exception as e:
get_logger().error(f"No PAT found in settings, and Azure Default Authentication failed, error: {e}")
raise
credentials = BasicAuthentication("", auth_token)
credentials = BasicAuthentication("", auth_token)
azure_devops_connection = Connection(base_url=org, creds=credentials)
azure_devops_client = azure_devops_connection.clients.get_git_client()
@ -257,13 +589,26 @@ class AzureDevopsProvider:
def _get_repo(self):
if self.repo is None:
self.repo = self.azure_devops_client.get_repository(project=self.workspace_slug,
repository_id=self.repo_slug)
self.repo = self.azure_devops_client.get_repository(
project=self.workspace_slug, repository_id=self.repo_slug
)
return self.repo
def _get_pr(self):
self.pr = self.azure_devops_client.get_pull_request_by_id(pull_request_id=self.pr_num, project=self.workspace_slug)
self.pr = self.azure_devops_client.get_pull_request_by_id(
pull_request_id=self.pr_num, project=self.workspace_slug
)
return self.pr
def get_commit_messages(self):
return "" # not implemented yet
def get_pr_id(self):
try:
pr_id = f"{self.workspace_slug}/{self.repo_slug}/{self.pr_num}"
return pr_id
except Exception as e:
if get_settings().config.verbosity_level >= 2:
get_logger().error(f"Failed to get pr id, error: {e}")
return ""

View File

@ -1,5 +1,4 @@
import json
import logging
from typing import Optional, Tuple
from urllib.parse import urlparse
@ -7,8 +6,13 @@ import requests
from atlassian.bitbucket import Cloud
from starlette_context import context
from pr_agent.algo.types import FilePatchInfo, EDIT_TYPE
from ..algo.file_filter import filter_ignored
from ..algo.language_handler import is_valid_file
from ..algo.utils import find_line_number_of_relevant_line_in_file
from ..config_loader import get_settings
from .git_provider import FilePatchInfo, GitProvider
from ..log import get_logger
from .git_provider import GitProvider
class BitbucketProvider(GitProvider):
@ -31,19 +35,23 @@ class BitbucketProvider(GitProvider):
self.repo = None
self.pr_num = None
self.pr = None
self.pr_url = pr_url
self.temp_comments = []
self.incremental = incremental
self.diff_files = None
if pr_url:
self.set_pr(pr_url)
self.bitbucket_comment_api_url = self.pr._BitbucketBase__data["links"][
"comments"
]["href"]
self.bitbucket_comment_api_url = self.pr._BitbucketBase__data["links"]["comments"]["href"]
self.bitbucket_pull_request_api_url = self.pr._BitbucketBase__data["links"]['self']['href']
def get_repo_settings(self):
try:
contents = self.repo_obj.get_contents(
".pr_agent.toml", ref=self.pr.head.sha
).decoded_content
url = (f"https://api.bitbucket.org/2.0/repositories/{self.workspace_slug}/{self.repo_slug}/src/"
f"{self.pr.destination_branch}/.pr_agent.toml")
response = requests.request("GET", url, headers=self.headers)
if response.status_code == 404: # not found
return ""
contents = response.text.encode('utf-8')
return contents
except Exception:
return ""
@ -61,14 +69,14 @@ class BitbucketProvider(GitProvider):
if not relevant_lines_start or relevant_lines_start == -1:
if get_settings().config.verbosity_level >= 2:
logging.exception(
get_logger().exception(
f"Failed to publish code suggestion, relevant_lines_start is {relevant_lines_start}"
)
continue
if relevant_lines_end < relevant_lines_start:
if get_settings().config.verbosity_level >= 2:
logging.exception(
get_logger().exception(
f"Failed to publish code suggestion, "
f"relevant_lines_end is {relevant_lines_end} and "
f"relevant_lines_start is {relevant_lines_start}"
@ -97,16 +105,11 @@ class BitbucketProvider(GitProvider):
return True
except Exception as e:
if get_settings().config.verbosity_level >= 2:
logging.error(f"Failed to publish code suggestion, error: {e}")
get_logger().error(f"Failed to publish code suggestion, error: {e}")
return False
def is_supported(self, capability: str) -> bool:
if capability in [
"get_issue_comments",
"create_inline_comment",
"publish_inline_comments",
"get_labels",
]:
if capability in ['get_issue_comments', 'publish_inline_comments', 'get_labels', 'gfm_markdown']:
return False
return True
@ -118,60 +121,188 @@ class BitbucketProvider(GitProvider):
return [diff.new.path for diff in self.pr.diffstat()]
def get_diff_files(self) -> list[FilePatchInfo]:
diffs = self.pr.diffstat()
if self.diff_files:
return self.diff_files
diffs_original = list(self.pr.diffstat())
diffs = filter_ignored(diffs_original, 'bitbucket')
if diffs != diffs_original:
try:
names_original = [d.new.path for d in diffs_original]
names_filtered = [d.new.path for d in diffs]
get_logger().info(f"Filtered out [ignore] files for PR", extra={
'original_files': names_original,
'filtered_files': names_filtered
})
except Exception as e:
pass
diff_split = [
"diff --git%s" % x for x in self.pr.diff().split("diff --git") if x.strip()
]
invalid_files_names = []
diff_files = []
for index, diff in enumerate(diffs):
if not is_valid_file(diff.new.path):
invalid_files_names.append(diff.new.path)
continue
original_file_content_str = self._get_pr_file_content(
diff.old.get_data("links")
)
new_file_content_str = self._get_pr_file_content(diff.new.get_data("links"))
diff_files.append(
FilePatchInfo(
original_file_content_str,
new_file_content_str,
diff_split[index],
diff.new.path,
)
file_patch_canonic_structure = FilePatchInfo(
original_file_content_str,
new_file_content_str,
diff_split[index],
diff.new.path,
)
if diff.data['status'] == 'added':
file_patch_canonic_structure.edit_type = EDIT_TYPE.ADDED
elif diff.data['status'] == 'removed':
file_patch_canonic_structure.edit_type = EDIT_TYPE.DELETED
elif diff.data['status'] == 'modified':
file_patch_canonic_structure.edit_type = EDIT_TYPE.MODIFIED
elif diff.data['status'] == 'renamed':
file_patch_canonic_structure.edit_type = EDIT_TYPE.RENAMED
diff_files.append(file_patch_canonic_structure)
if invalid_files_names:
get_logger().info(f"Invalid file names: {invalid_files_names}")
self.diff_files = diff_files
return diff_files
def get_latest_commit_url(self):
return self.pr.data['source']['commit']['links']['html']['href']
def get_comment_url(self, comment):
return comment.data['links']['html']['href']
def publish_persistent_comment(self, pr_comment: str,
initial_header: str,
update_header: bool = True,
name='review',
final_update_message=True):
try:
for comment in self.pr.comments():
body = comment.raw
if initial_header in body:
latest_commit_url = self.get_latest_commit_url()
comment_url = self.get_comment_url(comment)
if update_header:
updated_header = f"{initial_header}\n\n#### ({name.capitalize()} updated until commit {latest_commit_url})\n"
pr_comment_updated = pr_comment.replace(initial_header, updated_header)
else:
pr_comment_updated = pr_comment
get_logger().info(f"Persistent mode - updating comment {comment_url} to latest {name} message")
d = {"content": {"raw": pr_comment_updated}}
response = comment._update_data(comment.put(None, data=d))
if final_update_message:
self.publish_comment(
f"**[Persistent {name}]({comment_url})** updated to latest commit {latest_commit_url}")
return
except Exception as e:
get_logger().exception(f"Failed to update persistent review, error: {e}")
pass
self.publish_comment(pr_comment)
def publish_comment(self, pr_comment: str, is_temporary: bool = False):
comment = self.pr.comment(pr_comment)
if is_temporary:
self.temp_comments.append(comment["id"])
return comment
def edit_comment(self, comment, body: str):
try:
comment.update(body)
except Exception as e:
get_logger().exception(f"Failed to update comment, error: {e}")
def remove_initial_comment(self):
try:
for comment in self.temp_comments:
self.pr.delete(f"comments/{comment}")
self.remove_comment(comment)
except Exception as e:
logging.exception(f"Failed to remove temp comments, error: {e}")
get_logger().exception(f"Failed to remove temp comments, error: {e}")
def publish_inline_comment(
self, comment: str, from_line: int, to_line: int, file: str
):
payload = json.dumps(
{
"content": {
"raw": comment,
},
"inline": {"to": from_line, "path": file},
}
)
def remove_comment(self, comment):
try:
self.pr.delete(f"comments/{comment}")
except Exception as e:
get_logger().exception(f"Failed to remove comment, error: {e}")
# function to create_inline_comment
def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str, absolute_position: int = None):
position, absolute_position = find_line_number_of_relevant_line_in_file(self.get_diff_files(),
relevant_file.strip('`'),
relevant_line_in_file, absolute_position)
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}")
subject_type = "FILE"
else:
subject_type = "LINE"
path = relevant_file.strip()
return dict(body=body, path=path, position=absolute_position) if subject_type == "LINE" else {}
def publish_inline_comment(self, comment: str, from_line: int, file: str):
payload = json.dumps( {
"content": {
"raw": comment,
},
"inline": {
"to": from_line,
"path": file
},
})
response = requests.request(
"POST", self.bitbucket_comment_api_url, data=payload, headers=self.headers
)
return response
def get_line_link(self, relevant_file: str, relevant_line_start: int, relevant_line_end: int = None) -> str:
if relevant_line_start == -1:
link = f"{self.pr_url}/#L{relevant_file}"
else:
link = f"{self.pr_url}/#L{relevant_file}T{relevant_line_start}"
return link
def generate_link_to_relevant_line_number(self, suggestion) -> str:
try:
relevant_file = suggestion['relevant_file'].strip('`').strip("'").rstrip()
relevant_line_str = suggestion['relevant_line'].rstrip()
if not relevant_line_str:
return ""
diff_files = self.get_diff_files()
position, absolute_position = find_line_number_of_relevant_line_in_file \
(diff_files, relevant_file, relevant_line_str)
if absolute_position != -1 and self.pr_url:
link = f"{self.pr_url}/#L{relevant_file}T{absolute_position}"
return link
except Exception as e:
if get_settings().config.verbosity_level >= 2:
get_logger().info(f"Failed adding line link, error: {e}")
return ""
def publish_inline_comments(self, comments: list[dict]):
for comment in comments:
self.publish_inline_comment(
comment["body"], comment["start_line"], comment["line"], comment["path"]
)
if 'position' in comment:
self.publish_inline_comment(comment['body'], comment['position'], comment['path'])
elif 'start_line' in comment: # multi-line comment
# note that bitbucket does not seem to support range - only a comment on a single line - https://community.developer.atlassian.com/t/api-post-endpoint-for-inline-pull-request-comments/60452
self.publish_inline_comment(comment['body'], comment['start_line'], comment['path'])
elif 'line' in comment: # single-line comment
self.publish_inline_comment(comment['body'], comment['line'], comment['path'])
else:
get_logger().error(f"Could not publish inline comment {comment}")
def get_title(self):
return self.pr.title
@ -194,7 +325,7 @@ class BitbucketProvider(GitProvider):
"Bitbucket provider does not support issue comments yet"
)
def add_eyes_reaction(self, issue_comment_id: int) -> Optional[int]:
def add_eyes_reaction(self, issue_comment_id: int, disable_eyes: bool = False) -> Optional[int]:
return True
def remove_reaction(self, issue_comment_id: int, reaction_id: int) -> bool:
@ -233,21 +364,67 @@ class BitbucketProvider(GitProvider):
def _get_pr(self):
return self._get_repo().pullrequests.get(self.pr_num)
def get_pr_file_content(self, file_path: str, branch: str) -> str:
try:
if branch == self.pr.source_branch:
branch = self.pr.data["source"]["commit"]["hash"]
elif branch == self.pr.destination_branch:
branch = self.pr.data["destination"]["commit"]["hash"]
url = (f"https://api.bitbucket.org/2.0/repositories/{self.workspace_slug}/{self.repo_slug}/src/"
f"{branch}/{file_path}")
response = requests.request("GET", url, headers=self.headers)
if response.status_code == 404: # not found
return ""
contents = response.text
return contents
except Exception:
return ""
def create_or_update_pr_file(self, file_path: str, branch: str, contents="", message="") -> None:
url = (f"https://api.bitbucket.org/2.0/repositories/{self.workspace_slug}/{self.repo_slug}/src/")
if not message:
if contents:
message = f"Update {file_path}"
else:
message = f"Create {file_path}"
files={file_path: contents}
data={
"message": message,
"branch": branch
}
headers = {'Authorization':self.headers['Authorization']} if 'Authorization' in self.headers else {}
try:
requests.request("POST", url, headers=headers, data=data, files=files)
except Exception:
get_logger().exception(f"Failed to create empty file {file_path} in branch {branch}")
def _get_pr_file_content(self, remote_link: str):
return ""
def get_commit_messages(self):
return "" # not implemented yet
def publish_description(self, pr_title: str, pr_body: str):
pass
def create_inline_comment(
self, body: str, relevant_file: str, relevant_line_in_file: str
):
# bitbucket does not support labels
def publish_description(self, pr_title: str, description: str):
payload = json.dumps({
"description": description,
"title": pr_title
})
response = requests.request("PUT", self.bitbucket_pull_request_api_url, headers=self.headers, data=payload)
try:
if response.status_code != 200:
get_logger().info(f"Failed to update description, error code: {response.status_code}")
except:
pass
return response
# bitbucket does not support labels
def publish_labels(self, pr_types: list):
pass
def publish_labels(self, labels):
pass
def get_labels(self):
# bitbucket does not support labels
def get_pr_labels(self, update=False):
pass

View File

@ -0,0 +1,386 @@
import json
from typing import Optional, Tuple
from urllib.parse import quote_plus, urlparse
import requests
from atlassian.bitbucket import Bitbucket
from starlette_context import context
from .git_provider import GitProvider
from ..algo.types import EDIT_TYPE, FilePatchInfo
from ..algo.language_handler import is_valid_file
from ..algo.utils import load_large_diff, find_line_number_of_relevant_line_in_file
from ..config_loader import get_settings
from ..log import get_logger
class BitbucketServerProvider(GitProvider):
def __init__(
self, pr_url: Optional[str] = None, incremental: Optional[bool] = False
):
s = requests.Session()
try:
bearer = context.get("bitbucket_bearer_token", None)
s.headers["Authorization"] = f"Bearer {bearer}"
except Exception:
s.headers[
"Authorization"
] = f'Bearer {get_settings().get("BITBUCKET_SERVER.BEARER_TOKEN", None)}'
s.headers["Content-Type"] = "application/json"
self.headers = s.headers
self.bitbucket_server_url = None
self.workspace_slug = None
self.repo_slug = None
self.repo = None
self.pr_num = None
self.pr = None
self.pr_url = pr_url
self.temp_comments = []
self.incremental = incremental
self.diff_files = None
self.bitbucket_pull_request_api_url = pr_url
self.bitbucket_server_url = self._parse_bitbucket_server(url=pr_url)
self.bitbucket_client = Bitbucket(url=self.bitbucket_server_url,
token=get_settings().get("BITBUCKET_SERVER.BEARER_TOKEN", None))
if pr_url:
self.set_pr(pr_url)
def get_repo_settings(self):
try:
url = (f"{self.bitbucket_server_url}/projects/{self.workspace_slug}/repos/{self.repo_slug}/src/"
f"{self.pr.destination_branch}/.pr_agent.toml")
response = requests.request("GET", url, headers=self.headers)
if response.status_code == 404: # not found
return ""
contents = response.text.encode('utf-8')
return contents
except Exception:
return ""
def get_pr_id(self):
return self.pr_num
def publish_code_suggestions(self, code_suggestions: list) -> bool:
"""
Publishes code suggestions as comments on the PR.
"""
post_parameters_list = []
for suggestion in code_suggestions:
body = suggestion["body"]
relevant_file = suggestion["relevant_file"]
relevant_lines_start = suggestion["relevant_lines_start"]
relevant_lines_end = suggestion["relevant_lines_end"]
if not relevant_lines_start or relevant_lines_start == -1:
if get_settings().config.verbosity_level >= 2:
get_logger().exception(
f"Failed to publish code suggestion, relevant_lines_start is {relevant_lines_start}"
)
continue
if relevant_lines_end < relevant_lines_start:
if get_settings().config.verbosity_level >= 2:
get_logger().exception(
f"Failed to publish code suggestion, "
f"relevant_lines_end is {relevant_lines_end} and "
f"relevant_lines_start is {relevant_lines_start}"
)
continue
if relevant_lines_end > relevant_lines_start:
post_parameters = {
"body": body,
"path": relevant_file,
"line": relevant_lines_end,
"start_line": relevant_lines_start,
"start_side": "RIGHT",
}
else: # API is different for single line comments
post_parameters = {
"body": body,
"path": relevant_file,
"line": relevant_lines_start,
"side": "RIGHT",
}
post_parameters_list.append(post_parameters)
try:
self.publish_inline_comments(post_parameters_list)
return True
except Exception as e:
if get_settings().config.verbosity_level >= 2:
get_logger().error(f"Failed to publish code suggestion, error: {e}")
return False
def is_supported(self, capability: str) -> bool:
if capability in ['get_issue_comments', 'get_labels', 'gfm_markdown']:
return False
return True
def set_pr(self, pr_url: str):
self.workspace_slug, self.repo_slug, self.pr_num = self._parse_pr_url(pr_url)
self.pr = self._get_pr()
def get_file(self, path: str, commit_id: str):
file_content = ""
try:
file_content = self.bitbucket_client.get_content_of_file(self.workspace_slug,
self.repo_slug,
path,
commit_id)
except requests.HTTPError as e:
get_logger().debug(f"File {path} not found at commit id: {commit_id}")
return file_content
def get_files(self):
changes = self.bitbucket_client.get_pull_requests_changes(self.workspace_slug, self.repo_slug, self.pr_num)
diffstat = [change["path"]['toString'] for change in changes]
return diffstat
def get_diff_files(self) -> list[FilePatchInfo]:
if self.diff_files:
return self.diff_files
base_sha = self.pr.toRef['latestCommit']
head_sha = self.pr.fromRef['latestCommit']
diff_files = []
original_file_content_str = ""
new_file_content_str = ""
changes = self.bitbucket_client.get_pull_requests_changes(self.workspace_slug, self.repo_slug, self.pr_num)
for change in changes:
file_path = change['path']['toString']
if not is_valid_file(file_path.split("/")[-1]):
get_logger().info(f"Skipping a non-code file: {file_path}")
continue
match change['type']:
case 'ADD':
edit_type = EDIT_TYPE.ADDED
new_file_content_str = self.get_file(file_path, head_sha)
if isinstance(new_file_content_str, (bytes, bytearray)):
new_file_content_str = new_file_content_str.decode("utf-8")
original_file_content_str = ""
case 'DELETE':
edit_type = EDIT_TYPE.DELETED
new_file_content_str = ""
original_file_content_str = self.get_file(file_path, base_sha)
if isinstance(original_file_content_str, (bytes, bytearray)):
original_file_content_str = original_file_content_str.decode("utf-8")
case 'RENAME':
edit_type = EDIT_TYPE.RENAMED
case _:
edit_type = EDIT_TYPE.MODIFIED
original_file_content_str = self.get_file(file_path, base_sha)
if isinstance(original_file_content_str, (bytes, bytearray)):
original_file_content_str = original_file_content_str.decode("utf-8")
new_file_content_str = self.get_file(file_path, head_sha)
if isinstance(new_file_content_str, (bytes, bytearray)):
new_file_content_str = new_file_content_str.decode("utf-8")
patch = load_large_diff(file_path, new_file_content_str, original_file_content_str)
diff_files.append(
FilePatchInfo(
original_file_content_str,
new_file_content_str,
patch,
file_path,
edit_type=edit_type,
)
)
self.diff_files = diff_files
return diff_files
def publish_comment(self, pr_comment: str, is_temporary: bool = False):
if not is_temporary:
self.bitbucket_client.add_pull_request_comment(self.workspace_slug, self.repo_slug, self.pr_num, pr_comment)
def remove_initial_comment(self):
try:
for comment in self.temp_comments:
self.remove_comment(comment)
except ValueError as e:
get_logger().exception(f"Failed to remove temp comments, error: {e}")
def remove_comment(self, comment):
pass
# function to create_inline_comment
def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str,
absolute_position: int = None):
position, absolute_position = find_line_number_of_relevant_line_in_file(
self.get_diff_files(),
relevant_file.strip('`'),
relevant_line_in_file,
absolute_position
)
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}")
subject_type = "FILE"
else:
subject_type = "LINE"
path = relevant_file.strip()
return dict(body=body, path=path, position=absolute_position) if subject_type == "LINE" else {}
def publish_inline_comment(self, comment: str, from_line: int, file: str):
payload = {
"text": comment,
"severity": "NORMAL",
"anchor": {
"diffType": "EFFECTIVE",
"path": file,
"lineType": "ADDED",
"line": from_line,
"fileType": "TO"
}
}
try:
requests.post(url=self._get_pr_comments_url(), json=payload, headers=self.headers).raise_for_status()
except Exception as e:
get_logger().error(f"Failed to publish inline comment to '{file}' at line {from_line}, error: {e}")
raise e
def generate_link_to_relevant_line_number(self, suggestion) -> str:
try:
relevant_file = suggestion['relevant_file'].strip('`').strip("'").rstrip()
relevant_line_str = suggestion['relevant_line'].rstrip()
if not relevant_line_str:
return ""
diff_files = self.get_diff_files()
position, absolute_position = find_line_number_of_relevant_line_in_file \
(diff_files, relevant_file, relevant_line_str)
if absolute_position != -1:
if self.pr:
link = f"{self.pr_url}/diff#{quote_plus(relevant_file)}?t={absolute_position}"
return link
else:
if get_settings().config.verbosity_level >= 2:
get_logger().info(f"Failed adding line link to '{relevant_file}' since PR not set")
else:
if get_settings().config.verbosity_level >= 2:
get_logger().info(f"Failed adding line link to '{relevant_file}' since position not found")
if absolute_position != -1 and self.pr_url:
link = f"{self.pr_url}/diff#{quote_plus(relevant_file)}?t={absolute_position}"
return link
except Exception as e:
if get_settings().config.verbosity_level >= 2:
get_logger().info(f"Failed adding line link to '{relevant_file}', error: {e}")
return ""
def publish_inline_comments(self, comments: list[dict]):
for comment in comments:
if 'position' in comment:
self.publish_inline_comment(comment['body'], comment['position'], comment['path'])
elif 'start_line' in comment: # multi-line comment
# note that bitbucket does not seem to support range - only a comment on a single line - https://community.developer.atlassian.com/t/api-post-endpoint-for-inline-pull-request-comments/60452
self.publish_inline_comment(comment['body'], comment['start_line'], comment['path'])
elif 'line' in comment: # single-line comment
self.publish_inline_comment(comment['body'], comment['line'], comment['path'])
else:
get_logger().error(f"Could not publish inline comment: {comment}")
def get_title(self):
return self.pr.title
def get_languages(self):
return {"yaml": 0} # devops LOL
def get_pr_branch(self):
return self.pr.fromRef['displayId']
def get_pr_description_full(self):
if hasattr(self.pr, "description"):
return self.pr.description
else:
return None
def get_user_id(self):
return 0
def get_issue_comments(self):
raise NotImplementedError(
"Bitbucket provider does not support issue comments yet"
)
def add_eyes_reaction(self, issue_comment_id: int, disable_eyes: bool = False) -> Optional[int]:
return True
def remove_reaction(self, issue_comment_id: int, reaction_id: int) -> bool:
return True
@staticmethod
def _parse_bitbucket_server(url: str) -> str:
parsed_url = urlparse(url)
return f"{parsed_url.scheme}://{parsed_url.netloc}"
@staticmethod
def _parse_pr_url(pr_url: str) -> Tuple[str, str, int]:
parsed_url = urlparse(pr_url)
path_parts = parsed_url.path.strip("/").split("/")
if len(path_parts) < 6 or path_parts[4] != "pull-requests":
raise ValueError(
f"The provided URL '{pr_url}' does not appear to be a Bitbucket PR URL"
)
workspace_slug = path_parts[1]
repo_slug = path_parts[3]
try:
pr_number = int(path_parts[5])
except ValueError as e:
raise ValueError(f"Unable to convert PR number '{path_parts[5]}' to integer") from e
return workspace_slug, repo_slug, pr_number
def _get_repo(self):
if self.repo is None:
self.repo = self.bitbucket_client.get_repo(self.workspace_slug, self.repo_slug)
return self.repo
def _get_pr(self):
pr = self.bitbucket_client.get_pull_request(self.workspace_slug, self.repo_slug, pull_request_id=self.pr_num)
return type('new_dict', (object,), pr)
def _get_pr_file_content(self, remote_link: str):
return ""
def get_commit_messages(self):
def get_commit_messages(self):
raise NotImplementedError("Get commit messages function not implemented yet.")
# bitbucket does not support labels
def publish_description(self, pr_title: str, description: str):
payload = {
"version": self.pr.version,
"description": description,
"title": pr_title,
"reviewers": self.pr.reviewers # needs to be sent otherwise gets wiped
}
try:
self.bitbucket_client.update_pull_request(self.workspace_slug, self.repo_slug, str(self.pr_num), payload)
except Exception as e:
get_logger().error(f"Failed to update pull request, error: {e}")
raise e
# bitbucket does not support labels
def publish_labels(self, pr_types: list):
pass
# bitbucket does not support labels
def get_pr_labels(self, update=False):
pass
def _get_pr_comments_url(self):
return f"{self.bitbucket_server_url}/rest/api/latest/projects/{self.workspace_slug}/repos/{self.repo_slug}/pull-requests/{self.pr_num}/comments"

View File

@ -54,11 +54,16 @@ class CodeCommitClient:
def __init__(self):
self.boto_client = None
def is_supported(self, capability: str) -> bool:
if capability in ["gfm_markdown"]:
return False
return True
def _connect_boto_client(self):
try:
self.boto_client = boto3.client("codecommit")
except Exception as e:
raise ValueError(f"Failed to connect to AWS CodeCommit: {e}")
raise ValueError(f"Failed to connect to AWS CodeCommit: {e}") from e
def get_differences(self, repo_name: int, destination_commit: str, source_commit: str):
"""

View File

@ -1,17 +1,16 @@
import logging
import os
import re
from collections import Counter
from typing import List, Optional, Tuple
from urllib.parse import urlparse
from ..algo.language_handler import is_valid_file, language_extension_map
from ..algo.pr_processing import clip_tokens
from ..algo.utils import load_large_diff
from ..config_loader import get_settings
from .git_provider import EDIT_TYPE, FilePatchInfo, GitProvider, IncrementalPR
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 .git_provider import GitProvider
from ..config_loader import get_settings
from ..log import get_logger
from pr_agent.algo.language_handler import is_valid_file
class PullRequestCCMimic:
"""
@ -62,6 +61,7 @@ class CodeCommitProvider(GitProvider):
self.pr = None
self.diff_files = None
self.git_files = None
self.pr_url = pr_url
if pr_url:
self.set_pr(pr_url)
@ -74,6 +74,7 @@ class CodeCommitProvider(GitProvider):
"create_inline_comment",
"publish_inline_comments",
"get_labels",
"gfm_markdown"
]:
return False
return True
@ -165,7 +166,7 @@ class CodeCommitProvider(GitProvider):
def publish_comment(self, pr_comment: str, is_temporary: bool = False):
if is_temporary:
logging.info(pr_comment)
get_logger().info(pr_comment)
return
pr_comment = CodeCommitProvider._remove_markdown_html(pr_comment)
@ -187,12 +188,12 @@ class CodeCommitProvider(GitProvider):
for suggestion in code_suggestions:
# Verify that each suggestion has the required keys
if not all(key in suggestion for key in ["body", "relevant_file", "relevant_lines_start"]):
logging.warning(f"Skipping code suggestion #{counter}: Each suggestion must have 'body', 'relevant_file', 'relevant_lines_start' keys")
get_logger().warning(f"Skipping code suggestion #{counter}: Each suggestion must have 'body', 'relevant_file', 'relevant_lines_start' keys")
continue
# Publish the code suggestion to CodeCommit
try:
logging.debug(f"Code Suggestion #{counter} in file: {suggestion['relevant_file']}: {suggestion['relevant_lines_start']}")
get_logger().debug(f"Code Suggestion #{counter} in file: {suggestion['relevant_file']}: {suggestion['relevant_lines_start']}")
self.codecommit_client.publish_comment(
repo_name=self.repo_name,
pr_number=self.pr_num,
@ -215,25 +216,37 @@ class CodeCommitProvider(GitProvider):
def publish_labels(self, labels):
return [""] # not implemented yet
def get_labels(self):
def get_pr_labels(self, update=False):
return [""] # not implemented yet
def remove_initial_comment(self):
return "" # not implemented yet
def remove_comment(self, comment):
return "" # not implemented yet
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/codecommit/client/post_comment_for_compared_commit.html
raise NotImplementedError("CodeCommit provider does not support publishing inline comments yet")
def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
raise NotImplementedError("CodeCommit provider does not support creating inline comments yet")
def publish_inline_comments(self, comments: list[dict]):
raise NotImplementedError("CodeCommit provider does not support publishing inline comments yet")
def get_title(self):
return self.pr.get("title", "")
return self.pr.title
def get_pr_id(self):
"""
Returns the PR ID in the format: "repo_name/pr_number".
Note: This is an internal identifier for PR-Agent,
and is not the same as the CodeCommit PR identifier.
"""
try:
pr_id = f"{self.repo_name}/{self.pr_num}"
return pr_id
except:
return ""
def get_languages(self):
"""
Returns a dictionary of languages, containing the percentage of each language used in the PR.
@ -254,6 +267,8 @@ class CodeCommitProvider(GitProvider):
# where each dictionary item is a language name.
# We build that language->extension dictionary here in main_extensions_flat.
main_extensions_flat = {}
language_extension_map_org = get_settings().language_extension_map_org
language_extension_map = {k.lower(): v for k, v in language_extension_map_org.items()}
for language, extensions in language_extension_map.items():
for ext in extensions:
main_extensions_flat[ext] = language
@ -282,12 +297,12 @@ class CodeCommitProvider(GitProvider):
settings_filename = ".pr_agent.toml"
return self.codecommit_client.get_file(self.repo_name, settings_filename, self.pr.source_commit, optional=True)
def add_eyes_reaction(self, issue_comment_id: int) -> Optional[int]:
logging.info("CodeCommit provider does not support eyes reaction yet")
def add_eyes_reaction(self, issue_comment_id: int, disable_eyes: bool = False) -> Optional[int]:
get_logger().info("CodeCommit provider does not support eyes reaction yet")
return True
def remove_reaction(self, issue_comment_id: int, reaction_id: int) -> bool:
logging.info("CodeCommit provider does not support removing reactions yet")
get_logger().info("CodeCommit provider does not support removing reactions yet")
return True
@staticmethod
@ -353,7 +368,7 @@ class CodeCommitProvider(GitProvider):
# TODO: implement support for multiple targets in one CodeCommit PR
# for now, we are only using the first target in the PR
if len(response.targets) > 1:
logging.warning(
get_logger().warning(
"Multiple targets in one PR is not supported for CodeCommit yet. Continuing, using the first target only..."
)

View File

@ -1,5 +1,4 @@
import json
import logging
import os
import pathlib
import shutil
@ -7,18 +6,17 @@ import subprocess
import uuid
from collections import Counter, namedtuple
from pathlib import Path
from tempfile import mkdtemp, NamedTemporaryFile
from tempfile import NamedTemporaryFile, mkdtemp
import requests
import urllib3.util
from git import Repo
from pr_agent.config_loader import get_settings
from pr_agent.git_providers.git_provider import GitProvider, FilePatchInfo, \
EDIT_TYPE
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
logger = logging.getLogger(__name__)
from pr_agent.log import get_logger
def _call(*command, **kwargs) -> (int, str, str):
@ -33,42 +31,42 @@ def _call(*command, **kwargs) -> (int, str, str):
def clone(url, directory):
logger.info("Cloning %s to %s", url, directory)
get_logger().info("Cloning %s to %s", url, directory)
stdout = _call('git', 'clone', "--depth", "1", url, directory)
logger.info(stdout)
get_logger().info(stdout)
def fetch(url, refspec, cwd):
logger.info("Fetching %s %s", url, refspec)
get_logger().info("Fetching %s %s", url, refspec)
stdout = _call(
'git', 'fetch', '--depth', '2', url, refspec,
cwd=cwd
)
logger.info(stdout)
get_logger().info(stdout)
def checkout(cwd):
logger.info("Checking out")
get_logger().info("Checking out")
stdout = _call('git', 'checkout', "FETCH_HEAD", cwd=cwd)
logger.info(stdout)
get_logger().info(stdout)
def show(*args, cwd=None):
logger.info("Show")
get_logger().info("Show")
return _call('git', 'show', *args, cwd=cwd)
def diff(*args, cwd=None):
logger.info("Diff")
get_logger().info("Diff")
patch = _call('git', 'diff', *args, cwd=cwd)
if not patch:
logger.warning("No changes found")
get_logger().warning("No changes found")
return
return patch
def reset_local_changes(cwd):
logger.info("Reset local changes")
get_logger().info("Reset local changes")
_call('git', 'checkout', "--force", cwd=cwd)
@ -115,7 +113,14 @@ def adopt_to_gerrit_message(message):
lines = message.splitlines()
buf = []
for line in lines:
line = line.replace("*", "").replace("``", "`")
# remove markdown formatting
line = (line.replace("*", "")
.replace("``", "`")
.replace("<details>", "")
.replace("</details>", "")
.replace("<summary>", "")
.replace("</summary>", ""))
line = line.strip()
if line.startswith('#'):
buf.append("\n" +
@ -188,7 +193,7 @@ class GerritProvider(GitProvider):
)
self.repo = Repo(self.repo_path)
assert self.repo
self.pr_url = base_url
self.pr = PullRequestMimic(self.get_pr_title(), self.get_diff_files())
def get_pr_title(self):
@ -203,11 +208,11 @@ class GerritProvider(GitProvider):
Comment = namedtuple('Comment', ['body'])
return Comments([Comment(c['message']) for c in reversed(comments)])
def get_labels(self):
def get_pr_labels(self, update=False):
raise NotImplementedError(
'Getting labels is not implemented for the gerrit provider')
def add_eyes_reaction(self, issue_comment_id: int):
def add_eyes_reaction(self, issue_comment_id: int, disable_eyes: bool = False):
raise NotImplementedError(
'Adding reactions is not implemented for the gerrit provider')
@ -219,10 +224,12 @@ class GerritProvider(GitProvider):
return [self.repo.head.commit.message]
def get_repo_settings(self):
"""
TODO: Implement support of .pr_agent.toml
"""
return ""
try:
with open(self.repo_path / ".pr_agent.toml", 'rb') as f:
contents = f.read()
return contents
except OSError:
return b""
def get_diff_files(self) -> list[FilePatchInfo]:
diffs = self.repo.head.commit.diff(
@ -304,7 +311,8 @@ class GerritProvider(GitProvider):
# 'get_issue_comments',
'create_inline_comment',
'publish_inline_comments',
'get_labels'
'get_labels',
'gfm_markdown'
]:
return False
return True
@ -373,11 +381,6 @@ class GerritProvider(GitProvider):
'Publishing inline comments is not implemented for the gerrit '
'provider')
def create_inline_comment(self, body: str, relevant_file: str,
relevant_line_in_file: str):
raise NotImplementedError(
'Creating inline comments is not implemented for the gerrit '
'provider')
def publish_labels(self, labels):
# Not applicable to the local git provider,
@ -389,5 +392,8 @@ class GerritProvider(GitProvider):
# shutil.rmtree(self.repo_path)
pass
def remove_comment(self, comment):
pass
def get_pr_branch(self):
return self.repo.head

View File

@ -1,28 +1,11 @@
import logging
from abc import ABC, abstractmethod
from dataclasses import dataclass
# enum EDIT_TYPE (ADDED, DELETED, MODIFIED, RENAMED)
from enum import Enum
from typing import Optional
class EDIT_TYPE(Enum):
ADDED = 1
DELETED = 2
MODIFIED = 3
RENAMED = 4
@dataclass
class FilePatchInfo:
base_file: str
head_file: str
patch: str
filename: str
tokens: int = -1
edit_type: EDIT_TYPE = EDIT_TYPE.MODIFIED
old_filename: str = None
from pr_agent.config_loader import get_settings
from pr_agent.algo.types import FilePatchInfo
from pr_agent.log import get_logger
class GitProvider(ABC):
@ -30,46 +13,25 @@ class GitProvider(ABC):
def is_supported(self, capability: str) -> bool:
pass
@abstractmethod
def get_files(self) -> list:
pass
@abstractmethod
def get_diff_files(self) -> list[FilePatchInfo]:
pass
def get_incremental_commits(self, is_incremental):
pass
@abstractmethod
def publish_description(self, pr_title: str, pr_body: str):
pass
@abstractmethod
def publish_comment(self, pr_comment: str, is_temporary: bool = False):
pass
@abstractmethod
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
pass
@abstractmethod
def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
pass
@abstractmethod
def publish_inline_comments(self, comments: list[dict]):
pass
@abstractmethod
def publish_code_suggestions(self, code_suggestions: list) -> bool:
pass
@abstractmethod
def publish_labels(self, labels):
pass
@abstractmethod
def get_labels(self):
pass
@abstractmethod
def remove_initial_comment(self):
pass
@abstractmethod
def get_languages(self):
pass
@ -86,86 +48,261 @@ class GitProvider(ABC):
def get_pr_description_full(self) -> str:
pass
def edit_comment(self, comment, body: str):
pass
def reply_to_comment_from_comment_id(self, comment_id: int, body: str):
pass
def get_pr_description(self, *, full: bool = True) -> str:
from pr_agent.config_loader import get_settings
from pr_agent.algo.pr_processing import clip_tokens
max_tokens = get_settings().get("CONFIG.MAX_DESCRIPTION_TOKENS", None)
from pr_agent.algo.utils import clip_tokens
max_tokens_description = get_settings().get("CONFIG.MAX_DESCRIPTION_TOKENS", None)
description = self.get_pr_description_full() if full else self.get_user_description()
if max_tokens:
return clip_tokens(description, max_tokens)
if max_tokens_description:
return clip_tokens(description, max_tokens_description)
return description
def get_user_description(self) -> str:
description = (self.get_pr_description_full() or "").strip()
# if the existing description wasn't generated by the pr-agent, just return it as-is
if not description.startswith("## PR Type"):
return description
# if the existing description was generated by the pr-agent, but it doesn't contain the user description,
# return nothing (empty string) because it means there is no user description
if "## User Description:" not in description:
return ""
# otherwise, extract the original user description from the existing pr-agent description and return it
return description.split("## User Description:", 1)[1].strip()
if hasattr(self, 'user_description') and not (self.user_description is None):
return self.user_description
@abstractmethod
def get_issue_comments(self):
pass
description = (self.get_pr_description_full() or "").strip()
description_lowercase = description.lower()
get_logger().debug(f"Existing description", description=description_lowercase)
# if the existing description wasn't generated by the pr-agent, just return it as-is
if not self._is_generated_by_pr_agent(description_lowercase):
get_logger().info(f"Existing description was not generated by the pr-agent")
return description
# if the existing description was generated by the pr-agent, but it doesn't contain a user description,
# return nothing (empty string) because it means there is no user description
user_description_header = "### **user description**"
if user_description_header not in description_lowercase:
get_logger().info(f"Existing description was generated by the pr-agent, but it doesn't contain a user description")
return ""
# otherwise, extract the original user description from the existing pr-agent description and return it
# user_description_start_position = description_lowercase.find(user_description_header) + len(user_description_header)
# return description[user_description_start_position:].split("\n", 1)[-1].strip()
# the 'user description' is in the beginning. extract and return it
possible_headers = self._possible_headers()
start_position = description_lowercase.find(user_description_header) + len(user_description_header)
end_position = len(description)
for header in possible_headers: # try to clip at the next header
if header != user_description_header and header in description_lowercase:
end_position = min(end_position, description_lowercase.find(header))
if end_position != len(description) and end_position > start_position:
original_user_description = description[start_position:end_position].strip()
if original_user_description.endswith("___"):
original_user_description = original_user_description[:-3].strip()
else:
original_user_description = description.split("___")[0].strip()
if original_user_description.lower().startswith(user_description_header):
original_user_description = original_user_description[len(user_description_header):].strip()
get_logger().info(f"Extracted user description from existing description",
description=original_user_description)
self.user_description = original_user_description
return original_user_description
def _possible_headers(self):
return ("### **user description**", "### **pr type**", "### **pr description**", "### **pr labels**", "### **type**", "### **description**",
"### **labels**", "### 🤖 generated by pr agent")
def _is_generated_by_pr_agent(self, description_lowercase: str) -> bool:
possible_headers = self._possible_headers()
return any(description_lowercase.startswith(header) for header in possible_headers)
@abstractmethod
def get_repo_settings(self):
pass
def get_pr_id(self):
return ""
def get_line_link(self, relevant_file: str, relevant_line_start: int, relevant_line_end: int = None) -> str:
return ""
#### comments operations ####
@abstractmethod
def add_eyes_reaction(self, issue_comment_id: int) -> Optional[int]:
def publish_comment(self, pr_comment: str, is_temporary: bool = False):
pass
def publish_persistent_comment(self, pr_comment: str,
initial_header: str,
update_header: bool = True,
name='review',
final_update_message=True):
self.publish_comment(pr_comment)
def publish_persistent_comment_full(self, pr_comment: str,
initial_header: str,
update_header: bool = True,
name='review',
final_update_message=True):
try:
prev_comments = list(self.get_issue_comments())
for comment in prev_comments:
if comment.body.startswith(initial_header):
latest_commit_url = self.get_latest_commit_url()
comment_url = self.get_comment_url(comment)
if update_header:
updated_header = f"{initial_header}\n\n#### ({name.capitalize()} updated until commit {latest_commit_url})\n"
pr_comment_updated = pr_comment.replace(initial_header, updated_header)
else:
pr_comment_updated = pr_comment
get_logger().info(f"Persistent mode - updating comment {comment_url} to latest {name} message")
# response = self.mr.notes.update(comment.id, {'body': pr_comment_updated})
self.edit_comment(comment, pr_comment_updated)
if final_update_message:
self.publish_comment(
f"**[Persistent {name}]({comment_url})** updated to latest commit {latest_commit_url}")
return
except Exception as e:
get_logger().exception(f"Failed to update persistent review, error: {e}")
pass
self.publish_comment(pr_comment)
@abstractmethod
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
pass
def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str,
absolute_position: int = None):
raise NotImplementedError("This git provider does not support creating inline comments yet")
@abstractmethod
def publish_inline_comments(self, comments: list[dict]):
pass
@abstractmethod
def remove_initial_comment(self):
pass
@abstractmethod
def remove_comment(self, comment):
pass
@abstractmethod
def get_issue_comments(self):
pass
def get_comment_url(self, comment) -> str:
return ""
#### labels operations ####
@abstractmethod
def publish_labels(self, labels):
pass
@abstractmethod
def get_pr_labels(self, update=False):
pass
def get_repo_labels(self):
pass
@abstractmethod
def add_eyes_reaction(self, issue_comment_id: int, disable_eyes: bool = False) -> Optional[int]:
pass
@abstractmethod
def remove_reaction(self, issue_comment_id: int, reaction_id: int) -> bool:
pass
#### commits operations ####
@abstractmethod
def get_commit_messages(self):
pass
def get_pr_url(self) -> str:
if hasattr(self, 'pr_url'):
return self.pr_url
return ""
def get_latest_commit_url(self) -> str:
return ""
def auto_approve(self) -> bool:
return False
def calc_pr_statistics(self, pull_request_data: dict):
return {}
def get_num_of_files(self):
try:
return len(self.get_diff_files())
except Exception as e:
return -1
def get_main_pr_language(languages, files) -> str:
"""
Get the main language of the commit. Return an empty string if cannot determine.
"""
main_language_str = ""
if not languages:
get_logger().info("No languages detected")
return main_language_str
if not files:
get_logger().info("No files in diff")
return main_language_str
try:
top_language = max(languages, key=languages.get).lower()
# validate that the specific commit uses the main language
extension_list = []
for file in files:
if not file:
continue
if isinstance(file, str):
file = FilePatchInfo(base_file=None, head_file=None, patch=None, filename=file)
extension_list.append(file.filename.rsplit('.')[-1])
# get the most common extension
most_common_extension = max(set(extension_list), key=extension_list.count)
most_common_extension = '.' + max(set(extension_list), key=extension_list.count)
try:
language_extension_map_org = get_settings().language_extension_map_org
language_extension_map = {k.lower(): v for k, v in language_extension_map_org.items()}
# look for a match. TBD: add more languages, do this systematically
if most_common_extension == 'py' and top_language == 'python' or \
most_common_extension == 'js' and top_language == 'javascript' or \
most_common_extension == 'ts' and top_language == 'typescript' or \
most_common_extension == 'go' and top_language == 'go' or \
most_common_extension == 'java' and top_language == 'java' or \
most_common_extension == 'c' and top_language == 'c' or \
most_common_extension == 'cpp' and top_language == 'c++' or \
most_common_extension == 'cs' and top_language == 'c#' or \
most_common_extension == 'swift' and top_language == 'swift' or \
most_common_extension == 'php' and top_language == 'php' or \
most_common_extension == 'rb' and top_language == 'ruby' or \
most_common_extension == 'rs' and top_language == 'rust' or \
most_common_extension == 'scala' and top_language == 'scala' or \
most_common_extension == 'kt' and top_language == 'kotlin' or \
most_common_extension == 'pl' and top_language == 'perl' or \
most_common_extension == top_language:
main_language_str = top_language
if top_language in language_extension_map and most_common_extension in language_extension_map[top_language]:
main_language_str = top_language
else:
for language, extensions in language_extension_map.items():
if most_common_extension in extensions:
main_language_str = language
break
except Exception as e:
get_logger().exception(f"Failed to get main language: {e}")
pass
## old approach:
# most_common_extension = max(set(extension_list), key=extension_list.count)
# if most_common_extension == 'py' and top_language == 'python' or \
# most_common_extension == 'js' and top_language == 'javascript' or \
# most_common_extension == 'ts' and top_language == 'typescript' or \
# most_common_extension == 'tsx' and top_language == 'typescript' or \
# most_common_extension == 'go' and top_language == 'go' or \
# most_common_extension == 'java' and top_language == 'java' or \
# most_common_extension == 'c' and top_language == 'c' or \
# most_common_extension == 'cpp' and top_language == 'c++' or \
# most_common_extension == 'cs' and top_language == 'c#' or \
# most_common_extension == 'swift' and top_language == 'swift' or \
# most_common_extension == 'php' and top_language == 'php' or \
# most_common_extension == 'rb' and top_language == 'ruby' or \
# most_common_extension == 'rs' and top_language == 'rust' or \
# most_common_extension == 'scala' and top_language == 'scala' or \
# most_common_extension == 'kt' and top_language == 'kotlin' or \
# most_common_extension == 'pl' and top_language == 'perl' or \
# most_common_extension == top_language:
# main_language_str = top_language
except Exception as e:
logging.exception(e)
get_logger().exception(e)
pass
return main_language_str
@ -175,6 +312,13 @@ class IncrementalPR:
def __init__(self, is_incremental: bool = False):
self.is_incremental = is_incremental
self.commits_range = None
self.first_new_commit_sha = None
self.last_seen_commit_sha = None
self.first_new_commit = None
self.last_seen_commit = None
@property
def first_new_commit_sha(self):
return None if self.first_new_commit is None else self.first_new_commit.sha
@property
def last_seen_commit_sha(self):
return None if self.last_seen_commit is None else self.last_seen_commit.sha

View File

@ -1,29 +1,32 @@
import logging
import time
import hashlib
from datetime import datetime
from typing import Optional, Tuple, Any
from typing import Optional, Tuple
from urllib.parse import urlparse
from github import AppAuthentication, Auth, Github, GithubException, Reaction
from github import AppAuthentication, Auth, Github, GithubException
from retry import retry
from starlette_context import context
from .git_provider import FilePatchInfo, GitProvider, IncrementalPR
from ..algo.file_filter import filter_ignored
from ..algo.language_handler import is_valid_file
from ..algo.utils import load_large_diff
from ..algo.pr_processing import find_line_number_of_relevant_line_in_file, clip_tokens
from ..algo.utils import PRReviewHeader, load_large_diff, clip_tokens, find_line_number_of_relevant_line_in_file
from ..config_loader import get_settings
from ..log import get_logger
from ..servers.utils import RateLimitExceeded
from .git_provider import GitProvider, IncrementalPR
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
class GithubProvider(GitProvider):
def __init__(self, pr_url: Optional[str] = None, incremental=IncrementalPR(False)):
def __init__(self, pr_url: Optional[str] = None):
self.repo_obj = None
try:
self.installation_id = context.get("installation_id", None)
except Exception:
self.installation_id = None
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.github_client = self._get_github_client()
self.repo = None
self.pr_num = None
@ -31,64 +34,98 @@ class GithubProvider(GitProvider):
self.github_user_id = None
self.diff_files = None
self.git_files = None
self.incremental = incremental
if pr_url:
self.incremental = IncrementalPR(False)
if pr_url and 'pull' in pr_url:
self.set_pr(pr_url)
self.last_commit_id = list(self.pr.get_commits())[-1]
self.pr_commits = list(self.pr.get_commits())
self.last_commit_id = self.pr_commits[-1]
self.pr_url = self.get_pr_url() # pr_url for github actions can be as api.github.com, so we need to get the url from the pr object
else:
self.pr_commits = None
def get_incremental_commits(self, incremental=IncrementalPR(False)):
self.incremental = incremental
if self.incremental.is_incremental:
self.unreviewed_files_set = dict()
self._get_incremental_commits()
def is_supported(self, capability: str) -> bool:
return True
def get_pr_url(self) -> str:
return f"https://github.com/{self.repo}/pull/{self.pr_num}"
return self.pr.html_url
def set_pr(self, pr_url: str):
self.repo, self.pr_num = self._parse_pr_url(pr_url)
self.pr = self._get_pr()
if self.incremental.is_incremental:
self.get_incremental_commits()
def get_incremental_commits(self):
self.commits = list(self.pr.get_commits())
def _get_incremental_commits(self):
if not self.pr_commits:
self.pr_commits = list(self.pr.get_commits())
self.get_previous_review()
self.previous_review = self.get_previous_review(full=True, incremental=True)
if self.previous_review:
self.incremental.commits_range = self.get_commit_range()
# Get all files changed during the commit range
self.file_set = dict()
for commit in self.incremental.commits_range:
if commit.commit.message.startswith(f"Merge branch '{self._get_repo().default_branch}'"):
logging.info(f"Skipping merge commit {commit.commit.message}")
get_logger().info(f"Skipping merge commit {commit.commit.message}")
continue
self.file_set.update({file.filename: file for file in commit.files})
self.unreviewed_files_set.update({file.filename: file for file in commit.files})
else:
get_logger().info("No previous review found, will review the entire PR")
self.incremental.is_incremental = False
def get_commit_range(self):
last_review_time = self.previous_review.created_at
first_new_commit_index = 0
for index in range(len(self.commits) - 1, -1, -1):
if self.commits[index].commit.author.date > last_review_time:
self.incremental.first_new_commit_sha = self.commits[index].sha
first_new_commit_index = None
for index in range(len(self.pr_commits) - 1, -1, -1):
if self.pr_commits[index].commit.author.date > last_review_time:
self.incremental.first_new_commit = self.pr_commits[index]
first_new_commit_index = index
else:
self.incremental.last_seen_commit_sha = self.commits[index].sha
self.incremental.last_seen_commit = self.pr_commits[index]
break
return self.commits[first_new_commit_index:]
return self.pr_commits[first_new_commit_index:] if first_new_commit_index is not None else []
def get_previous_review(self):
self.previous_review = None
self.comments = list(self.pr.get_issue_comments())
def get_previous_review(self, *, full: bool, incremental: bool):
if not (full or incremental):
raise ValueError("At least one of full or incremental must be True")
if not getattr(self, "comments", None):
self.comments = list(self.pr.get_issue_comments())
prefixes = []
if full:
prefixes.append(PRReviewHeader.REGULAR.value)
if incremental:
prefixes.append(PRReviewHeader.INCREMENTAL.value)
for index in range(len(self.comments) - 1, -1, -1):
if self.comments[index].body.startswith("## PR Analysis"):
self.previous_review = self.comments[index]
break
if any(self.comments[index].body.startswith(prefix) for prefix in prefixes):
return self.comments[index]
def get_files(self):
if self.incremental.is_incremental and self.file_set:
return self.file_set.values()
if not self.git_files:
# bring files from GitHub only once
self.git_files = self.pr.get_files()
return self.git_files
if self.incremental.is_incremental and self.unreviewed_files_set:
return self.unreviewed_files_set.values()
try:
git_files = context.get("git_files", None)
if git_files:
return git_files
self.git_files = list(self.pr.get_files()) # 'list' to handle pagination
context["git_files"] = self.git_files
return self.git_files
except Exception:
if not self.git_files:
self.git_files = list(self.pr.get_files())
return self.git_files
def get_num_of_files(self):
if hasattr(self.git_files, "totalCount"):
return self.git_files.totalCount
else:
try:
return len(self.git_files)
except Exception as e:
return -1
@retry(exceptions=RateLimitExceeded,
tries=get_settings().github.ratelimit_retries, delay=2, backoff=2, jitter=(1, 3))
@ -102,44 +139,105 @@ class GithubProvider(GitProvider):
or renamed files in the merge request.
"""
try:
try:
diff_files = context.get("diff_files", None)
if diff_files:
return diff_files
except Exception:
pass
if self.diff_files:
return self.diff_files
files = self.get_files()
diff_files = []
# filter files using [ignore] patterns
files_original = self.get_files()
files = filter_ignored(files_original)
if files_original != files:
try:
names_original = [file.filename for file in files_original]
names_new = [file.filename for file in files]
get_logger().info(f"Filtered out [ignore] files for pull request:", extra=
{"files": names_original,
"filtered_files": names_new})
except Exception:
pass
diff_files = []
invalid_files_names = []
for file in files:
if not is_valid_file(file.filename):
invalid_files_names.append(file.filename)
continue
new_file_content_str = self._get_pr_file_content(file, self.pr.head.sha) # communication with GitHub
patch = file.patch
if self.incremental.is_incremental and self.file_set:
if self.incremental.is_incremental and self.unreviewed_files_set:
original_file_content_str = self._get_pr_file_content(file, self.incremental.last_seen_commit_sha)
patch = load_large_diff(file.filename, new_file_content_str, original_file_content_str)
self.file_set[file.filename] = patch
self.unreviewed_files_set[file.filename] = patch
else:
original_file_content_str = self._get_pr_file_content(file, self.pr.base.sha)
if not patch:
patch = load_large_diff(file.filename, new_file_content_str, original_file_content_str)
diff_files.append(FilePatchInfo(original_file_content_str, new_file_content_str, patch, file.filename))
if file.status == 'added':
edit_type = EDIT_TYPE.ADDED
elif file.status == 'removed':
edit_type = EDIT_TYPE.DELETED
elif file.status == 'renamed':
edit_type = EDIT_TYPE.RENAMED
elif file.status == 'modified':
edit_type = EDIT_TYPE.MODIFIED
else:
get_logger().error(f"Unknown edit type: {file.status}")
edit_type = EDIT_TYPE.UNKNOWN
# count number of lines added and removed
patch_lines = patch.splitlines(keepends=True)
num_plus_lines = len([line for line in patch_lines if line.startswith('+')])
num_minus_lines = len([line for line in patch_lines if line.startswith('-')])
file_patch_canonical_structure = FilePatchInfo(original_file_content_str, new_file_content_str, patch,
file.filename, edit_type=edit_type,
num_plus_lines=num_plus_lines,
num_minus_lines=num_minus_lines,)
diff_files.append(file_patch_canonical_structure)
if invalid_files_names:
get_logger().info(f"Filtered out files with invalid extensions: {invalid_files_names}")
self.diff_files = diff_files
try:
context["diff_files"] = diff_files
except Exception:
pass
return diff_files
except GithubException.RateLimitExceededException as e:
logging.error(f"Rate limit exceeded for GitHub API. Original message: {e}")
get_logger().error(f"Rate limit exceeded for GitHub API. Original message: {e}")
raise RateLimitExceeded("Rate limit exceeded for GitHub API.") from e
def publish_description(self, pr_title: str, pr_body: str):
self.pr.edit(title=pr_title, body=pr_body)
def get_latest_commit_url(self) -> str:
return self.last_commit_id.html_url
def get_comment_url(self, comment) -> str:
return comment.html_url
def publish_persistent_comment(self, pr_comment: str,
initial_header: str,
update_header: bool = True,
name='review',
final_update_message=True):
self.publish_persistent_comment_full(pr_comment, initial_header, update_header, name, final_update_message)
def publish_comment(self, pr_comment: str, is_temporary: bool = False):
if is_temporary and not get_settings().config.publish_output_progress:
logging.debug(f"Skipping publish_comment for temporary comment: {pr_comment}")
get_logger().debug(f"Skipping publish_comment for temporary comment: {pr_comment}")
return
response = self.pr.create_issue_comment(pr_comment)
if hasattr(response, "user") and hasattr(response.user, "login"):
self.github_user_id = response.user.login
@ -147,24 +245,135 @@ class GithubProvider(GitProvider):
if not hasattr(self.pr, 'comments_list'):
self.pr.comments_list = []
self.pr.comments_list.append(response)
return response
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
self.publish_inline_comments([self.create_inline_comment(body, relevant_file, relevant_line_in_file)])
def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
position, absolute_position = find_line_number_of_relevant_line_in_file(self.diff_files, relevant_file.strip('`'), relevant_line_in_file)
def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str,
absolute_position: int = None):
position, absolute_position = find_line_number_of_relevant_line_in_file(self.diff_files,
relevant_file.strip('`'),
relevant_line_in_file,
absolute_position)
if position == -1:
if get_settings().config.verbosity_level >= 2:
logging.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"
else:
subject_type = "LINE"
path = relevant_file.strip()
return dict(body=body, path=path, position=position) if subject_type == "LINE" else {}
def publish_inline_comments(self, comments: list[dict]):
self.pr.create_review(commit=self.last_commit_id, comments=comments)
def publish_inline_comments(self, comments: list[dict], disable_fallback: bool = False):
try:
# publish all comments in a single message
self.pr.create_review(commit=self.last_commit_id, comments=comments)
except Exception as e:
if get_settings().config.verbosity_level >= 2:
get_logger().error(f"Failed to publish inline comments")
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
else:
raise e # will end up with publishing the comments one by one
try:
self._publish_inline_comments_fallback_with_verification(comments)
except Exception as e:
if get_settings().config.verbosity_level >= 2:
get_logger().error(f"Failed to publish inline code comments fallback, error: {e}")
raise e
def _publish_inline_comments_fallback_with_verification(self, comments: list[dict]):
"""
Check each inline comment separately against the GitHub API and discard of invalid comments,
then publish all the remaining valid comments in a single review.
For invalid comments, also try removing the suggestion part and posting the comment just on the first line.
"""
verified_comments, invalid_comments = self._verify_code_comments(comments)
# publish as a group the verified comments
if verified_comments:
try:
self.pr.create_review(commit=self.last_commit_id, comments=verified_comments)
except:
pass
# try to publish one by one the invalid comments as a one-line code comment
if invalid_comments and get_settings().github.try_fix_invalid_inline_comments:
fixed_comments_as_one_liner = self._try_fix_invalid_inline_comments(
[comment for comment, _ in invalid_comments])
for comment in fixed_comments_as_one_liner:
try:
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}")
except:
if get_settings().config.verbosity_level >= 2:
get_logger().error(f"Failed to publish invalid comment as a single line comment: {comment}")
def _verify_code_comment(self, comment: dict):
is_verified = False
e = None
try:
# event ="" # By leaving this blank, you set the review action state to PENDING
input = dict(commit_id=self.last_commit_id.sha, comments=[comment])
headers, data = self.pr._requester.requestJsonAndCheck(
"POST", f"{self.pr.url}/reviews", input=input)
pending_review_id = data["id"]
is_verified = True
except Exception as err:
is_verified = False
pending_review_id = None
e = err
if pending_review_id is not None:
try:
self.pr._requester.requestJsonAndCheck("DELETE", f"{self.pr.url}/reviews/{pending_review_id}")
except Exception:
pass
return is_verified, e
def _verify_code_comments(self, comments: list[dict]) -> tuple[list[dict], list[tuple[dict, Exception]]]:
"""Very each comment against the GitHub API and return 2 lists: 1 of verified and 1 of invalid comments"""
verified_comments = []
invalid_comments = []
for comment in comments:
time.sleep(1) # for avoiding secondary rate limit
is_verified, e = self._verify_code_comment(comment)
if is_verified:
verified_comments.append(comment)
else:
invalid_comments.append((comment, e))
return verified_comments, invalid_comments
def _try_fix_invalid_inline_comments(self, invalid_comments: list[dict]) -> list[dict]:
"""
Try fixing invalid comments by removing the suggestion part and setting the comment just on the first line.
Return only comments that have been modified in some way.
This is a best-effort attempt to fix invalid comments, and should be verified accordingly.
"""
import copy
fixed_comments = []
for comment in invalid_comments:
try:
fixed_comment = copy.deepcopy(comment) # avoid modifying the original comment dict for later logging
if "```suggestion" in comment["body"]:
fixed_comment["body"] = comment["body"].split("```suggestion")[0]
if "start_line" in comment:
fixed_comment["line"] = comment["start_line"]
del fixed_comment["start_line"]
if "start_side" in comment:
fixed_comment["side"] = comment["start_side"]
del fixed_comment["start_side"]
if fixed_comment != comment:
fixed_comments.append(fixed_comment)
except Exception as e:
if get_settings().config.verbosity_level >= 2:
get_logger().error(f"Failed to fix inline comment, error: {e}")
return fixed_comments
def publish_code_suggestions(self, code_suggestions: list) -> bool:
"""
@ -179,13 +388,13 @@ class GithubProvider(GitProvider):
if not relevant_lines_start or relevant_lines_start == -1:
if get_settings().config.verbosity_level >= 2:
logging.exception(
get_logger().exception(
f"Failed to publish code suggestion, relevant_lines_start is {relevant_lines_start}")
continue
if relevant_lines_end < relevant_lines_start:
if get_settings().config.verbosity_level >= 2:
logging.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_start is {relevant_lines_start}")
continue
@ -208,20 +417,39 @@ class GithubProvider(GitProvider):
post_parameters_list.append(post_parameters)
try:
self.pr.create_review(commit=self.last_commit_id, comments=post_parameters_list)
self.publish_inline_comments(post_parameters_list)
return True
except Exception as e:
if get_settings().config.verbosity_level >= 2:
logging.error(f"Failed to publish code suggestion, error: {e}")
get_logger().error(f"Failed to publish code suggestion, error: {e}")
return False
def edit_comment(self, comment, body: str):
comment.edit(body=body)
def reply_to_comment_from_comment_id(self, comment_id: int, body: str):
try:
# self.pr.get_issue_comment(comment_id).edit(body)
headers, data_patch = self.pr._requester.requestJsonAndCheck(
"POST", f"{self.base_url}/repos/{self.repo}/pulls/{self.pr_num}/comments/{comment_id}/replies",
input={"body": body}
)
except Exception as e:
get_logger().exception(f"Failed to reply comment, error: {e}")
def remove_initial_comment(self):
try:
for comment in getattr(self.pr, 'comments_list', []):
if comment.is_temporary:
comment.delete()
self.remove_comment(comment)
except Exception as e:
logging.exception(f"Failed to remove initial comment, error: {e}")
get_logger().exception(f"Failed to remove initial comment, error: {e}")
def remove_comment(self, comment):
try:
comment.delete()
except Exception as e:
get_logger().exception(f"Failed to remove comment, error: {e}")
def get_title(self):
return self.pr.title
@ -239,9 +467,10 @@ class GithubProvider(GitProvider):
def get_user_id(self):
if not self.github_user_id:
try:
self.github_user_id = self.github_client.get_user().login
self.github_user_id = self.github_client.get_user().raw_data['login']
except Exception as e:
logging.exception(f"Failed to get user id, error: {e}")
self.github_user_id = ""
# logging.exception(f"Failed to get user id, error: {e}")
return self.github_user_id
def get_notifications(self, since: datetime):
@ -258,28 +487,39 @@ class GithubProvider(GitProvider):
def get_repo_settings(self):
try:
contents = self.repo_obj.get_contents(".pr_agent.toml", ref=self.pr.head.sha).decoded_content
# contents = self.repo_obj.get_contents(".pr_agent.toml", ref=self.pr.head.sha).decoded_content
# more logical to take 'pr_agent.toml' from the default branch
contents = self.repo_obj.get_contents(".pr_agent.toml").decoded_content
return contents
except Exception:
return ""
def add_eyes_reaction(self, issue_comment_id: int) -> Optional[int]:
def add_eyes_reaction(self, issue_comment_id: int, disable_eyes: bool = False) -> Optional[int]:
if disable_eyes:
return None
try:
reaction = self.pr.get_issue_comment(issue_comment_id).create_reaction("eyes")
return reaction.id
headers, data_patch = self.pr._requester.requestJsonAndCheck(
"POST", f"{self.base_url}/repos/{self.repo}/issues/comments/{issue_comment_id}/reactions",
input={"content": "eyes"}
)
return data_patch.get("id", None)
except Exception as e:
logging.exception(f"Failed to add eyes reaction, error: {e}")
get_logger().exception(f"Failed to add eyes reaction, error: {e}")
return None
def remove_reaction(self, issue_comment_id: int, reaction_id: int) -> bool:
def remove_reaction(self, issue_comment_id: int, reaction_id: str) -> bool:
try:
self.pr.get_issue_comment(issue_comment_id).delete_reaction(reaction_id)
# self.pr.get_issue_comment(issue_comment_id).delete_reaction(reaction_id)
headers, data_patch = self.pr._requester.requestJsonAndCheck(
"DELETE",
f"{self.base_url}/repos/{self.repo}/issues/comments/{issue_comment_id}/reactions/{reaction_id}"
)
return True
except Exception as e:
logging.exception(f"Failed to remove eyes reaction, error: {e}")
get_logger().exception(f"Failed to remove eyes reaction, error: {e}")
return False
@staticmethod
def _parse_pr_url(pr_url: str) -> Tuple[str, int]:
parsed_url = urlparse(pr_url)
@ -309,6 +549,35 @@ class GithubProvider(GitProvider):
return repo_name, pr_number
@staticmethod
def _parse_issue_url(issue_url: str) -> Tuple[str, int]:
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('/')
if 'api.github.com' in parsed_url.netloc:
if len(path_parts) < 5 or path_parts[3] != 'issues':
raise ValueError("The provided URL does not appear to be a GitHub ISSUE URL")
repo_name = '/'.join(path_parts[1:3])
try:
issue_number = int(path_parts[4])
except ValueError as e:
raise ValueError("Unable to convert issue number to integer") from e
return repo_name, issue_number
if len(path_parts) < 4 or path_parts[2] != 'issues':
raise ValueError("The provided URL does not appear to be a GitHub PR issue")
repo_name = '/'.join(path_parts[:2])
try:
issue_number = int(path_parts[3])
except ValueError as e:
raise ValueError("Unable to convert issue number to integer") from e
return repo_name, issue_number
def _get_github_client(self):
deployment_type = get_settings().get("GITHUB.DEPLOYMENT_TYPE", "user")
@ -322,7 +591,7 @@ class GithubProvider(GitProvider):
raise ValueError("GitHub app installation ID is required when using GitHub app deployment")
auth = AppAuthentication(app_id=app_id, private_key=private_key,
installation_id=self.installation_id)
return Github(app_auth=auth)
return Github(app_auth=auth, base_url=self.base_url)
if deployment_type == 'user':
try:
@ -331,7 +600,7 @@ class GithubProvider(GitProvider):
raise ValueError(
"GitHub token is required when using user deployment. See: "
"https://github.com/Codium-ai/pr-agent#method-2-run-from-source") from e
return Github(auth=Auth.Token(token))
return Github(auth=Auth.Token(token), base_url=self.base_url)
def _get_repo(self):
if hasattr(self, 'repo_obj') and \
@ -346,17 +615,40 @@ class GithubProvider(GitProvider):
def _get_pr(self):
return self._get_repo().get_pull(self.pr_num)
def _get_pr_file_content(self, file: FilePatchInfo, sha: str) -> str:
def get_pr_file_content(self, file_path: str, branch: str) -> str:
try:
file_content_str = str(self._get_repo().get_contents(file.filename, ref=sha).decoded_content.decode())
file_content_str = str(
self._get_repo()
.get_contents(file_path, ref=branch)
.decoded_content.decode()
)
except Exception:
file_content_str = ""
return file_content_str
def create_or_update_pr_file(
self, file_path: str, branch: str, contents="", message=""
) -> None:
try:
file_obj = self._get_repo().get_contents(file_path, ref=branch)
sha1=file_obj.sha
except Exception:
sha1=""
self.repo_obj.update_file(
path=file_path,
message=message,
content=contents,
sha=sha1,
branch=branch,
)
def _get_pr_file_content(self, file: FilePatchInfo, sha: str) -> str:
return self.get_pr_file_content(file.filename, sha)
def publish_labels(self, pr_types):
try:
label_color_map = {"Bug fix": "1d76db", "Tests": "e99695", "Bug fix with tests": "c5def5",
"Refactoring": "bfdadc", "Enhancement": "bfd4f2", "Documentation": "d4c5f9",
"Enhancement": "bfd4f2", "Documentation": "d4c5f9",
"Other": "d1bcf9"}
post_parameters = []
for p in pr_types:
@ -366,15 +658,26 @@ class GithubProvider(GitProvider):
"PUT", f"{self.pr.issue_url}/labels", input=post_parameters
)
except Exception as e:
logging.exception(f"Failed to publish labels, error: {e}")
get_logger().exception(f"Failed to publish labels, error: {e}")
def get_labels(self):
def get_pr_labels(self, update=False):
try:
return [label.name for label in self.pr.labels]
if not update:
labels =self.pr.labels
return [label.name for label in labels]
else: # obtain the latest labels. Maybe they changed while the AI was running
headers, labels = self.pr._requester.requestJsonAndCheck(
"GET", f"{self.pr.issue_url}/labels")
return [label['name'] for label in labels]
except Exception as e:
logging.exception(f"Failed to get labels, error: {e}")
get_logger().exception(f"Failed to get labels, error: {e}")
return []
def get_repo_labels(self):
labels = self.repo_obj.get_labels()
return [label for label in labels]
def get_commit_messages(self):
"""
Retrieves the commit messages of a pull request.
@ -395,8 +698,8 @@ class GithubProvider(GitProvider):
def generate_link_to_relevant_line_number(self, suggestion) -> str:
try:
relevant_file = suggestion['relevant file'].strip('`').strip("'")
relevant_line_str = suggestion['relevant line']
relevant_file = suggestion['relevant_file'].strip('`').strip("'").strip('\n')
relevant_line_str = suggestion['relevant_line'].strip('\n')
if not relevant_line_str:
return ""
@ -410,10 +713,41 @@ class GithubProvider(GitProvider):
# link to diff
sha_file = hashlib.sha256(relevant_file.encode('utf-8')).hexdigest()
link = f"https://github.com/{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
except Exception as e:
if get_settings().config.verbosity_level >= 2:
logging.info(f"Failed adding line link, error: {e}")
get_logger().info(f"Failed adding line link, error: {e}")
return ""
def get_line_link(self, relevant_file: str, relevant_line_start: int, relevant_line_end: int = None) -> str:
sha_file = hashlib.sha256(relevant_file.encode('utf-8')).hexdigest()
if relevant_line_start == -1:
link = f"{self.base_url_html}/{self.repo}/pull/{self.pr_num}/files#diff-{sha_file}"
elif relevant_line_end:
link = f"{self.base_url_html}/{self.repo}/pull/{self.pr_num}/files#diff-{sha_file}R{relevant_line_start}-R{relevant_line_end}"
else:
link = f"{self.base_url_html}/{self.repo}/pull/{self.pr_num}/files#diff-{sha_file}R{relevant_line_start}"
return link
def get_pr_id(self):
try:
pr_id = f"{self.repo}/{self.pr_num}"
return pr_id
except:
return ""
def auto_approve(self) -> bool:
try:
res = self.pr.create_review(event="APPROVE")
if res.state == "APPROVED":
return True
return False
except Exception as e:
get_logger().exception(f"Failed to auto-approve, error: {e}")
return False
def calc_pr_statistics(self, pull_request_data: dict):
return {}

View File

@ -1,4 +1,4 @@
import logging
import hashlib
import re
from typing import Optional, Tuple
from urllib.parse import urlparse
@ -6,13 +6,14 @@ from urllib.parse import urlparse
import gitlab
from gitlab import GitlabGetError
from ..algo.file_filter import filter_ignored
from ..algo.language_handler import is_valid_file
from ..algo.pr_processing import clip_tokens
from ..algo.utils import load_large_diff
from ..algo.utils import load_large_diff, clip_tokens, find_line_number_of_relevant_line_in_file
from ..config_loader import get_settings
from .git_provider import EDIT_TYPE, FilePatchInfo, GitProvider
from .git_provider import GitProvider
from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
from ..log import get_logger
logger = logging.getLogger()
class DiffNotFoundError(Exception):
"""Raised when the diff for a merge request cannot be found."""
@ -37,13 +38,14 @@ class GitLabProvider(GitProvider):
self.diff_files = None
self.git_files = None
self.temp_comments = []
self.pr_url = merge_request_url
self._set_merge_request(merge_request_url)
self.RE_HUNK_HEADER = re.compile(
r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@[ ]?(.*)")
self.incremental = incremental
def is_supported(self, capability: str) -> bool:
if capability in ['get_issue_comments', 'create_inline_comment', 'publish_inline_comments']:
if capability in ['get_issue_comments', 'create_inline_comment', 'publish_inline_comments']: # gfm_markdown is supported in gitlab !
return False
return True
@ -58,11 +60,11 @@ class GitLabProvider(GitProvider):
try:
self.last_diff = self.mr.diffs.list(get_all=True)[-1]
except IndexError as e:
logger.error(f"Could not get diff for merge request {self.id_mr}")
get_logger().error(f"Could not get diff for merge request {self.id_mr}")
raise DiffNotFoundError(f"Could not get diff for merge request {self.id_mr}") from e
def _get_pr_file_content(self, file_path: str, branch: str) -> str:
def get_pr_file_content(self, file_path: str, branch: str) -> str:
try:
return self.gl.projects.get(self.id_project).files.get(file_path, branch).decode()
except GitlabGetError:
@ -83,47 +85,71 @@ class GitLabProvider(GitProvider):
if self.diff_files:
return self.diff_files
diffs = self.mr.changes()['changes']
# filter files using [ignore] patterns
diffs_original = self.mr.changes()['changes']
diffs = filter_ignored(diffs_original, 'gitlab')
if diffs != diffs_original:
try:
names_original = [diff['new_path'] for diff in diffs_original]
names_filtered = [diff['new_path'] for diff in diffs]
get_logger().info(f"Filtered out [ignore] files for merge request {self.id_mr}", extra={
'original_files': names_original,
'filtered_files': names_filtered
})
except Exception as e:
pass
diff_files = []
invalid_files_names = []
for diff in diffs:
if is_valid_file(diff['new_path']):
# original_file_content_str = self._get_pr_file_content(diff['old_path'], self.mr.target_branch)
# new_file_content_str = self._get_pr_file_content(diff['new_path'], self.mr.source_branch)
original_file_content_str = self._get_pr_file_content(diff['old_path'], self.mr.diff_refs['base_sha'])
new_file_content_str = self._get_pr_file_content(diff['new_path'], self.mr.diff_refs['head_sha'])
if not is_valid_file(diff['new_path']):
invalid_files_names.append(diff['new_path'])
continue
try:
if isinstance(original_file_content_str, bytes):
original_file_content_str = bytes.decode(original_file_content_str, 'utf-8')
if isinstance(new_file_content_str, bytes):
new_file_content_str = bytes.decode(new_file_content_str, 'utf-8')
except UnicodeDecodeError:
logging.warning(
f"Cannot decode file {diff['old_path']} or {diff['new_path']} in merge request {self.id_mr}")
original_file_content_str = self.get_pr_file_content(diff['old_path'], self.mr.diff_refs['base_sha'])
new_file_content_str = self.get_pr_file_content(diff['new_path'], self.mr.diff_refs['head_sha'])
try:
if isinstance(original_file_content_str, bytes):
original_file_content_str = bytes.decode(original_file_content_str, 'utf-8')
if isinstance(new_file_content_str, bytes):
new_file_content_str = bytes.decode(new_file_content_str, 'utf-8')
except UnicodeDecodeError:
get_logger().warning(
f"Cannot decode file {diff['old_path']} or {diff['new_path']} in merge request {self.id_mr}")
edit_type = EDIT_TYPE.MODIFIED
if diff['new_file']:
edit_type = EDIT_TYPE.ADDED
elif diff['deleted_file']:
edit_type = EDIT_TYPE.DELETED
elif diff['renamed_file']:
edit_type = EDIT_TYPE.RENAMED
edit_type = EDIT_TYPE.MODIFIED
if diff['new_file']:
edit_type = EDIT_TYPE.ADDED
elif diff['deleted_file']:
edit_type = EDIT_TYPE.DELETED
elif diff['renamed_file']:
edit_type = EDIT_TYPE.RENAMED
filename = diff['new_path']
patch = diff['diff']
if not patch:
patch = load_large_diff(filename, new_file_content_str, original_file_content_str)
filename = diff['new_path']
patch = diff['diff']
if not patch:
patch = load_large_diff(filename, new_file_content_str, original_file_content_str)
# count number of lines added and removed
patch_lines = patch.splitlines(keepends=True)
num_plus_lines = len([line for line in patch_lines if line.startswith('+')])
num_minus_lines = len([line for line in patch_lines if line.startswith('-')])
diff_files.append(
FilePatchInfo(original_file_content_str, new_file_content_str,
patch=patch,
filename=filename,
edit_type=edit_type,
old_filename=None if diff['old_path'] == diff['new_path'] else diff['old_path'],
num_plus_lines=num_plus_lines,
num_minus_lines=num_minus_lines, ))
if invalid_files_names:
get_logger().info(f"Filtered out files with invalid extensions: {invalid_files_names}")
diff_files.append(
FilePatchInfo(original_file_content_str, new_file_content_str,
patch=patch,
filename=filename,
edit_type=edit_type,
old_filename=None if diff['old_path'] == diff['new_path'] else diff['old_path']))
self.diff_files = diff_files
return diff_files
def get_files(self):
def get_files(self) -> list:
if not self.git_files:
self.git_files = [change['new_path'] for change in self.mr.changes()['changes']]
return self.git_files
@ -134,12 +160,38 @@ class GitLabProvider(GitProvider):
self.mr.description = pr_body
self.mr.save()
except Exception as e:
logging.exception(f"Could not update merge request {self.id_mr} description: {e}")
get_logger().exception(f"Could not update merge request {self.id_mr} description: {e}")
def get_latest_commit_url(self):
return self.mr.commits().next().web_url
def get_comment_url(self, comment):
return f"{self.mr.web_url}#note_{comment.id}"
def publish_persistent_comment(self, pr_comment: str,
initial_header: str,
update_header: bool = True,
name='review',
final_update_message=True):
self.publish_persistent_comment_full(pr_comment, initial_header, update_header, name, final_update_message)
def publish_comment(self, mr_comment: str, is_temporary: bool = False):
comment = self.mr.notes.create({'body': mr_comment})
if is_temporary:
self.temp_comments.append(comment)
return comment
def edit_comment(self, comment, body: str):
self.mr.notes.update(comment.id,{'body': body} )
def edit_comment_from_comment_id(self, comment_id: int, body: str):
comment = self.mr.notes.get(comment_id)
comment.body = body
comment.save()
def reply_to_comment_from_comment_id(self, comment_id: int, body: str):
discussion = self.mr.discussions.get(comment_id)
discussion.notes.create({'body': body})
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
edit_type, found, source_line_no, target_file, target_line_no = self.search_line(relevant_file,
@ -147,21 +199,25 @@ class GitLabProvider(GitProvider):
self.send_inline_comment(body, edit_type, found, relevant_file, relevant_line_in_file, source_line_no,
target_file, target_line_no)
def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str, absolute_position: int = None):
raise NotImplementedError("Gitlab provider does not support creating inline comments yet")
def create_inline_comments(self, comments: list[dict]):
raise NotImplementedError("Gitlab provider does not support publishing inline comments yet")
def get_comment_body_from_comment_id(self, comment_id: int):
comment = self.mr.notes.get(comment_id)
return comment
def send_inline_comment(self,body: str,edit_type: str,found: bool,relevant_file: str,relevant_line_in_file: int,
source_line_no: int, target_file: str,target_line_no: int) -> None:
if not found:
logging.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}")
else:
# in order to have exact sha's we have to find correct diff for this change
diff = self.get_relevant_diff(relevant_file, relevant_line_in_file)
if diff is None:
logger.error(f"Could not get diff for merge request {self.id_mr}")
get_logger().error(f"Could not get diff for merge request {self.id_mr}")
raise DiffNotFoundError(f"Could not get diff for merge request {self.id_mr}")
pos_obj = {'position_type': 'text',
'new_path': target_file.filename,
@ -174,24 +230,27 @@ class GitLabProvider(GitProvider):
else:
pos_obj['new_line'] = target_line_no - 1
pos_obj['old_line'] = source_line_no - 1
logging.debug(f"Creating comment in {self.id_mr} with body {body} and position {pos_obj}")
self.mr.discussions.create({'body': body,
'position': pos_obj})
get_logger().debug(f"Creating comment in {self.id_mr} with body {body} and position {pos_obj}")
try:
self.mr.discussions.create({'body': body, 'position': pos_obj})
except Exception as e:
get_logger().debug(
f"Failed to create comment in {self.id_mr} with position {pos_obj} (probably not a '+' line)")
def get_relevant_diff(self, relevant_file: str, relevant_line_in_file: int) -> Optional[dict]:
changes = self.mr.changes() # Retrieve the changes for the merge request once
if not changes:
logging.error('No changes found for the merge request.')
get_logger().error('No changes found for the merge request.')
return None
all_diffs = self.mr.diffs.list(get_all=True)
if not all_diffs:
logging.error('No diffs found for the merge request.')
get_logger().error('No diffs found for the merge request.')
return None
for diff in all_diffs:
for change in changes['changes']:
if change['new_path'] == relevant_file and relevant_line_in_file in change['diff']:
return diff
logging.debug(
get_logger().debug(
f'No relevant diff found for {relevant_file} {relevant_line_in_file}. Falling back to last diff.')
return self.last_diff # fallback to last_diff if no relevant diff is found
@ -226,7 +285,10 @@ class GitLabProvider(GitProvider):
self.send_inline_comment(body, edit_type, found, relevant_file, relevant_line_in_file, source_line_no,
target_file, target_line_no)
except Exception as e:
logging.exception(f"Could not publish code suggestion:\nsuggestion: {suggestion}\nerror: {e}")
get_logger().exception(f"Could not publish code suggestion:\nsuggestion: {suggestion}\nerror: {e}")
# note that we publish suggestions one-by-one. so, if one fails, the rest will still be published
return True
def search_line(self, relevant_file, relevant_line_in_file):
target_file = None
@ -285,9 +347,15 @@ class GitLabProvider(GitProvider):
def remove_initial_comment(self):
try:
for comment in self.temp_comments:
comment.delete()
self.remove_comment(comment)
except Exception as e:
logging.exception(f"Failed to remove temp comments, error: {e}")
get_logger().exception(f"Failed to remove temp comments, error: {e}")
def remove_comment(self, comment):
try:
comment.delete()
except Exception as e:
get_logger().exception(f"Failed to remove comment, error: {e}")
def get_title(self):
return self.mr.title
@ -303,16 +371,16 @@ class GitLabProvider(GitProvider):
return self.mr.description
def get_issue_comments(self):
raise NotImplementedError("GitLab provider does not support issue comments yet")
return self.mr.notes.list(get_all=True)[::-1]
def get_repo_settings(self):
try:
contents = self.gl.projects.get(self.id_project).files.get(file_path='.pr_agent.toml', ref=self.mr.source_branch)
contents = self.gl.projects.get(self.id_project).files.get(file_path='.pr_agent.toml', ref=self.mr.target_branch).decode()
return contents
except Exception:
return ""
def add_eyes_reaction(self, issue_comment_id: int) -> Optional[int]:
def add_eyes_reaction(self, issue_comment_id: int, disable_eyes: bool = False) -> Optional[int]:
return True
def remove_reaction(self, issue_comment_id: int, reaction_id: int) -> bool:
@ -355,14 +423,17 @@ class GitLabProvider(GitProvider):
self.mr.labels = list(set(pr_types))
self.mr.save()
except Exception as e:
logging.exception(f"Failed to publish labels, error: {e}")
get_logger().exception(f"Failed to publish labels, error: {e}")
def publish_inline_comments(self, comments: list[dict]):
pass
def get_labels(self):
def get_pr_labels(self, update=False):
return self.mr.labels
def get_repo_labels(self):
return self.gl.projects.get(self.id_project).labels.list()
def get_commit_messages(self):
"""
Retrieves the commit messages of a pull request.
@ -378,4 +449,45 @@ class GitLabProvider(GitProvider):
commit_messages_str = ""
if max_tokens:
commit_messages_str = clip_tokens(commit_messages_str, max_tokens)
return commit_messages_str
return commit_messages_str
def get_pr_id(self):
try:
pr_id = self.mr.web_url
return pr_id
except:
return ""
def get_line_link(self, relevant_file: str, relevant_line_start: int, relevant_line_end: int = None) -> str:
if relevant_line_start == -1:
link = f"{self.gl.url}/{self.id_project}/-/blob/{self.mr.source_branch}/{relevant_file}?ref_type=heads"
elif relevant_line_end:
link = f"{self.gl.url}/{self.id_project}/-/blob/{self.mr.source_branch}/{relevant_file}?ref_type=heads#L{relevant_line_start}-L{relevant_line_end}"
else:
link = f"{self.gl.url}/{self.id_project}/-/blob/{self.mr.source_branch}/{relevant_file}?ref_type=heads#L{relevant_line_start}"
return link
def generate_link_to_relevant_line_number(self, suggestion) -> str:
try:
relevant_file = suggestion['relevant_file'].strip('`').strip("'").rstrip()
relevant_line_str = suggestion['relevant_line'].rstrip()
if not relevant_line_str:
return ""
position, absolute_position = find_line_number_of_relevant_line_in_file \
(self.diff_files, relevant_file, relevant_line_str)
if absolute_position != -1:
# link to right file only
link = f"{self.gl.url}/{self.id_project}/-/blob/{self.mr.source_branch}/{relevant_file}?ref_type=heads#L{absolute_position}"
# # link to diff
# sha_file = hashlib.sha1(relevant_file.encode('utf-8')).hexdigest()
# link = f"{self.pr.web_url}/diffs#{sha_file}_{absolute_position}_{absolute_position}"
return link
except Exception as e:
if get_settings().config.verbosity_level >= 2:
get_logger().info(f"Failed adding line link, error: {e}")
return ""

View File

@ -1,4 +1,3 @@
import logging
from collections import Counter
from pathlib import Path
from typing import List
@ -6,7 +5,9 @@ from typing import List
from git import Repo
from pr_agent.config_loader import _find_repository_root, get_settings
from pr_agent.git_providers.git_provider import EDIT_TYPE, FilePatchInfo, 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
class PullRequestMimic:
@ -49,14 +50,15 @@ class LocalGitProvider(GitProvider):
"""
Prepare the repository for PR-mimic generation.
"""
logging.debug('Preparing repository for PR-mimic generation...')
get_logger().debug('Preparing repository for PR-mimic generation...')
if self.repo.is_dirty():
raise ValueError('The repository is not in a clean state. Please commit or stash pending changes.')
if self.target_branch_name not in self.repo.heads:
raise KeyError(f'Branch: {self.target_branch_name} does not exist')
def is_supported(self, capability: str) -> bool:
if capability in ['get_issue_comments', 'create_inline_comment', 'publish_inline_comments', 'get_labels']:
if capability in ['get_issue_comments', 'create_inline_comment', 'publish_inline_comments', 'get_labels',
'gfm_markdown']:
return False
return True
@ -120,9 +122,6 @@ class LocalGitProvider(GitProvider):
def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
raise NotImplementedError('Publishing inline comments is not implemented for the local git provider')
def create_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str):
raise NotImplementedError('Creating inline comments is not implemented for the local git provider')
def publish_inline_comments(self, comments: list[dict]):
raise NotImplementedError('Publishing inline comments is not implemented for the local git provider')
@ -139,6 +138,9 @@ class LocalGitProvider(GitProvider):
def remove_initial_comment(self):
pass # Not applicable to the local git provider, but required by the interface
def remove_comment(self, comment):
pass # Not applicable to the local git provider, but required by the interface
def get_languages(self):
"""
Calculate percentage of languages in repository. Used for hunk prioritisation.
@ -174,5 +176,5 @@ class LocalGitProvider(GitProvider):
def get_issue_comments(self):
raise NotImplementedError('Getting issue comments is not implemented for the local git provider')
def get_labels(self):
def get_pr_labels(self, update=False):
raise NotImplementedError('Getting labels is not implemented for the local git provider')

View File

@ -0,0 +1,49 @@
import copy
import os
import tempfile
from dynaconf import Dynaconf
from pr_agent.config_loader import get_settings
from pr_agent.git_providers import get_git_provider, get_git_provider_with_context
from pr_agent.log import get_logger
from starlette_context import context
def apply_repo_settings(pr_url):
git_provider = get_git_provider_with_context(pr_url)
if get_settings().config.use_repo_settings_file:
repo_settings_file = None
try:
try:
repo_settings = context.get("repo_settings", None)
except Exception:
repo_settings = None
pass
if repo_settings is None: # None is different from "", which is a valid value
repo_settings = git_provider.get_repo_settings()
try:
context["repo_settings"] = repo_settings
except Exception:
pass
if repo_settings:
repo_settings_file = None
fd, repo_settings_file = tempfile.mkstemp(suffix='.toml')
os.write(fd, repo_settings)
new_settings = Dynaconf(settings_files=[repo_settings_file])
for section, contents in new_settings.as_dict().items():
section_dict = copy.deepcopy(get_settings().as_dict().get(section, {}))
for key, value in contents.items():
section_dict[key] = value
get_settings().unset(section)
get_settings().set(section, section_dict, merge=False)
get_logger().info(f"Applying repo settings:\n{new_settings.as_dict()}")
except Exception as e:
get_logger().exception("Failed to apply repo settings", e)
finally:
if repo_settings_file:
try:
os.remove(repo_settings_file)
except Exception as e:
get_logger().error(f"Failed to remove temporary settings file {repo_settings_file}", e)

View File

@ -0,0 +1,13 @@
from pr_agent.config_loader import get_settings
from pr_agent.identity_providers.default_identity_provider import DefaultIdentityProvider
_IDENTITY_PROVIDERS = {
'default': DefaultIdentityProvider
}
def get_identity_provider():
identity_provider_id = get_settings().get("CONFIG.IDENTITY_PROVIDER", "default")
if identity_provider_id not in _IDENTITY_PROVIDERS:
raise ValueError(f"Unknown identity provider: {identity_provider_id}")
return _IDENTITY_PROVIDERS[identity_provider_id]()

View File

@ -0,0 +1,9 @@
from pr_agent.identity_providers.identity_provider import Eligibility, IdentityProvider
class DefaultIdentityProvider(IdentityProvider):
def verify_eligibility(self, git_provider, git_provider_id, pr_url):
return Eligibility.ELIGIBLE
def inc_invocation_count(self, git_provider, git_provider_id):
pass

View File

@ -0,0 +1,18 @@
from abc import ABC, abstractmethod
from enum import Enum
class Eligibility(Enum):
NOT_ELIGIBLE = 0
ELIGIBLE = 1
TRIAL = 2
class IdentityProvider(ABC):
@abstractmethod
def verify_eligibility(self, git_provider, git_provier_id, pr_url):
pass
@abstractmethod
def inc_invocation_count(self, git_provider, git_provider_id):
pass

65
pr_agent/log/__init__.py Normal file
View File

@ -0,0 +1,65 @@
import json
import logging
import os
import sys
from enum import Enum
from loguru import logger
from pr_agent.config_loader import get_settings
class LoggingFormat(str, Enum):
CONSOLE = "CONSOLE"
JSON = "JSON"
def json_format(record: dict) -> str:
return record["message"]
def analytics_filter(record: dict) -> bool:
return record.get("extra", {}).get("analytics", False)
def inv_analytics_filter(record: dict) -> bool:
return not record.get("extra", {}).get("analytics", False)
def setup_logger(level: str = "INFO", fmt: LoggingFormat = LoggingFormat.CONSOLE):
level: int = logging.getLevelName(level.upper())
if type(level) is not int:
level = logging.INFO
if fmt == LoggingFormat.JSON and os.getenv("LOG_SANE", "0").lower() == "0": # better debugging github_app
logger.remove(None)
logger.add(
sys.stdout,
filter=inv_analytics_filter,
level=level,
format="{message}",
colorize=False,
serialize=True,
)
elif fmt == LoggingFormat.CONSOLE: # does not print the 'extra' fields
logger.remove(None)
logger.add(sys.stdout, level=level, colorize=True, filter=inv_analytics_filter)
log_folder = get_settings().get("CONFIG.ANALYTICS_FOLDER", "")
if log_folder:
pid = os.getpid()
log_file = os.path.join(log_folder, f"pr-agent.{pid}.log")
logger.add(
log_file,
filter=analytics_filter,
level=level,
format="{message}",
colorize=False,
serialize=True,
)
return logger
def get_logger(*args, **kwargs):
return logger

View File

@ -2,15 +2,18 @@ from pr_agent.config_loader import get_settings
def get_secret_provider():
try:
provider_id = get_settings().config.secret_provider
except AttributeError as e:
raise ValueError("secret_provider is a required attribute in the configuration file") from e
try:
if provider_id == 'google_cloud_storage':
if not get_settings().get("CONFIG.SECRET_PROVIDER"):
return None
provider_id = get_settings().config.secret_provider
if provider_id == 'google_cloud_storage':
try:
from pr_agent.secret_providers.google_cloud_storage_secret_provider import GoogleCloudStorageSecretProvider
return GoogleCloudStorageSecretProvider()
else:
raise ValueError(f"Unknown secret provider: {provider_id}")
except Exception as e:
raise ValueError(f"Failed to initialize secret provider {provider_id}") from e
except Exception as e:
raise ValueError(f"Failed to initialize google_cloud_storage secret provider {provider_id}") from e
else:
raise ValueError("Unknown SECRET_PROVIDER")

View File

@ -1,9 +1,8 @@
import ujson
from google.cloud import storage
from pr_agent.config_loader import get_settings
from pr_agent.git_providers.gitlab_provider import logger
from pr_agent.log import get_logger
from pr_agent.secret_providers.secret_provider import SecretProvider
@ -15,7 +14,7 @@ class GoogleCloudStorageSecretProvider(SecretProvider):
self.bucket_name = get_settings().google_cloud_storage.bucket_name
self.bucket = self.client.bucket(self.bucket_name)
except Exception as e:
logger.error(f"Failed to initialize Google Cloud Storage Secret Provider: {e}")
get_logger().error(f"Failed to initialize Google Cloud Storage Secret Provider: {e}")
raise e
def get_secret(self, secret_name: str) -> str:
@ -23,7 +22,7 @@ class GoogleCloudStorageSecretProvider(SecretProvider):
blob = self.bucket.blob(secret_name)
return blob.download_as_string()
except Exception as e:
logger.error(f"Failed to get secret {secret_name} from Google Cloud Storage: {e}")
get_logger().error(f"Failed to get secret {secret_name} from Google Cloud Storage: {e}")
return ""
def store_secret(self, secret_name: str, secret_value: str):
@ -31,5 +30,5 @@ class GoogleCloudStorageSecretProvider(SecretProvider):
blob = self.bucket.blob(secret_name)
blob.upload_from_string(secret_value)
except Exception as e:
logger.error(f"Failed to store secret {secret_name} in Google Cloud Storage: {e}")
get_logger().error(f"Failed to store secret {secret_name} in Google Cloud Storage: {e}")
raise e

View File

View File

@ -0,0 +1,147 @@
# This file contains the code for the Azure DevOps Server webhook server.
# The server listens for incoming webhooks from Azure DevOps Server and forwards them to the PR Agent.
# ADO webhook documentation: https://learn.microsoft.com/en-us/azure/devops/service-hooks/services/webhooks?view=azure-devops
import json
import os
import re
import secrets
from urllib.parse import unquote
import uvicorn
from fastapi import APIRouter, Depends, FastAPI, HTTPException
from fastapi.security import HTTPBasic, HTTPBasicCredentials
from fastapi.encoders import jsonable_encoder
from starlette import status
from starlette.background import BackgroundTasks
from starlette.middleware import Middleware
from starlette.requests import Request
from starlette.responses import JSONResponse
from starlette_context.middleware import RawContextMiddleware
from pr_agent.agent.pr_agent import PRAgent, command2class
from pr_agent.algo.utils import update_settings_from_args
from pr_agent.config_loader import get_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
setup_logger(fmt=LoggingFormat.JSON, level="DEBUG")
security = HTTPBasic()
router = APIRouter()
available_commands_rgx = re.compile(r"^\/(" + "|".join(command2class.keys()) + r")\s*")
azure_devops_server = get_settings().get("azure_devops_server")
WEBHOOK_USERNAME = azure_devops_server.get("webhook_username")
WEBHOOK_PASSWORD = azure_devops_server.get("webhook_password")
def handle_request(
background_tasks: BackgroundTasks, url: str, body: str, log_context: dict
):
log_context["action"] = body
log_context["api_url"] = url
async def inner():
try:
with get_logger().contextualize(**log_context):
await PRAgent().handle_request(url, body)
except Exception as e:
get_logger().error(f"Failed to handle webhook: {e}")
background_tasks.add_task(inner)
# currently only basic auth is supported with azure webhooks
# for this reason, https must be enabled to ensure the credentials are not sent in clear text
def authorize(credentials: HTTPBasicCredentials = Depends(security)):
is_user_ok = secrets.compare_digest(credentials.username, WEBHOOK_USERNAME)
is_pass_ok = secrets.compare_digest(credentials.password, WEBHOOK_PASSWORD)
if not (is_user_ok and is_pass_ok):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail='Incorrect username or password.',
headers={'WWW-Authenticate': 'Basic'},
)
async def _perform_commands_azure(commands_conf: str, agent: PRAgent, api_url: str, log_context: dict):
apply_repo_settings(api_url)
commands = get_settings().get(f"azure_devops_server.{commands_conf}")
for command in commands:
try:
split_command = command.split(" ")
command = split_command[0]
args = split_command[1:]
other_args = update_settings_from_args(args)
new_command = ' '.join([command] + other_args)
get_logger().info(f"Performing command: {new_command}")
with get_logger().contextualize(**log_context):
await agent.handle_request(api_url, new_command)
except Exception as e:
get_logger().error(f"Failed to perform command {command}: {e}")
@router.post("/", dependencies=[Depends(authorize)])
async def handle_webhook(background_tasks: BackgroundTasks, request: Request):
log_context = {"server_type": "azure_devops_server"}
data = await request.json()
get_logger().info(json.dumps(data))
actions = []
if data["eventType"] == "git.pullrequest.created":
# API V1 (latest)
pr_url = unquote(data["resource"]["_links"]["web"]["href"].replace("_apis/git/repositories", "_git"))
log_context["event"] = data["eventType"]
log_context["api_url"] = pr_url
await _perform_commands_azure("pr_commands", PRAgent(), pr_url, log_context)
return
elif data["eventType"] == "ms.vss-code.git-pullrequest-comment-event" and "content" in data["resource"]["comment"]:
if available_commands_rgx.match(data["resource"]["comment"]["content"]):
if(data["resourceVersion"] == "2.0"):
repo = data["resource"]["pullRequest"]["repository"]["webUrl"]
pr_url = unquote(f'{repo}/pullrequest/{data["resource"]["pullRequest"]["pullRequestId"]}')
actions = [data["resource"]["comment"]["content"]]
else:
# API V1 not supported as it does not contain the PR URL
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST,
content=json.dumps({"message": "version 1.0 webhook for Azure Devops PR comment is not supported. please upgrade to version 2.0"})),
else:
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST,
content=json.dumps({"message": "Unsupported command"}),
)
else:
return JSONResponse(
status_code=status.HTTP_204_NO_CONTENT,
content=json.dumps({"message": "Unsupported event"}),
)
log_context["event"] = data["eventType"]
log_context["api_url"] = pr_url
for action in actions:
try:
handle_request(background_tasks, pr_url, action, log_context)
except Exception as e:
get_logger().error("Azure DevOps Trigger failed. Error:" + str(e))
return JSONResponse(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
content=json.dumps({"message": "Internal server error"}),
)
return JSONResponse(
status_code=status.HTTP_202_ACCEPTED, content=jsonable_encoder({"message": "webhook triggered successfully"})
)
@router.get("/")
async def root():
return {"status": "ok"}
def start():
app = FastAPI(middleware=[Middleware(RawContextMiddleware)])
app.include_router(router)
uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", "3000")))
if __name__ == "__main__":
start()

View File

@ -1,9 +1,8 @@
import base64
import copy
import hashlib
import json
import logging
import os
import sys
import time
import jwt
@ -17,12 +16,22 @@ from starlette_context import context
from starlette_context.middleware import RawContextMiddleware
from pr_agent.agent.pr_agent import PRAgent
from pr_agent.algo.utils import update_settings_from_args
from pr_agent.config_loader import get_settings, global_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.identity_provider import Eligibility
from pr_agent.log import LoggingFormat, get_logger, setup_logger
from pr_agent.secret_providers import get_secret_provider
from pr_agent.servers.github_action_runner import get_setting_or_env, is_true
from pr_agent.tools.pr_code_suggestions import PRCodeSuggestions
from pr_agent.tools.pr_description import PRDescription
from pr_agent.tools.pr_reviewer import PRReviewer
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
setup_logger(fmt=LoggingFormat.JSON, level="DEBUG")
router = APIRouter()
secret_provider = get_secret_provider()
secret_provider = get_secret_provider() if get_settings().get("CONFIG.SECRET_PROVIDER") else None
async def get_bearer_token(shared_secret: str, client_key: str):
try:
@ -49,7 +58,7 @@ async def get_bearer_token(shared_secret: str, client_key: str):
bearer_token = response.json()["access_token"]
return bearer_token
except Exception as e:
logging.error(f"Failed to get bearer token: {e}")
get_logger().error(f"Failed to get bearer token: {e}")
raise e
@router.get("/")
@ -60,24 +69,60 @@ async def handle_manifest(request: Request, response: Response):
manifest = manifest.replace("app_key", get_settings().bitbucket.app_key)
manifest = manifest.replace("base_url", get_settings().bitbucket.base_url)
except:
logging.error("Failed to replace api_key in Bitbucket manifest, trying to continue")
get_logger().error("Failed to replace api_key in Bitbucket manifest, trying to continue")
manifest_obj = json.loads(manifest)
return JSONResponse(manifest_obj)
async def _perform_commands_bitbucket(commands_conf: str, agent: PRAgent, api_url: str, log_context: dict):
apply_repo_settings(api_url)
commands = get_settings().get(f"bitbucket_app.{commands_conf}", {})
for command in commands:
try:
split_command = command.split(" ")
command = split_command[0]
args = split_command[1:]
other_args = update_settings_from_args(args)
new_command = ' '.join([command] + other_args)
get_logger().info(f"Performing command: {new_command}")
with get_logger().contextualize(**log_context):
await agent.handle_request(api_url, new_command)
except Exception as e:
get_logger().error(f"Failed to perform command {command}: {e}")
@router.post("/webhook")
async def handle_github_webhooks(background_tasks: BackgroundTasks, request: Request):
print(request.headers)
log_context = {"server_type": "bitbucket_app"}
get_logger().debug(request.headers)
jwt_header = request.headers.get("authorization", None)
if jwt_header:
input_jwt = jwt_header.split(" ")[1]
data = await request.json()
print(data)
get_logger().debug(data)
async def inner():
try:
owner = data["data"]["repository"]["owner"]["username"]
secrets = json.loads(secret_provider.get_secret(owner))
try:
if data["data"]["actor"]["type"] != "user":
return "OK"
except KeyError:
get_logger().error("Failed to get actor type, check previous logs, this shouldn't happen.")
try:
owner = data["data"]["repository"]["owner"]["username"]
except Exception as e:
get_logger().error(f"Failed to get owner, will continue: {e}")
owner = "unknown"
sender_id = data["data"]["actor"]["account_id"]
log_context["sender"] = owner
log_context["sender_id"] = sender_id
jwt_parts = input_jwt.split(".")
claim_part = jwt_parts[1]
claim_part += "=" * (-len(claim_part) % 4)
decoded_claims = base64.urlsafe_b64decode(claim_part)
claims = json.loads(decoded_claims)
client_key = claims["iss"]
secrets = json.loads(secret_provider.get_secret(client_key))
shared_secret = secrets["shared_secret"]
client_key = secrets["client_key"]
jwt.decode(input_jwt, shared_secret, audience=client_key, algorithms=["HS256"])
bearer_token = await get_bearer_token(shared_secret, client_key)
context['bitbucket_bearer_token'] = bearer_token
@ -86,13 +131,36 @@ async def handle_github_webhooks(background_tasks: BackgroundTasks, request: Req
agent = PRAgent()
if event == "pullrequest:created":
pr_url = data["data"]["pullrequest"]["links"]["html"]["href"]
await agent.handle_request(pr_url, "review")
log_context["api_url"] = pr_url
log_context["event"] = "pull_request"
if pr_url:
with get_logger().contextualize(**log_context):
apply_repo_settings(pr_url)
if get_identity_provider().verify_eligibility("bitbucket",
sender_id, pr_url) is not Eligibility.NOT_ELIGIBLE:
if get_settings().get("bitbucket_app.pr_commands"):
await _perform_commands_bitbucket("pr_commands", PRAgent(), pr_url, log_context)
else: # backwards compatibility
auto_review = get_setting_or_env("BITBUCKET_APP.AUTO_REVIEW", None)
if is_true(auto_review): # by default, auto review is disabled
await PRReviewer(pr_url).run()
auto_improve = get_setting_or_env("BITBUCKET_APP.AUTO_IMPROVE", None)
if is_true(auto_improve): # by default, auto improve is disabled
await PRCodeSuggestions(pr_url).run()
auto_describe = get_setting_or_env("BITBUCKET_APP.AUTO_DESCRIBE", None)
if is_true(auto_describe): # by default, auto describe is disabled
await PRDescription(pr_url).run()
elif event == "pullrequest:comment_created":
pr_url = data["data"]["pullrequest"]["links"]["html"]["href"]
log_context["api_url"] = pr_url
log_context["event"] = "comment"
comment_body = data["data"]["comment"]["content"]["raw"]
await agent.handle_request(pr_url, comment_body)
with get_logger().contextualize(**log_context):
if get_identity_provider().verify_eligibility("bitbucket",
sender_id, pr_url) is not Eligibility.NOT_ELIGIBLE:
await agent.handle_request(pr_url, comment_body)
except Exception as e:
logging.error(f"Failed to handle webhook: {e}")
get_logger().error(f"Failed to handle webhook: {e}")
background_tasks.add_task(inner)
return "OK"
@ -103,9 +171,10 @@ async def handle_github_webhooks(request: Request, response: Response):
@router.post("/installed")
async def handle_installed_webhooks(request: Request, response: Response):
try:
print(request.headers)
get_logger().info("handle_installed_webhooks")
get_logger().info(request.headers)
data = await request.json()
print(data)
get_logger().info(data)
shared_secret = data["sharedSecret"]
client_key = data["clientKey"]
username = data["principal"]["username"]
@ -115,13 +184,15 @@ async def handle_installed_webhooks(request: Request, response: Response):
}
secret_provider.store_secret(username, json.dumps(secrets))
except Exception as e:
logging.error(f"Failed to register user: {e}")
get_logger().error(f"Failed to register user: {e}")
return JSONResponse({"error": "Unable to register user"}, status_code=500)
@router.post("/uninstalled")
async def handle_uninstalled_webhooks(request: Request, response: Response):
get_logger().info("handle_uninstalled_webhooks")
data = await request.json()
print(data)
get_logger().info(data)
def start():

View File

@ -0,0 +1,88 @@
import json
import os
import uvicorn
from fastapi import APIRouter, FastAPI
from fastapi.encoders import jsonable_encoder
from starlette import status
from starlette.background import BackgroundTasks
from starlette.middleware import Middleware
from starlette.requests import Request
from starlette.responses import JSONResponse
from starlette_context.middleware import RawContextMiddleware
from pr_agent.agent.pr_agent import PRAgent
from pr_agent.config_loader import get_settings
from pr_agent.log import LoggingFormat, get_logger, setup_logger
from pr_agent.servers.utils import verify_signature
setup_logger(fmt=LoggingFormat.JSON, level="DEBUG")
router = APIRouter()
def handle_request(
background_tasks: BackgroundTasks, url: str, body: str, log_context: dict
):
log_context["action"] = body
log_context["api_url"] = url
async def inner():
try:
with get_logger().contextualize(**log_context):
await PRAgent().handle_request(url, body)
except Exception as e:
get_logger().error(f"Failed to handle webhook: {e}")
background_tasks.add_task(inner)
@router.post("/")
async def handle_webhook(background_tasks: BackgroundTasks, request: Request):
log_context = {"server_type": "bitbucket_server"}
data = await request.json()
get_logger().info(json.dumps(data))
webhook_secret = get_settings().get("BITBUCKET_SERVER.WEBHOOK_SECRET", None)
if webhook_secret:
body_bytes = await request.body()
signature_header = request.headers.get("x-hub-signature", None)
verify_signature(body_bytes, webhook_secret, signature_header)
pr_id = data["pullRequest"]["id"]
repository_name = data["pullRequest"]["toRef"]["repository"]["slug"]
project_name = data["pullRequest"]["toRef"]["repository"]["project"]["key"]
bitbucket_server = get_settings().get("BITBUCKET_SERVER.URL")
pr_url = f"{bitbucket_server}/projects/{project_name}/repos/{repository_name}/pull-requests/{pr_id}"
log_context["api_url"] = pr_url
log_context["event"] = "pull_request"
if data["eventKey"] == "pr:opened":
body = "review"
elif data["eventKey"] == "pr:comment:added":
body = data["comment"]["text"]
else:
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST,
content=json.dumps({"message": "Unsupported event"}),
)
handle_request(background_tasks, pr_url, body, log_context)
return JSONResponse(
status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})
)
@router.get("/")
async def root():
return {"status": "ok"}
def start():
app = FastAPI(middleware=[Middleware(RawContextMiddleware)])
app.include_router(router)
uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", "3000")))
if __name__ == "__main__":
start()

Some files were not shown because too many files have changed in this diff Show More