Refactor reaction handling in GitHub provider and update help text in PR tools

This commit is contained in:
mrT23
2024-02-20 08:06:33 +02:00
parent 6eca495801
commit 4a0b12c036
6 changed files with 16 additions and 17 deletions

View File

@ -347,7 +347,7 @@ class AzureDevopsProvider(GitProvider):
def publish_description(self, pr_title: str, pr_body: str):
if len(pr_body) > MAX_PR_DESCRIPTION_AZURE_LENGTH:
usage_guide_text='<details> <summary><strong>✨ Usage guide:</strong></summary><hr>'
usage_guide_text='<details> <summary><strong>✨ Describe tool usage guide:</strong></summary><hr>'
ind = pr_body.find(usage_guide_text)
if ind != -1:
pr_body = pr_body[:ind]

View File

@ -456,28 +456,27 @@ class GithubProvider(GitProvider):
if disable_eyes:
return None
try:
reaction = self.pr.get_issue_comment(issue_comment_id).create_reaction("eyes")
return reaction.id
headers, data_patch = self.pr._requester.requestJsonAndCheck(
"POST", f"https://api.github.com/repos/{self.repo}/issues/comments/{issue_comment_id}/reactions",
input={"content": "eyes"}
)
return data_patch.get("id", None)
except Exception as e:
get_logger().exception(f"Failed to add eyes reaction, error: {e}")
try:
headers, data_patch = self.pr._requester.requestJsonAndCheck(
"POST", f"https://api.github.com/repos/{self.repo}/pulls/comments/{issue_comment_id}/reactions",
input={"content": "eyes"}
)
except:
pass
return None
def remove_reaction(self, issue_comment_id: int, reaction_id: int) -> bool:
def remove_reaction(self, issue_comment_id: int, reaction_id: str) -> bool:
try:
self.pr.get_issue_comment(issue_comment_id).delete_reaction(reaction_id)
# self.pr.get_issue_comment(issue_comment_id).delete_reaction(reaction_id)
headers, data_patch = self.pr._requester.requestJsonAndCheck(
"DELETE",
f"https://api.github.com/repos/{self.repo}/issues/comments/{issue_comment_id}/reactions/{reaction_id}"
)
return True
except Exception as e:
get_logger().exception(f"Failed to remove eyes reaction, error: {e}")
return False
@staticmethod
def _parse_pr_url(pr_url: str) -> Tuple[str, int]:
parsed_url = urlparse(pr_url)