From 09b0a04a472e4f3805d61a85152a77a7a4aaabb5 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Tue, 10 Sep 2024 20:06:48 +0300 Subject: [PATCH] docs and fixes --- .../core-abilities/static_code_analysis.md | 70 ++++++++++++++++++- docs/docs/tools/analyze.md | 2 +- docs/docs/tools/test.md | 6 +- pr_agent/algo/utils.py | 5 +- pr_agent/servers/github_polling.py | 4 +- 5 files changed, 77 insertions(+), 10 deletions(-) diff --git a/docs/docs/core-abilities/static_code_analysis.md b/docs/docs/core-abilities/static_code_analysis.md index 9e5276f7c..b33c2c5d0 100644 --- a/docs/docs/core-abilities/static_code_analysis.md +++ b/docs/docs/core-abilities/static_code_analysis.md @@ -1,2 +1,70 @@ ## Overview - Static Code Analysis 💎 -TBD + +By combining static code analysis with LLM capabilities, PR-Agent can provide a comprehensive analysis of the PR code changes on a component level. + +It scans the PR code changes, finds all the code components (methods, functions, classes) that changed, and enables to interactively generate tests, docs, code suggestions and similar code search for each component. + +!!! note "Language that are currently supported:" + Python, Java, C++, JavaScript, TypeScript, C#. + + +## Capabilities + +### Analyze PR + + +The [`analyze`](https://pr-agent-docs.codium.ai/tools/analyze/) tool enables to interactively generate tests, docs, code suggestions and similar code search for each component that changed in the PR. +It can be invoked manually by commenting on any PR: +``` +/analyze +``` + +An example result: + +![Analyze 1](https://codium.ai/images/pr_agent/analyze_1.png){width=768} + +Clicking on each checkbox will trigger the relevant tool for the selected component. + +### Generate Tests + +The [`test`](https://pr-agent-docs.codium.ai/tools/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, Or be triggered interactively by using the `analyze` tool. + +![test1](https://codium.ai/images/pr_agent/test1.png){width=768} + +### Generate Docs for a Component + +The [`add_docs`](https://pr-agent-docs.codium.ai/tools/documentation/) tool scans the PR code changes, and automatically generate docstrings for any code components that changed in the PR. +It can be invoked manually by commenting on any PR: +``` +/add_docs component_name +``` + +Or be triggered interactively by using the `analyze` tool. + +![Docs single component](https://codium.ai/images/pr_agent/docs_single_component.png){width=768} + +### Generate Code Suggestions for a Component +The [`improve_component`](https://pr-agent-docs.codium.ai/tools/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 +``` + +Or be triggered interactively by using the `analyze` tool. + +![improve_component2](https://codium.ai/images/pr_agent/improve_component2.png){width=768} + +### Find Similar Code + +The [`similar code`](https://pr-agent-docs.codium.ai/tools/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} diff --git a/docs/docs/tools/analyze.md b/docs/docs/tools/analyze.md index 68bf674b0..05458b132 100644 --- a/docs/docs/tools/analyze.md +++ b/docs/docs/tools/analyze.md @@ -1,7 +1,7 @@ ## 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. +The tool scans the PR code changes, finds 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: ``` diff --git a/docs/docs/tools/test.md b/docs/docs/tools/test.md index dc93e55ca..b5a143f06 100644 --- a/docs/docs/tools/test.md +++ b/docs/docs/tools/test.md @@ -10,14 +10,10 @@ To get a list of the components that changed in the PR and choose the relevant c ## 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} +![test1](https://codium.ai/images/pr_agent/test1.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)): diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 9dcf6f47d..08401514a 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -938,7 +938,10 @@ def is_value_no(value): return False -def process_description(description_full: str): +def process_description(description_full: str) -> Tuple[str, List]: + if not description_full: + return "", [] + split_str = "### **Changes walkthrough** 📝" description_split = description_full.split(split_str) base_description_str = description_split[0] diff --git a/pr_agent/servers/github_polling.py b/pr_agent/servers/github_polling.py index 8750f7779..de1a9f529 100644 --- a/pr_agent/servers/github_polling.py +++ b/pr_agent/servers/github_polling.py @@ -79,8 +79,8 @@ async def is_valid_notification(notification, headers, handled_ids, session, use pr_url = notification['subject']['url'] latest_comment = notification['subject']['latest_comment_url'] if not latest_comment or not isinstance(latest_comment, str): - get_logger().debug(f"not latest_comment, but its ok") - # continue + get_logger().debug(f"no latest_comment") + return False, handled_ids async with session.get(latest_comment, headers=headers) as comment_response: check_prev_comments = False if comment_response.status == 200: