Support adding / removing reaction from comments in GitHub different servers

This commit is contained in:
Ori Kotek
2023-08-07 16:18:08 +03:00
parent 8f751f7371
commit 886139c6b5
7 changed files with 57 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import os
from pr_agent.agent.pr_agent import PRAgent
from pr_agent.config_loader import get_settings
from pr_agent.git_providers import get_git_provider
from pr_agent.tools.pr_reviewer import PRReviewer
@ -61,7 +62,12 @@ async def run_action():
pr_url = event_payload.get("issue", {}).get("pull_request", {}).get("url")
if pr_url:
body = comment_body.strip().lower()
comment_id = event_payload.get("comment", {}).get("id")
provider = get_git_provider()(pr_url=pr_url)
added_reaction = provider.add_eyes_reaction(comment_id)
await PRAgent().handle_request(pr_url, body)
if added_reaction:
provider.remove_reaction(comment_id, added_reaction)
if __name__ == '__main__':

View File

@ -11,6 +11,7 @@ from starlette_context.middleware import RawContextMiddleware
from pr_agent.agent.pr_agent import PRAgent
from pr_agent.config_loader import get_settings, global_settings
from pr_agent.git_providers import get_git_provider
from pr_agent.servers.utils import verify_signature
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
@ -80,7 +81,13 @@ async def handle_request(body: Dict[str, Any]):
return {}
pull_request = body["issue"]["pull_request"]
api_url = pull_request.get("url")
comment_id = body.get("comment", {}).get("id")
provider = get_git_provider()(pr_url=api_url)
added_reaction = provider.add_eyes_reaction(comment_id)
await agent.handle_request(api_url, comment_body)
if added_reaction:
provider.remove_reaction(comment_id, added_reaction)
elif action == "opened" or 'reopened' in action:
pull_request = body.get("pull_request")

View File

@ -98,8 +98,12 @@ async def polling_loop():
if user_tag not in comment_body:
continue
rest_of_comment = comment_body.split(user_tag)[1].strip()
comment_id = comment['id']
git_provider.set_pr(pr_url)
added_reaction = git_provider.add_eyes_reaction(comment_id)
success = await agent.handle_request(pr_url, rest_of_comment)
if added_reaction:
git_provider.remove_reaction(comment_id, added_reaction)
if not success:
git_provider.set_pr(pr_url)
git_provider.publish_comment("### How to use PR-Agent\n" +