This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new c25858cb30 feat(slack): add unfurl options to slack notifier (#40694)
c25858cb30 is described below
commit c25858cb30306ebfd6e473ded636ef0b7c84a88c
Author: Armand Sauzay <[email protected]>
AuthorDate: Wed Jul 10 19:29:20 2024 +0200
feat(slack): add unfurl options to slack notifier (#40694)
---
airflow/providers/slack/notifications/slack.py | 6 +++++
tests/providers/slack/notifications/test_slack.py | 32 +++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/airflow/providers/slack/notifications/slack.py
b/airflow/providers/slack/notifications/slack.py
index 5fd800bede..aefc4629a1 100644
--- a/airflow/providers/slack/notifications/slack.py
+++ b/airflow/providers/slack/notifications/slack.py
@@ -64,6 +64,8 @@ class SlackNotifier(BaseNotifier):
proxy: str | None = None,
timeout: int | None = None,
retry_handlers: list[RetryHandler] | None = None,
+ unfurl_links: bool = True,
+ unfurl_media: bool = True,
):
super().__init__()
self.slack_conn_id = slack_conn_id
@@ -77,6 +79,8 @@ class SlackNotifier(BaseNotifier):
self.timeout = timeout
self.proxy = proxy
self.retry_handlers = retry_handlers
+ self.unfurl_links = unfurl_links
+ self.unfurl_media = unfurl_media
@cached_property
def hook(self) -> SlackHook:
@@ -98,6 +102,8 @@ class SlackNotifier(BaseNotifier):
"icon_url": self.icon_url,
"attachments": json.dumps(self.attachments),
"blocks": json.dumps(self.blocks),
+ "unfurl_links": self.unfurl_links,
+ "unfurl_media": self.unfurl_media,
}
self.hook.call("chat.postMessage", json=api_call_params)
diff --git a/tests/providers/slack/notifications/test_slack.py
b/tests/providers/slack/notifications/test_slack.py
index 4a2c1430de..8fba3a9d8c 100644
--- a/tests/providers/slack/notifications/test_slack.py
+++ b/tests/providers/slack/notifications/test_slack.py
@@ -68,6 +68,8 @@ class TestSlackNotifier:
"/pin_100.png",
"attachments": "[]",
"blocks": "[]",
+ "unfurl_links": True,
+ "unfurl_media": True,
},
)
mock_slack_hook.assert_called_once_with(slack_conn_id="test_conn_id",
**hook_extra_kwargs)
@@ -89,6 +91,8 @@ class TestSlackNotifier:
"/pin_100.png",
"attachments": "[]",
"blocks": "[]",
+ "unfurl_links": True,
+ "unfurl_media": True,
},
)
@@ -114,5 +118,33 @@ class TestSlackNotifier:
"/pin_100.png",
"attachments": '[{"image_url": "test_slack_notifier.png"}]',
"blocks": "[]",
+ "unfurl_links": True,
+ "unfurl_media": True,
+ },
+ )
+
+ @mock.patch("airflow.providers.slack.notifications.slack.SlackHook")
+ def test_slack_notifier_unfurl_options(self, mock_slack_hook, dag_maker):
+ with dag_maker("test_slack_notifier_unfurl_options") as dag:
+ EmptyOperator(task_id="task1")
+
+ notifier = send_slack_notification(
+ text="test",
+ unfurl_links=False,
+ unfurl_media=False,
+ )
+ notifier({"dag": dag})
+ mock_slack_hook.return_value.call.assert_called_once_with(
+ "chat.postMessage",
+ json={
+ "channel": "#general",
+ "username": "Airflow",
+ "text": "test",
+ "icon_url":
"https://raw.githubusercontent.com/apache/airflow/2.5.0/airflow/www/static"
+ "/pin_100.png",
+ "attachments": "[]",
+ "blocks": "[]",
+ "unfurl_links": False,
+ "unfurl_media": False,
},
)