Slack alerts: issue title in message title

Fix #283
This commit is contained in:
Klaas van Schelven
2025-11-26 10:35:26 +01:00
parent 1ecd03634c
commit 2ac297c012

View File

@@ -149,22 +149,22 @@ def slack_backend_send_alert(
issue = Issue.objects.get(id=issue_id)
issue_url = get_settings().BASE_URL + issue.get_absolute_url()
link = f"<{issue_url}|" + _safe_markdown(truncatechars(issue.title().replace("|", ""), 200)) + ">"
title = truncatechars(issue.title().replace("|", ""), 200)
link = f"<{issue_url}|view on Bugsink>"
sections = [
{
"type": "header",
"text": {
"type": "plain_text",
# TODO arguably issue.title() should get this location; "later" because I don't have a test env.
"text": f"{alert_reason} issue",
"text": title,
},
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": link,
"type": "plain_text",
"text": f"{alert_reason} issue",
},
},
]
@@ -191,18 +191,24 @@ def slack_backend_send_alert(
# if event.environment:
# fields["environment"] = event.environment
data = {"text": sections[0]["text"]["text"], # mattermost requires at least one text field; use the first section
"blocks": sections + [
{
"type": "section",
"fields": [
sections += [{"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": f"*{field}*: " + _safe_markdown(value),
} for field, value in fields.items()
]
},
]}
]}]
sections += [{
"type": "section",
"text": {
"type": "mrkdwn",
"text": link,
},
}]
# slack service-backend also support mattermost; mattermost requires at least one text field; use the first section
data = {"text": sections[0]["text"]["text"], "blocks": sections}
try:
result = requests.post(