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 4c9b44c commit 05964be
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions server/tasks/github/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 05964be

Please sign in to comment.