Skip to content

Commit

Permalink
add github edit event
Browse files Browse the repository at this point in the history
  • Loading branch information
freeziyou committed Feb 4, 2024
1 parent 05964be commit ef80840
Showing 1 changed file with 4 additions and 47 deletions.
51 changes: 4 additions & 47 deletions server/tasks/github/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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.
Expand All @@ -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())
Expand Down

0 comments on commit ef80840

Please sign in to comment.