Move configuration from config.py to config.json and add support for GitHub organization webhooks
remove _format_watch() from utils.github_webhook as the value of watchers_count is always identical with stargazers_count https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#watch https://developer.github.com/changes/2012-09-05-watcher-api/
This commit is contained in:
+4
-8
@@ -24,13 +24,14 @@ from typing import Union
|
||||
from aiohttp import ClientSession, ClientResponse
|
||||
from aiohttp.web_request import Request
|
||||
|
||||
from config import BOT_TOKEN, GH_WEBHOOKS
|
||||
from config import BOT_TOKEN
|
||||
from utils.github_webhook import format_github_webhook
|
||||
|
||||
|
||||
async def send_to_telegram(session: ClientSession, request: Request) -> str:
|
||||
async def send_to_telegram(session: ClientSession,
|
||||
chat_id: Union[str, int],
|
||||
request: Request) -> str:
|
||||
message_text: Optional[str] = await format_github_webhook(request)
|
||||
chat_id: int = await get_corresponding_chat_id(await request.json())
|
||||
if not message_text:
|
||||
tg_status = "nothing to send"
|
||||
else:
|
||||
@@ -39,11 +40,6 @@ async def send_to_telegram(session: ClientSession, request: Request) -> str:
|
||||
return tg_status
|
||||
|
||||
|
||||
async def get_corresponding_chat_id(payload: dict) -> int:
|
||||
repo_name = payload['repository']['full_name']
|
||||
return GH_WEBHOOKS[repo_name]['chat_id']
|
||||
|
||||
|
||||
async def send_message(session: ClientSession,
|
||||
chat_id: Union[int, str],
|
||||
text: str) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user