From 05964be76d5d2ce3c6363e0d80efe25c0785fdf4 Mon Sep 17 00:00:00 2001 From: freeziyou <80776877@qq.com> Date: Sun, 4 Feb 2024 11:46:19 +0800 Subject: [PATCH] add github edit event --- server/tasks/github/issue.py | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/server/tasks/github/issue.py b/server/tasks/github/issue.py index 461f10fa..5214db0c 100644 --- a/server/tasks/github/issue.py +++ b/server/tasks/github/issue.py @@ -35,6 +35,9 @@ def on_issue_comment(data: dict) -> list: case "created": task = on_issue_comment_created.delay(event.model_dump()) return [task.id] + case "edited": + task = on_issue_comment_edited.delay(event.model_dump()) + return [task.id] case _: app.logger.info(f"Unhandled issue event action: {action}") return [] @@ -86,6 +89,52 @@ def on_issue_comment_created(event_dict: dict | list | None) -> list: return [] +@celery.task() +def on_issue_comment_edited(event_dict: dict | list | None) -> list: + """Handle issue comment edited event. + + Send issue card message to Repo Owner. + """ + try: + event = IssueCommentEvent(**event_dict) + except Exception as e: + app.logger.error(f"Failed to parse issue event: {e}") + return [] + + repo = db.session.query(Repo).filter(Repo.repo_id == event.repository.id).first() + if repo: + if hasattr(event.issue, "pull_request") and event.issue.pull_request: + pr = ( + db.session.query(PullRequest) + .filter( + PullRequest.repo_id == repo.id, + PullRequest.pull_request_number == event.issue.number, + ) + .first() + ) + if pr: + task = send_pull_request_comment.delay( + pr.id, event.comment.body, event.sender.login + ) + return [task.id] + else: + issue = ( + db.session.query(Issue) + .filter( + Issue.repo_id == repo.id, + Issue.issue_number == event.issue.number, + ) + .first() + ) + if issue: + task = send_issue_comment.delay( + issue.id, event.comment.body, event.sender.login + ) + return [task.id] + + return [] + + @celery.task() def on_issue(data: dict) -> list: """Parse and handle issue event.