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