Skip to content

Commit

Permalink
✨ do not handle webhook if no subscribers
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Sep 8, 2024
1 parent 7a25b83 commit 35dd2c7
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/plugins/github/webhooks/issue_closed.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
async def handle_issue_closed_event(
event: IssuesClosed | PullRequestClosed, subscribers: SUBSCRIBERS
):
if not subscribers:
return

repo_name = event.payload.repository.full_name
owner, repo = repo_name.split("/", 1)

Expand Down
7 changes: 5 additions & 2 deletions src/plugins/github/webhooks/issue_commented.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@Author : yanyongyu
@Date : 2023-04-26 18:39:12
@LastEditors : yanyongyu
@LastEditTime : 2024-08-18 17:26:21
@LastEditTime : 2024-09-08 12:28:07
@Description : None
@GitHub : https://github.com/yanyongyu
"""
Expand Down Expand Up @@ -44,9 +44,12 @@


@issue_commented.handle()
async def handle_issue_opened_event(
async def handle_issue_comment_created_event(
event: IssueCommentCreated, subscribers: SUBSCRIBERS
):
if not subscribers:
return

repo_name = event.payload.repository.full_name
owner, repo = repo_name.split("/", 1)

Expand Down
5 changes: 4 additions & 1 deletion src/plugins/github/webhooks/issue_opened.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@Author : yanyongyu
@Date : 2023-04-04 20:02:19
@LastEditors : yanyongyu
@LastEditTime : 2024-08-18 17:26:48
@LastEditTime : 2024-09-08 12:28:15
@Description : Webhook issue opened broadcast
@GitHub : https://github.com/yanyongyu
"""
Expand Down Expand Up @@ -47,6 +47,9 @@
async def handle_issue_opened_event(
event: IssuesOpened | PullRequestOpened, subscribers: SUBSCRIBERS
):
if not subscribers:
return

repo_name = event.payload.repository.full_name
owner, repo = repo_name.split("/", 1)

Expand Down
6 changes: 5 additions & 1 deletion src/plugins/github/webhooks/release_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@Author : yanyongyu
@Date : 2023-04-04 20:02:19
@LastEditors : yanyongyu
@LastEditTime : 2024-08-18 17:26:59
@LastEditTime : 2024-09-08 12:28:26
@Description : Webhook release publish broadcast
@GitHub : https://github.com/yanyongyu
"""
Expand Down Expand Up @@ -39,8 +39,12 @@
async def handle_release_published_event(
event: ReleasePublished, subscribers: SUBSCRIBERS
):
if not subscribers:
return

owner = event.payload.repository.owner.login
repo = event.payload.repository.name

tag = ReleaseTag(
owner=owner, repo=repo, tag=event.payload.release.tag_name, is_receive=False
)
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/github/webhooks/star.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@Author : yanyongyu
@Date : 2022-12-18 13:44:11
@LastEditors : yanyongyu
@LastEditTime : 2024-08-18 17:27:13
@LastEditTime : 2024-09-08 12:27:35
@Description : Webhook star event broadcast
@GitHub : https://github.com/yanyongyu
"""
Expand Down Expand Up @@ -39,6 +39,9 @@
parameterless=(Depends(Throttle((StarCreated, StarDeleted), THROTTLE_EXPIRE)),)
)
async def handle_star_event(event: StarCreated | StarDeleted, subscribers: SUBSCRIBERS):
if not subscribers:
return

username = event.payload.sender.login
repo_name = event.payload.repository.full_name
action = event.payload.action
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/github/webhooks/unknown.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@Author : yanyongyu
@Date : 2022-11-07 05:14:32
@LastEditors : yanyongyu
@LastEditTime : 2024-08-18 17:27:21
@LastEditTime : 2024-09-08 12:28:43
@Description : Webhook unknown event broadcast
@GitHub : https://github.com/yanyongyu
"""
Expand Down Expand Up @@ -46,6 +46,9 @@
async def handle_unknown_event(
event: Event, event_info: EVENT_INFO, subscribers: SUBSCRIBERS
):
if not subscribers:
return

username: str = get_attr_or_item(get_attr_or_item(event.payload, "sender"), "login")

owner, repo, event_name, action = event_info
Expand Down

0 comments on commit 35dd2c7

Please sign in to comment.