|
1 | 1 | from datetime import timedelta |
2 | 2 | from typing import Any, Dict, List, Literal, Optional, Sequence, Tuple, Union |
3 | 3 |
|
| 4 | +from pydantic import BaseModel |
| 5 | + |
4 | 6 | from elementary.messages.block_builders import ( |
5 | 7 | BoldTextLineBlock, |
6 | 8 | BulletListBlock, |
|
53 | 55 | ] |
54 | 56 |
|
55 | 57 |
|
| 58 | +class MessageBuilderConfig(BaseModel): |
| 59 | + alert_groups_subscribers: bool = False |
| 60 | + |
| 61 | + |
56 | 62 | class AlertMessageBuilder: |
| 63 | + def __init__(self, config: Optional[MessageBuilderConfig] = None): |
| 64 | + self.config = config or MessageBuilderConfig() |
| 65 | + |
57 | 66 | STATUS_DISPLAYS: Dict[str, str] = { |
58 | 67 | "fail": "Failure", |
59 | 68 | "warn": "Warning", |
@@ -423,6 +432,17 @@ def _get_alert_list_line( |
423 | 432 | inlines.append(TextBlock(text="Owners:")) |
424 | 433 | inlines.append(MentionLineBlock(*owners)) |
425 | 434 |
|
| 435 | + if subscribers := list(set(alert.subscribers)): |
| 436 | + if self.config.alert_groups_subscribers: |
| 437 | + inlines.append(TextBlock(text="-")) |
| 438 | + if len(subscribers) == 1: |
| 439 | + inlines.append(TextBlock(text="Subscriber:")) |
| 440 | + inlines.append(MentionBlock(user=subscribers.pop())) |
| 441 | + else: |
| 442 | + subscribers.sort() |
| 443 | + inlines.append(TextBlock(text="Subscribers:")) |
| 444 | + inlines.append(MentionLineBlock(*subscribers)) |
| 445 | + |
426 | 446 | if report_link := alert.get_report_link(): |
427 | 447 | inlines.append(TextBlock(text="-")) |
428 | 448 | inlines.append(LinkBlock(text=report_link.text, url=report_link.url)) |
|
0 commit comments