fix: improve message handling and formatting in build_message function
All checks were successful
Lint and Syntax Check / build (push) Successful in 11s

This commit is contained in:
Space-Banane
2026-04-04 16:17:58 +02:00
parent cd79af6599
commit 73335050aa

27
main.py
View File

@@ -102,19 +102,29 @@ def build_message(event_object, action_str, type_str):
print( print(
f"Custom prompt file not found at {AGENT_PROMPT_FILE_PATH}. Using default message." f"Custom prompt file not found at {AGENT_PROMPT_FILE_PATH}. Using default message."
) )
message = fill_template(DEFAULT_PROMPT_TEMPLATE, event_object, action_str, type_str) message = fill_template(
message = message.replace("You were [action_str] to an [type_str]", action_summary) DEFAULT_PROMPT_TEMPLATE, event_object, action_str, type_str
)
message = message.replace(
"You were [action_str] to an [type_str]", action_summary
)
return message return message
with open(AGENT_PROMPT_FILE_PATH, "r") as f: with open(AGENT_PROMPT_FILE_PATH, "r") as f:
custom_prompt = f.read() custom_prompt = f.read()
message = fill_template(custom_prompt, event_object, action_str, type_str) message = fill_template(custom_prompt, event_object, action_str, type_str)
message = message.replace("You were [action_str] to an [type_str]", action_summary) message = message.replace(
"You were [action_str] to an [type_str]", action_summary
)
return message return message
else: else:
print("No custom prompt file specified. Using default message.") print("No custom prompt file specified. Using default message.")
message = fill_template(DEFAULT_PROMPT_TEMPLATE, event_object, action_str, type_str) message = fill_template(
message = message.replace("You were [action_str] to an [type_str]", action_summary) DEFAULT_PROMPT_TEMPLATE, event_object, action_str, type_str
)
message = message.replace(
"You were [action_str] to an [type_str]", action_summary
)
return message return message
@@ -135,7 +145,9 @@ def sendToAgent(event_object):
else: else:
action_str = "assigned" action_str = "assigned"
type_str = "issue" if event_object["type"] == "issue" else "pull request" type_str = "issue" if event_object["type"] == "issue" else "pull request"
assignees = event_object.get("assignees", [event_object.get("assignee", "Unknown")]) assignees = event_object.get(
"assignees", [event_object.get("assignee", "Unknown")]
)
if AGENT_USERNAME not in assignees: if AGENT_USERNAME not in assignees:
print( print(
f"Agent {AGENT_USERNAME} is not among the assignees for this event. Skipping notification." f"Agent {AGENT_USERNAME} is not among the assignees for this event. Skipping notification."
@@ -157,6 +169,7 @@ def sendToAgent(event_object):
"thinking": "low", "thinking": "low",
"timeoutSeconds": 45, "timeoutSeconds": 45,
"model": OPENCLAW_MODEL, "model": OPENCLAW_MODEL,
"deliver": False,
}, },
auth=auth, auth=auth,
) )
@@ -339,7 +352,7 @@ def main(args):
set_stored_assignees( set_stored_assignees(
db, event_type, repo_id, event_object["number"], assignees_list db, event_type, repo_id, event_object["number"], assignees_list
) )
# Send to OpenClaw # Send to OpenClaw
if action == "assigned": if action == "assigned":
sendToAgent(event_object) sendToAgent(event_object)