123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- def pr_comment(self, comment):
- pr_threads = self.azure_git_client.get_threads(self.azure_repo_id, self.azure_pull_request_id)
- existing_thread = None
- existing_comment = None
- for pr_thread in pr_threads:
- for pr_thread_comment in pr_thread.comments:
- if pr_thread_comment.content and globals.comment_on_pr_header in pr_thread_comment.content:
- existing_thread = pr_thread
- existing_comment = pr_thread_comment
- comments_markdown = f"# {globals.comment_on_pr_header}\n{comment}"
- if len(comments_markdown) > 65535:
- comments_markdown = comments_markdown[:65535]
- if existing_comment is not None:
- globals.printdebug(f"DEBUG: Update/edit existing comment for PR #{self.azure_pull_request_id}\n"
- f"{comments_markdown}")
- pr_thread_comment = Comment()
- pr_thread_comment.parent_comment_id = 0
- pr_thread_comment.content = comments_markdown
- pr_thread_comment.comment_type = 1
- retval = self.azure_git_client.update_comment(pr_thread_comment, self.azure_repo_id,
- self.azure_pull_request_id, existing_thread.id,
- existing_comment.id)
- globals.printdebug(f"DEBUG: Updated thread, retval={retval}")
- else:
- globals.printdebug(f"DEBUG: Create new thread for PR #{self.azure_pull_request_id}")
- pr_thread_comment = Comment()
- pr_thread_comment.parent_comment_id = 0
- pr_thread_comment.content = comments_markdown
- pr_thread_comment.comment_type = 1
- pr_thread = GitPullRequestCommentThread()
- pr_thread.comments = [pr_thread_comment]
- pr_thread.status = 1
- retval = self.azure_git_client.create_thread(pr_thread, self.azure_repo_id, self.azure_pull_request_id)
- globals.printdebug(f"DEBUG: Created thread, retval={retval}")
- return True
|