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 1/3] 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. From ef80840df1314de546b7593ac283cdf8319bbb28 Mon Sep 17 00:00:00 2001 From: freeziyou <80776877@qq.com> Date: Sun, 4 Feb 2024 11:51:58 +0800 Subject: [PATCH 2/3] add github edit event --- server/tasks/github/issue.py | 51 +++--------------------------------- 1 file changed, 4 insertions(+), 47 deletions(-) diff --git a/server/tasks/github/issue.py b/server/tasks/github/issue.py index 5214db0c..6bc18f1b 100644 --- a/server/tasks/github/issue.py +++ b/server/tasks/github/issue.py @@ -36,7 +36,7 @@ def on_issue_comment(data: dict) -> list: task = on_issue_comment_created.delay(event.model_dump()) return [task.id] case "edited": - task = on_issue_comment_edited.delay(event.model_dump()) + task = on_issue_comment_created.delay(event.model_dump()) return [task.id] case _: app.logger.info(f"Unhandled issue event action: {action}") @@ -89,52 +89,6 @@ 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. @@ -156,6 +110,9 @@ def on_issue(data: dict) -> list: case "opened": task = on_issue_opened.delay(event.model_dump()) return [task.id] + case "edited": + task = on_issue_updated.delay(event.model_dump()) + return [task.id] # TODO: 区分已关闭的 Issue case _: task = on_issue_updated.delay(event.model_dump()) From 0dc76bcd5341e3b327b2b24a7fd4537792bfd776 Mon Sep 17 00:00:00 2001 From: freeziyou <80776877@qq.com> Date: Sun, 4 Feb 2024 11:54:31 +0800 Subject: [PATCH 3/3] add github edit event --- server/tasks/github/issue.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/server/tasks/github/issue.py b/server/tasks/github/issue.py index 6bc18f1b..7b5bd5ba 100644 --- a/server/tasks/github/issue.py +++ b/server/tasks/github/issue.py @@ -110,9 +110,6 @@ def on_issue(data: dict) -> list: case "opened": task = on_issue_opened.delay(event.model_dump()) return [task.id] - case "edited": - task = on_issue_updated.delay(event.model_dump()) - return [task.id] # TODO: 区分已关闭的 Issue case _: task = on_issue_updated.delay(event.model_dump())