slack_incoming: Verify that keys exist before checking their value.

This commit is contained in:
Alex Vandiver 2022-11-29 16:11:07 -05:00 committed by Tim Abbott
parent f1a8209705
commit eb3674362a
3 changed files with 14 additions and 4 deletions

View File

@ -19,12 +19,20 @@
"short": true
},
{
"title": "Title without value",
"title": "Title with null value",
"value": null,
"short": true
},
{
"title": "Title without value",
"short": true
},
{
"title": null,
"value": "Value with null title",
"short": true
},
{
"value": "Value without title",
"short": true
},

View File

@ -191,7 +191,9 @@ Build bla bla succeeded
**Requested by**: Some user
**Duration**: 00:02:03
**Build pipeline**: ConsumerAddressModule
**Title with null value**
**Title without value**
Value with null title
Value without title
""".strip()

View File

@ -193,14 +193,14 @@ def render_attachment(attachment: WildValue) -> str:
if "fields" in attachment:
fields = []
for field in attachment["fields"]:
if field["title"] and field["value"]:
if "title" in field and "value" in field and field["title"] and field["value"]:
title = field["title"].tame(check_string)
value = field["value"].tame(check_string)
fields.append(f"*{title}*: {value}")
elif field["title"]:
elif "title" in field and field["title"]:
title = field["title"].tame(check_string)
fields.append(f"*{title}*")
elif field["value"]:
elif "value" in field and field["value"]:
value = field["value"].tame(check_string)
fields.append(f"{value}")
pieces.append("\n".join(fields))