Skip to content

Commit

Permalink
feat: github webhook 支持 released 事件
Browse files Browse the repository at this point in the history
  • Loading branch information
Cassius0924 committed Mar 5, 2024
1 parent 1f6ef75 commit f38f9de
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 4 deletions.
2 changes: 2 additions & 0 deletions wechatter/models/github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .pr_review_webhook import GithubPrReviewWebhook
from .pr_webhook import GithubPrWebhook
from .push_webhook import GithubPushWebhook
from .release_webhook import GithubReleaseWebhook
from .star_webhook import GithubStarWebhook

__all__ = [
Expand All @@ -20,4 +21,5 @@
"GithubPrWebhook",
"GithubPushWebhook",
"GithubStarWebhook",
"GithubReleaseWebhook",
]
27 changes: 27 additions & 0 deletions wechatter/models/github/release_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from pydantic import BaseModel

from wechatter.models.github.base import Repository, User


class Release(BaseModel):
url: str
assets_url: str
upload_url: str
html_url: str
author: User
body: str
tag_name: str
target_commitish: str
name: str
draft: bool
prerelease: bool
created_at: str
published_at: str
id: int


class GithubReleaseWebhook(BaseModel):
action: str
release: Release
repository: Repository
sender: User
8 changes: 4 additions & 4 deletions wechatter/models/wechat/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def from_api_msg(
province=payload.get("province", ""),
city=payload.get("city", ""),
# phone_list=payload.get("phone", []),
is_star=payload.get("star", ""),
is_friend=payload.get("friend", ""),
is_star=payload.get("star", False),
is_friend=payload.get("friend", False),
is_official_account=is_official_account,
)

Expand All @@ -128,8 +128,8 @@ def from_api_msg(
name=to_payload.get("name", ""),
alias=to_payload.get("alias", ""),
gender="unknown",
is_star=to_payload.get("star", ""),
is_friend=to_payload.get("friend", ""),
is_star=to_payload.get("star", False),
is_friend=to_payload.get("friend", False),
)

_content = content.replace("\u2005", " ", 1)
Expand Down
2 changes: 2 additions & 0 deletions wechatter/webhook_handlers/github/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .pr_handler import handle_pr
from .pr_review_handler import handle_pr_review
from .push_handler import handle_push
from .release_handler import handle_release
from .star_handler import handle_star

__all__ = [
Expand All @@ -20,4 +21,5 @@
"handle_pr",
"handle_push",
"handle_star",
"handle_release",
]
25 changes: 25 additions & 0 deletions wechatter/webhook_handlers/github/release_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from loguru import logger

from wechatter.models.github import GithubReleaseWebhook
from wechatter.sender import sender
from wechatter.webhook_handlers.hanlders import github_webhook_handler


@github_webhook_handler("release")
def handle_release(data: dict):
payload = GithubReleaseWebhook(**data)
if payload.action != "published":
return
logger.info(
f"Release event on {payload.release.html_url} in repository {payload.repository.full_name}."
)
message = (
"== GitHub Release 事件 ==\n"
f"🚀 新的版本发布了!\n"
f"📚 仓库:{payload.repository.full_name}\n"
f"🏷️ 版本:{payload.release.tag_name}\n"
f"🧑‍💻 提交者:{payload.sender.login}\n"
f"🔗 查看详情:{payload.release.html_url}"
)

sender.mass_send_msg_to_github_webhook_receivers(message)

0 comments on commit f38f9de

Please sign in to comment.