Skip to content

Commit 2a2f5c2

Browse files
committed
CR fixes
1 parent 79751eb commit 2a2f5c2

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

src/robusta/integrations/slack/sender.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,14 +409,24 @@ def __create_holmes_callback(self, finding: Finding) -> CallbackBlock:
409409
}
410410
)
411411

412+
@staticmethod
413+
def extract_mentions(title) -> (str, str):
414+
mentions = MENTION_PATTERN.findall(title)
415+
416+
mention = ""
417+
if mentions:
418+
mention = " " + " ".join(mentions)
419+
title = MENTION_PATTERN.sub("", title).strip()
420+
421+
return title, mention
422+
423+
412424
def __create_finding_header(
413425
self, finding: Finding, status: FindingStatus, platform_enabled: bool, include_investigate_link: bool
414426
) -> MarkdownBlock:
415427
title = finding.title.removeprefix("[RESOLVED] ")
416428

417-
match = MENTION_PATTERN.search(title)
418-
mention = f" {match.group(0)}" if match else ""
419-
title = MENTION_PATTERN.sub("", title).strip()
429+
title, mention = self.extract_mentions(title)
420430

421431
sev = finding.severity
422432
if finding.source == FindingSource.PROMETHEUS:

tests/slack/test_slack_mentions.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from integrations.slack import SlackSender
2+
3+
4+
def test_title_without_mentions():
5+
title = "Title with no mentions"
6+
new_title, mention = SlackSender.extract_mentions(title)
7+
assert new_title == title
8+
assert mention == ""
9+
10+
def test_title_with_single_mention():
11+
title = "Title with single mention <@U024BE7LH>"
12+
new_title, mention = SlackSender.extract_mentions(title)
13+
assert new_title == "Title with single mention"
14+
assert mention == " <@U024BE7LH>"
15+
16+
def test_title_with_two_mentions():
17+
title = "Title with <@U024BE7LG> two mentions <@U024BE7LH>"
18+
new_title, mention = SlackSender.extract_mentions(title)
19+
assert new_title == "Title with two mentions"
20+
assert mention == " <@U024BE7LG> <@U024BE7LH>"

0 commit comments

Comments
 (0)