diff --git a/pr_agent/git_providers/azuredevops_provider.py b/pr_agent/git_providers/azuredevops_provider.py index 80bf68c5..7524896c 100644 --- a/pr_agent/git_providers/azuredevops_provider.py +++ b/pr_agent/git_providers/azuredevops_provider.py @@ -18,14 +18,10 @@ ADO_APP_CLIENT_DEFAULT_ID = "499b84ac-1321-427f-aa17-267ca6975798/.default" MAX_PR_DESCRIPTION_AZURE_LENGTH = 4000-1 try: - # noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences from azure.devops.connection import Connection # noinspection PyUnresolvedReferences - from azure.devops.v7_1.git.models import (Comment, CommentThread, - GitPullRequest, - GitPullRequestIterationChanges, - GitVersionDescriptor) + from azure.devops.released.git import (Comment, CommentThread, GitPullRequest, GitVersionDescriptor, GitClient) # noinspection PyUnresolvedReferences from azure.identity import DefaultAzureCredential from msrest.authentication import BasicAuthentication @@ -121,31 +117,29 @@ class AzureDevopsProvider(GitProvider): get_logger().warning(f"Azure failed to publish code suggestion, error: {e}") return True - - def get_pr_description_full(self) -> str: return self.pr.description - def edit_comment(self, comment, body: str): + def edit_comment(self, comment: 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"], + thread_id=comment.thread_id, + comment_id=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): + def remove_comment(self, comment: 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"], + thread_id=comment.thread_id, + comment_id=comment.id, project=self.workspace_slug, ) except Exception as e: @@ -378,7 +372,7 @@ class AzureDevopsProvider(GitProvider): get_logger().exception(f"Failed to get diff files, error: {e}") return [] - def publish_comment(self, pr_comment: str, is_temporary: bool = False, thread_context=None): + def publish_comment(self, pr_comment: str, is_temporary: bool = False, thread_context=None) -> Comment: if is_temporary and not get_settings().config.publish_output_progress: get_logger().debug(f"Skipping publish_comment for temporary comment: {pr_comment}") return None @@ -390,10 +384,11 @@ class AzureDevopsProvider(GitProvider): repository_id=self.repo_slug, pull_request_id=self.pr_num, ) - response = {"thread_id": thread_response.id, "comment_id": thread_response.comments[0].id} + created_comment = thread_response.comments[0] + created_comment.thread_id = thread_response.id if is_temporary: - self.temp_comments.append(response) - return response + self.temp_comments.append(created_comment) + return created_comment def publish_description(self, pr_title: str, pr_body: str): if len(pr_body) > MAX_PR_DESCRIPTION_AZURE_LENGTH: @@ -522,7 +517,7 @@ class AzureDevopsProvider(GitProvider): def get_user_id(self): return 0 - def get_issue_comments(self): + def get_issue_comments(self) -> list[Comment]: threads = self.azure_devops_client.get_threads(repository_id=self.repo_slug, pull_request_id=self.pr_num, project=self.workspace_slug) threads.reverse() comment_list = [] @@ -562,7 +557,7 @@ class AzureDevopsProvider(GitProvider): return workspace_slug, repo_slug, pr_number @staticmethod - def _get_azure_devops_client(): + def _get_azure_devops_client() -> GitClient: org = get_settings().azure_devops.get("org", None) pat = get_settings().azure_devops.get("pat", None) diff --git a/pr_agent/git_providers/git_provider.py b/pr_agent/git_providers/git_provider.py index 2895bd55..dfb5b224 100644 --- a/pr_agent/git_providers/git_provider.py +++ b/pr_agent/git_providers/git_provider.py @@ -228,7 +228,7 @@ class GitProvider(ABC): update_header: bool = True, name='review', final_update_message=True): - self.publish_comment(pr_comment) + return self.publish_comment(pr_comment) def publish_persistent_comment_full(self, pr_comment: str, initial_header: str, @@ -250,14 +250,13 @@ class GitProvider(ABC): # 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( + return self.publish_comment( f"**[Persistent {name}]({comment_url})** updated to latest commit {latest_commit_url}") - return + return comment except Exception as e: get_logger().exception(f"Failed to update persistent review, error: {e}") pass - self.publish_comment(pr_comment) - + return self.publish_comment(pr_comment) @abstractmethod def publish_inline_comment(self, body: str, relevant_file: str, relevant_line_in_file: str, original_suggestion=None):