classAzureProvider_6.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. def pr_comment(self, comment):
  2. pr_threads = self.azure_git_client.get_threads(self.azure_repo_id, self.azure_pull_request_id)
  3. existing_thread = None
  4. existing_comment = None
  5. for pr_thread in pr_threads:
  6. for pr_thread_comment in pr_thread.comments:
  7. if pr_thread_comment.content and globals.comment_on_pr_header in pr_thread_comment.content:
  8. existing_thread = pr_thread
  9. existing_comment = pr_thread_comment
  10. comments_markdown = f"# {globals.comment_on_pr_header}\n{comment}"
  11. if len(comments_markdown) > 65535:
  12. comments_markdown = comments_markdown[:65535]
  13. if existing_comment is not None:
  14. globals.printdebug(f"DEBUG: Update/edit existing comment for PR #{self.azure_pull_request_id}\n"
  15. f"{comments_markdown}")
  16. pr_thread_comment = Comment()
  17. pr_thread_comment.parent_comment_id = 0
  18. pr_thread_comment.content = comments_markdown
  19. pr_thread_comment.comment_type = 1
  20. retval = self.azure_git_client.update_comment(pr_thread_comment, self.azure_repo_id,
  21. self.azure_pull_request_id, existing_thread.id,
  22. existing_comment.id)
  23. globals.printdebug(f"DEBUG: Updated thread, retval={retval}")
  24. else:
  25. globals.printdebug(f"DEBUG: Create new thread for PR #{self.azure_pull_request_id}")
  26. pr_thread_comment = Comment()
  27. pr_thread_comment.parent_comment_id = 0
  28. pr_thread_comment.content = comments_markdown
  29. pr_thread_comment.comment_type = 1
  30. pr_thread = GitPullRequestCommentThread()
  31. pr_thread.comments = [pr_thread_comment]
  32. pr_thread.status = 1
  33. retval = self.azure_git_client.create_thread(pr_thread, self.azure_repo_id, self.azure_pull_request_id)
  34. globals.printdebug(f"DEBUG: Created thread, retval={retval}")
  35. return True