From e925f31ac00ab60eb5e7fa28611ed559c5aa7123 Mon Sep 17 00:00:00 2001 From: cdornano <156191933+cdornano@users.noreply.github.com> Date: Fri, 21 Mar 2025 12:57:03 +0000 Subject: [PATCH 1/4] Update azuredevops_provider.py Will make qodo agent comments "Active" by default, and not "ByDesign" which is renders to "unknown" on Azure DevOps PRs. With this, PR authors are obliged to treat the PR comment of the qodo agent before Merging. This will help companies in analysing the impact of qodo agent on their PR, as every comment needs to be treated as either "Resolved" "Won't fix" "Close" --- pr_agent/git_providers/azuredevops_provider.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_agent/git_providers/azuredevops_provider.py b/pr_agent/git_providers/azuredevops_provider.py index e305d7c2..2e1c57b6 100644 --- a/pr_agent/git_providers/azuredevops_provider.py +++ b/pr_agent/git_providers/azuredevops_provider.py @@ -383,7 +383,7 @@ class AzureDevopsProvider(GitProvider): get_logger().debug(f"Skipping publish_comment for temporary comment: {pr_comment}") return None comment = Comment(content=pr_comment) - thread = CommentThread(comments=[comment], thread_context=thread_context, status=5) + 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, From dde362bd4736956d719056fe369acd74f40a478d Mon Sep 17 00:00:00 2001 From: Slava Eliseev Date: Sat, 22 Mar 2025 00:48:25 +0300 Subject: [PATCH 2/4] doc: Add info about ollama context length --- docs/docs/usage-guide/changing_a_model.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/docs/usage-guide/changing_a_model.md b/docs/docs/usage-guide/changing_a_model.md index 844cd6a5..cc4bd253 100644 --- a/docs/docs/usage-guide/changing_a_model.md +++ b/docs/docs/usage-guide/changing_a_model.md @@ -54,6 +54,10 @@ duplicate_examples=true # will duplicate the examples in the prompt, to help the api_base = "http://localhost:11434" # or whatever port you're running Ollama on ``` +By default, Ollama uses a context window size of 2048 tokens. In most cases this is not enough to cover pr-agent promt and pull-request diff. Context window size can be overridden with the `OLLAMA_CONTEXT_LENGTH` environment variable. For example, to set the default context length to 8K, use: `OLLAMA_CONTEXT_LENGTH=8192 ollama serve`. More information you can find on the [official ollama faq](https://github.com/ollama/ollama/blob/main/docs/faq.md#how-can-i-specify-the-context-window-size). + +Please note that the `custom_model_max_tokens` setting should be configured in accordance with the `OLLAMA_CONTEXT_LENGTH`. Failure to do so may result in unexpected model output. + !!! note "Local models vs commercial models" Qodo Merge is compatible with almost any AI model, but analyzing complex code repositories and pull requests requires a model specifically optimized for code analysis. From 6efb6949451512ee8995e3a231c0c4a9e9963dfc Mon Sep 17 00:00:00 2001 From: Tal Date: Sun, 23 Mar 2025 09:07:01 +0200 Subject: [PATCH 3/4] Generated best practices file --- best_practices.md | 147 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 best_practices.md diff --git a/best_practices.md b/best_practices.md new file mode 100644 index 00000000..19eee22d --- /dev/null +++ b/best_practices.md @@ -0,0 +1,147 @@ + +Pattern 1: Use proper error handling with get_logger() instead of print statements for consistent logging throughout the codebase. + + +Example code before: +``` +try: + # Some code that might fail + result = process_data() +except Exception as e: + print(f"Failed to process data: {e}") +``` + +Example code after: +``` +try: + # Some code that might fail + result = process_data() +except Exception as e: + get_logger().error(f"Failed to process data", artifact={"error": str(e)}) +``` + +
Relevant past discussions: +- https://github.com/qodo-ai/pr-agent/pull/1529#discussion_r1958684550 +- https://github.com/qodo-ai/pr-agent/pull/1529#discussion_r1958686068 +- https://github.com/qodo-ai/pr-agent/pull/1529#discussion_r1964110734 +- https://github.com/qodo-ai/pr-agent/pull/1529#discussion_r1964107962 +
+ + +Pattern 2: Add defensive null/type checking for dictionary access to prevent potential runtime errors, especially when working with API responses or user inputs. + + +Example code before: +``` +if suggestion.get('score') >= threshold and suggestion.get('improved_code'): + process_suggestion(suggestion) +``` + +Example code after: +``` +if suggestion.get('score') is not None and suggestion.get('improved_code') and int(suggestion['score']) >= threshold: + process_suggestion(suggestion) +``` + +
Relevant past discussions: +- https://github.com/qodo-ai/pr-agent/pull/1391#discussion_r1879875496 +- https://github.com/qodo-ai/pr-agent/pull/1290#discussion_r1798939921 +- https://github.com/qodo-ai/pr-agent/pull/1391#discussion_r1879875489 +
+ + +Pattern 3: Add descriptive comments for complex logic or non-obvious code to improve maintainability and help future developers understand the purpose of the code. + + +Example code before: +``` +if not issue or not isinstance(issue, dict): + continue +``` + +Example code after: +``` +# Skip empty issues or non-dictionary items to ensure valid data structure +if not issue or not isinstance(issue, dict): + continue +``` + +
Relevant past discussions: +- https://github.com/qodo-ai/pr-agent/pull/1262#discussion_r1782097205 +- https://github.com/qodo-ai/pr-agent/pull/1583#discussion_r1971790979 +
+ + +Pattern 4: Wrap API calls and external service interactions with proper try-except blocks and add specific error handling for different failure scenarios. + + +Example code before: +``` +data_above_threshold = {'code_suggestions': []} +for suggestion in data['code_suggestions']: + if int(suggestion.get('score', 0)) >= threshold: + data_above_threshold['code_suggestions'].append(suggestion) +self.push_inline_code_suggestions(data_above_threshold) +``` + +Example code after: +``` +data_above_threshold = {'code_suggestions': []} +try: + for suggestion in data['code_suggestions']: + if int(suggestion.get('score', 0)) >= threshold: + data_above_threshold['code_suggestions'].append(suggestion) + if data_above_threshold['code_suggestions']: + self.push_inline_code_suggestions(data_above_threshold) +except Exception as e: + get_logger().error(f"Failed to publish suggestions, error: {e}") +``` + +
Relevant past discussions: +- https://github.com/qodo-ai/pr-agent/pull/1391#discussion_r1879870807 +- https://github.com/qodo-ai/pr-agent/pull/1263#discussion_r1782129216 +
+ + +Pattern 5: Use consistent formatting and capitalization in documentation, especially in field descriptions and configuration comments, to improve readability. + + +Example code before: +``` +class ConfigFields(BaseModel): + field_one: str = Field(description="the first field that does something") + field_two: str = Field(description="The second field for another purpose") +``` + +Example code after: +``` +class ConfigFields(BaseModel): + field_one: str = Field(description="The first field that does something") + field_two: str = Field(description="The second field for another purpose") +``` + +
Relevant past discussions: +- https://github.com/qodo-ai/pr-agent/pull/1262#discussion_r1782097204 +- https://github.com/qodo-ai/pr-agent/pull/1543#discussion_r1958093666 +
+ + +Pattern 6: Fix typos and grammatical errors in documentation, comments, and user-facing messages to maintain professionalism and clarity. + + +Example code before: +``` +# Create a webhook in GitLab. Set the URL to http[s]:///webhook, the secret token to the generated secret from step 2, andenable the triggers. +``` + +Example code after: +``` +# Create a webhook in GitLab. Set the URL to http[s]:///webhook, the secret token to the generated secret from step 2, and enable the triggers. +``` + +
Relevant past discussions: +- https://github.com/qodo-ai/pr-agent/pull/1307#discussion_r1817699788 +- https://github.com/qodo-ai/pr-agent/pull/1307#discussion_r1817699656 +- https://github.com/qodo-ai/pr-agent/pull/1517#discussion_r1942896094 +
+ From ad17cb4d925ccef98eb5109ac4bf45d309c7557b Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 23 Mar 2025 09:26:44 +0200 Subject: [PATCH 4/4] cleanup --- best_practices.md | 147 ---------------------------------------------- 1 file changed, 147 deletions(-) delete mode 100644 best_practices.md diff --git a/best_practices.md b/best_practices.md deleted file mode 100644 index 19eee22d..00000000 --- a/best_practices.md +++ /dev/null @@ -1,147 +0,0 @@ - -Pattern 1: Use proper error handling with get_logger() instead of print statements for consistent logging throughout the codebase. - - -Example code before: -``` -try: - # Some code that might fail - result = process_data() -except Exception as e: - print(f"Failed to process data: {e}") -``` - -Example code after: -``` -try: - # Some code that might fail - result = process_data() -except Exception as e: - get_logger().error(f"Failed to process data", artifact={"error": str(e)}) -``` - -
Relevant past discussions: -- https://github.com/qodo-ai/pr-agent/pull/1529#discussion_r1958684550 -- https://github.com/qodo-ai/pr-agent/pull/1529#discussion_r1958686068 -- https://github.com/qodo-ai/pr-agent/pull/1529#discussion_r1964110734 -- https://github.com/qodo-ai/pr-agent/pull/1529#discussion_r1964107962 -
- - -Pattern 2: Add defensive null/type checking for dictionary access to prevent potential runtime errors, especially when working with API responses or user inputs. - - -Example code before: -``` -if suggestion.get('score') >= threshold and suggestion.get('improved_code'): - process_suggestion(suggestion) -``` - -Example code after: -``` -if suggestion.get('score') is not None and suggestion.get('improved_code') and int(suggestion['score']) >= threshold: - process_suggestion(suggestion) -``` - -
Relevant past discussions: -- https://github.com/qodo-ai/pr-agent/pull/1391#discussion_r1879875496 -- https://github.com/qodo-ai/pr-agent/pull/1290#discussion_r1798939921 -- https://github.com/qodo-ai/pr-agent/pull/1391#discussion_r1879875489 -
- - -Pattern 3: Add descriptive comments for complex logic or non-obvious code to improve maintainability and help future developers understand the purpose of the code. - - -Example code before: -``` -if not issue or not isinstance(issue, dict): - continue -``` - -Example code after: -``` -# Skip empty issues or non-dictionary items to ensure valid data structure -if not issue or not isinstance(issue, dict): - continue -``` - -
Relevant past discussions: -- https://github.com/qodo-ai/pr-agent/pull/1262#discussion_r1782097205 -- https://github.com/qodo-ai/pr-agent/pull/1583#discussion_r1971790979 -
- - -Pattern 4: Wrap API calls and external service interactions with proper try-except blocks and add specific error handling for different failure scenarios. - - -Example code before: -``` -data_above_threshold = {'code_suggestions': []} -for suggestion in data['code_suggestions']: - if int(suggestion.get('score', 0)) >= threshold: - data_above_threshold['code_suggestions'].append(suggestion) -self.push_inline_code_suggestions(data_above_threshold) -``` - -Example code after: -``` -data_above_threshold = {'code_suggestions': []} -try: - for suggestion in data['code_suggestions']: - if int(suggestion.get('score', 0)) >= threshold: - data_above_threshold['code_suggestions'].append(suggestion) - if data_above_threshold['code_suggestions']: - self.push_inline_code_suggestions(data_above_threshold) -except Exception as e: - get_logger().error(f"Failed to publish suggestions, error: {e}") -``` - -
Relevant past discussions: -- https://github.com/qodo-ai/pr-agent/pull/1391#discussion_r1879870807 -- https://github.com/qodo-ai/pr-agent/pull/1263#discussion_r1782129216 -
- - -Pattern 5: Use consistent formatting and capitalization in documentation, especially in field descriptions and configuration comments, to improve readability. - - -Example code before: -``` -class ConfigFields(BaseModel): - field_one: str = Field(description="the first field that does something") - field_two: str = Field(description="The second field for another purpose") -``` - -Example code after: -``` -class ConfigFields(BaseModel): - field_one: str = Field(description="The first field that does something") - field_two: str = Field(description="The second field for another purpose") -``` - -
Relevant past discussions: -- https://github.com/qodo-ai/pr-agent/pull/1262#discussion_r1782097204 -- https://github.com/qodo-ai/pr-agent/pull/1543#discussion_r1958093666 -
- - -Pattern 6: Fix typos and grammatical errors in documentation, comments, and user-facing messages to maintain professionalism and clarity. - - -Example code before: -``` -# Create a webhook in GitLab. Set the URL to http[s]:///webhook, the secret token to the generated secret from step 2, andenable the triggers. -``` - -Example code after: -``` -# Create a webhook in GitLab. Set the URL to http[s]:///webhook, the secret token to the generated secret from step 2, and enable the triggers. -``` - -
Relevant past discussions: -- https://github.com/qodo-ai/pr-agent/pull/1307#discussion_r1817699788 -- https://github.com/qodo-ai/pr-agent/pull/1307#discussion_r1817699656 -- https://github.com/qodo-ai/pr-agent/pull/1517#discussion_r1942896094 -
-