123
This commit is contained in:
parent
d94cea9c0c
commit
f341ea0aa7
@ -694,7 +694,7 @@ async def webhook_github(
|
||||
notification_channel_id = repo_config['notification_channel_id']
|
||||
|
||||
# Convert embed to dict for sending via API
|
||||
message_content = {"embeds": [discord_embed.to_dict()]}
|
||||
send_payload_dict = {"embeds": [discord_embed.to_dict()]}
|
||||
|
||||
# Use the send_discord_message_via_api from api_server.py
|
||||
# This requires DISCORD_BOT_TOKEN to be set in the environment for api_server
|
||||
@ -703,42 +703,10 @@ async def webhook_github(
|
||||
# Still return 200 to GitHub to acknowledge receipt, but log error.
|
||||
return {"status": "error", "message": "Notification sending failed (bot token not configured)."}
|
||||
|
||||
send_result = await send_discord_message_via_api(
|
||||
channel_id=notification_channel_id,
|
||||
content=json.dumps(message_content) # send_discord_message_via_api expects a string for 'content'
|
||||
# but it should handle dicts with 'embeds' if modified or we send raw.
|
||||
# For now, let's assume it needs a simple string or we adapt it.
|
||||
# The current send_discord_message_via_api sends 'content' as a top-level string.
|
||||
# We need to send an embed.
|
||||
)
|
||||
# The send_discord_message_via_api needs to be adapted to send embeds.
|
||||
# For now, let's construct the data for the POST request directly as it would expect.
|
||||
|
||||
# Corrected way to send embed using the existing send_discord_message_via_api structure
|
||||
# The function expects a simple string content. We need to modify it or use aiohttp directly here.
|
||||
# Let's assume we'll modify send_discord_message_via_api later or use a more direct aiohttp call.
|
||||
# For now, this will likely fail to send an embed correctly with the current send_discord_message_via_api.
|
||||
# This is a placeholder for correct embed sending.
|
||||
|
||||
# To send an embed, the JSON body to Discord API should be like:
|
||||
# { "embeds": [ { ... embed object ... } ] }
|
||||
# The current `send_discord_message_via_api` sends `{"content": "message"}`.
|
||||
# This part needs careful implementation.
|
||||
|
||||
# For now, let's log what would be sent.
|
||||
log.info(f"Prepared to send GitHub notification to channel {notification_channel_id} for repo {repo_db_id}.")
|
||||
# Actual sending logic will be refined.
|
||||
|
||||
# Placeholder for actual sending:
|
||||
# For a quick test, we can try to send a simple text message.
|
||||
# simple_text = f"New push to {repo_config['repository_url']}. Commits: {len(payload.get('commits', []))}"
|
||||
# send_result = await send_discord_message_via_api(notification_channel_id, simple_text)
|
||||
|
||||
# If send_discord_message_via_api is adapted to handle embeds in its 'content' (e.g. by checking if it's a dict with 'embeds' key)
|
||||
# then the following would be more appropriate:
|
||||
# This requires send_discord_message_via_api to be flexible.
|
||||
send_payload_dict = {"embeds": [discord_embed.to_dict()]}
|
||||
log.info(f"Sending GitHub notification to channel {notification_channel_id} for repo {repo_db_id}.")
|
||||
|
||||
# Send the embed using the send_discord_message_via_api function
|
||||
# The function can handle dict content with embeds
|
||||
send_result = await send_discord_message_via_api(
|
||||
channel_id=notification_channel_id,
|
||||
content=send_payload_dict # Pass the dict directly
|
||||
@ -848,13 +816,19 @@ async def webhook_gitlab(
|
||||
|
||||
notification_channel_id = repo_config['notification_channel_id']
|
||||
|
||||
# Similar to GitHub, sending embed needs careful handling with send_discord_message_via_api
|
||||
# Use the send_discord_message_via_api from api_server.py
|
||||
# This requires DISCORD_BOT_TOKEN to be set in the environment for api_server
|
||||
if not api_settings.DISCORD_BOT_TOKEN:
|
||||
log.error("DISCORD_BOT_TOKEN not configured in API settings. Cannot send webhook notification.")
|
||||
return {"status": "error", "message": "Notification sending failed (bot token not configured)."}
|
||||
|
||||
# Convert embed to dict for sending via API
|
||||
send_payload_dict = {"embeds": [discord_embed.to_dict()]}
|
||||
|
||||
log.info(f"Sending GitLab notification to channel {notification_channel_id} for repo {repo_db_id}.")
|
||||
|
||||
# Send the embed using the send_discord_message_via_api function
|
||||
# The function can handle dict content with embeds
|
||||
send_result = await send_discord_message_via_api(
|
||||
channel_id=notification_channel_id,
|
||||
content=send_payload_dict # Pass the dict directly
|
||||
|
Loading…
x
Reference in New Issue
Block a user