-
Notifications
You must be signed in to change notification settings - Fork 204
Add attribution block to alert messages in data monitoring #2016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add attribution block to alert messages in data monitoring #2016
Conversation
- Introduced a new function to append an attribution block to alert messages. - Updated the alert message construction to include the attribution block, enhancing message content with a link to Elementary. - Refactored imports for better organization and clarity.
WalkthroughAdds an internal helper to inject an attribution block ("Powered by Elementary") into alert message bodies and wires it into the alert sending flow. Imports are updated to support new block types. No public APIs change. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant A as Alert Generator
participant H as _add_elementary_attribution
participant N as Notifier/Sender
A->>A: Build alert_message_body
A->>H: Inject attribution
note right of H: Insert after HeaderBlock if present,<br/>else append at end
H-->>A: message_body with attribution
A->>N: Send updated message_body
N-->>A: Send result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Comment |
|
👋 @MikaKerman |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
elementary/monitor/data_monitoring/alerts/data_monitoring_alerts.py (3)
66-80: Make attribution insertion idempotent and avoid hardcoding the URL twice.Add a quick scan to skip insertion when the Elementary link already exists, and factor the URL into a local var to prevent drift.
def _add_elementary_attribution(body: MessageBody) -> MessageBody: - lines = [ + elementary_url = "https://www.elementary-data.com/" + + # Avoid duplicate attribution if already present + if any( + isinstance(b, LinesBlock) + and any( + isinstance(inl, LinkBlock) and inl.url.rstrip("/") == elementary_url.rstrip("/") + for line in b.lines + for inl in getattr(line, "inlines", []) + ) + for b in body.blocks + ): + return body + + lines = [ LineBlock( inlines=[ TextBlock(text="Powered by"), LinkBlock( text="Elementary", - url="https://www.elementary-data.com/", + url=elementary_url, ), ] ) ] @@ - first_block_is_header = body.blocks and isinstance(body.blocks[0], HeaderBlock) + first_block_is_header = bool(body.blocks) and isinstance(body.blocks[0], HeaderBlock)Also applies to: 82-95
83-87: Minor typing/readability: avoid relying on list truthiness.Use an explicit boolean for header detection to keep static type checkers happy and improve clarity.
-first_block_is_header = body.blocks and isinstance(body.blocks[0], HeaderBlock) +first_block_is_header = bool(body.blocks) and isinstance(body.blocks[0], HeaderBlock)
353-353: Hook point LGTM; consider consistency and config.Nice placement before send. Optionally, apply attribution to the health-check test message too, or gate via a config flag (e.g., show_attribution: bool) for white-label scenarios.
If you want the test message to include attribution:
def _send_test_message(self) -> MessageSendResult: @@ - test_message = get_health_check_message() + test_message = _add_elementary_attribution(get_health_check_message())
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
elementary/monitor/data_monitoring/alerts/data_monitoring_alerts.py(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
elementary/monitor/data_monitoring/alerts/data_monitoring_alerts.py (2)
elementary/messages/blocks.py (5)
HeaderBlock(119-121)LineBlock(66-69)LinesBlock(137-138)LinkBlock(45-48)TextBlock(39-42)elementary/messages/message_body.py (1)
MessageBody(36-39)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: test / test
- GitHub Check: code-quality
🔇 Additional comments (1)
elementary/monitor/data_monitoring/alerts/data_monitoring_alerts.py (1)
10-17: Imports look good; surface matches usage.The added block imports and MessageBlock typing align with the helper’s construction and annotations. No issues spotted.

Summary by CodeRabbit