mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-12-12 10:55:17 +00:00
Merge pull request #1998 from LawrenceMantin/main
Adds a new configuration group [azure_devops] to allow "active" comments
This commit is contained in:
commit
aafa835137
3 changed files with 64 additions and 1 deletions
|
|
@ -351,7 +351,9 @@ class AzureDevopsProvider(GitProvider):
|
||||||
get_logger().debug(f"Skipping publish_comment for temporary comment: {pr_comment}")
|
get_logger().debug(f"Skipping publish_comment for temporary comment: {pr_comment}")
|
||||||
return None
|
return None
|
||||||
comment = Comment(content=pr_comment)
|
comment = Comment(content=pr_comment)
|
||||||
thread = CommentThread(comments=[comment], thread_context=thread_context, status="closed")
|
|
||||||
|
status = get_settings().azure_devops.get("default_comment_status", "closed")
|
||||||
|
thread = CommentThread(comments=[comment], thread_context=thread_context, status=status)
|
||||||
thread_response = self.azure_devops_client.create_thread(
|
thread_response = self.azure_devops_client.create_thread(
|
||||||
comment_thread=thread,
|
comment_thread=thread,
|
||||||
project=self.workspace_slug,
|
project=self.workspace_slug,
|
||||||
|
|
|
||||||
|
|
@ -373,6 +373,8 @@ extra_instructions = "" # public - extra instructions to the auto best practices
|
||||||
content = ""
|
content = ""
|
||||||
max_patterns = 5 # max number of patterns to be detected
|
max_patterns = 5 # max number of patterns to be detected
|
||||||
|
|
||||||
|
[azure_devops]
|
||||||
|
default_comment_status = "closed"
|
||||||
|
|
||||||
[azure_devops_server]
|
[azure_devops_server]
|
||||||
pr_commands = [
|
pr_commands = [
|
||||||
|
|
|
||||||
59
tests/unittest/test_azure_devops_comment.py
Normal file
59
tests/unittest/test_azure_devops_comment.py
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
import unittest
|
||||||
|
from pr_agent.config_loader import get_settings
|
||||||
|
from unittest.mock import patch, MagicMock
|
||||||
|
from pr_agent.git_providers import AzureDevopsProvider
|
||||||
|
|
||||||
|
class TestAzureDevopsProviderPublishComment(unittest.TestCase):
|
||||||
|
@patch("pr_agent.git_providers.azuredevops_provider.get_settings")
|
||||||
|
def test_publish_comment_default_closed(self, mock_get_settings):
|
||||||
|
# Simulate config with no default_comment_status
|
||||||
|
mock_settings = MagicMock()
|
||||||
|
mock_settings.azure_devops.default_comment_status = None
|
||||||
|
mock_settings.config.publish_output_progress = True
|
||||||
|
mock_get_settings.return_value = mock_settings
|
||||||
|
|
||||||
|
with patch.object(AzureDevopsProvider, "_get_azure_devops_client", return_value=(MagicMock(), MagicMock())):
|
||||||
|
provider = AzureDevopsProvider()
|
||||||
|
provider.workspace_slug = "ws"
|
||||||
|
provider.repo_slug = "repo"
|
||||||
|
provider.pr_num = 1
|
||||||
|
|
||||||
|
# Patch CommentThread and create_thread
|
||||||
|
with patch("pr_agent.git_providers.azuredevops_provider.CommentThread") as MockThread:
|
||||||
|
provider.azure_devops_client.create_thread.return_value.comments = [MagicMock()]
|
||||||
|
provider.azure_devops_client.create_thread.return_value.comments[0].thread_id = 123
|
||||||
|
provider.azure_devops_client.create_thread.return_value.id = 123
|
||||||
|
|
||||||
|
provider.publish_comment("test comment")
|
||||||
|
args, kwargs = MockThread.call_args
|
||||||
|
assert kwargs.get("status") == "closed"
|
||||||
|
|
||||||
|
@patch("pr_agent.git_providers.azuredevops_provider.get_settings")
|
||||||
|
def test_publish_comment_active(self, mock_get_settings):
|
||||||
|
# Simulate config with default_comment_status = "active"
|
||||||
|
mock_settings = MagicMock()
|
||||||
|
mock_settings.azure_devops.default_comment_status = "active"
|
||||||
|
mock_settings.config.publish_output_progress = True
|
||||||
|
mock_get_settings.return_value = mock_settings
|
||||||
|
|
||||||
|
with patch.object(AzureDevopsProvider, "_get_azure_devops_client", return_value=(MagicMock(), MagicMock())):
|
||||||
|
provider = AzureDevopsProvider()
|
||||||
|
provider.workspace_slug = "ws"
|
||||||
|
provider.repo_slug = "repo"
|
||||||
|
provider.pr_num = 1
|
||||||
|
|
||||||
|
# Patch CommentThread and create_thread
|
||||||
|
with patch("pr_agent.git_providers.azuredevops_provider.CommentThread") as MockThread:
|
||||||
|
provider.azure_devops_client.create_thread.return_value.comments = [MagicMock()]
|
||||||
|
provider.azure_devops_client.create_thread.return_value.comments[0].thread_id = 123
|
||||||
|
provider.azure_devops_client.create_thread.return_value.id = 123
|
||||||
|
|
||||||
|
provider.publish_comment("test comment")
|
||||||
|
args, kwargs = MockThread.call_args
|
||||||
|
assert kwargs.get("status") == "active"
|
||||||
|
|
||||||
|
def test_default_comment_status_from_config_file(self):
|
||||||
|
# Import get_settings directly to read from configuration.toml
|
||||||
|
status = get_settings().azure_devops.default_comment_status
|
||||||
|
# The expected value should match what's in your configuration.toml
|
||||||
|
self.assertEqual(status, "closed")
|
||||||
Loading…
Reference in a new issue