Skip to content
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

[AIRFLOW-5113] Support icon url in slack web hook #5724

Merged
merged 2 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions airflow/contrib/hooks/slack_webhook_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class SlackWebhookHook(HttpHook):
:type username: str
:param icon_emoji: The emoji to use as icon for the user posting to Slack
:type icon_emoji: str
:param icon_url: The icon image URL string to use in place of the default icon.
:type icon_url: str
:param link_names: Whether or not to find and link channel and usernames in your
message
:type link_names: bool
Expand All @@ -62,6 +64,7 @@ def __init__(self,
channel=None,
username=None,
icon_emoji=None,
icon_url=None,
link_names=False,
proxy=None,
*args,
Expand All @@ -74,6 +77,7 @@ def __init__(self,
self.channel = channel
self.username = username
self.icon_emoji = icon_emoji
self.icon_url = icon_url
self.link_names = link_names
self.proxy = proxy

Expand Down Expand Up @@ -110,6 +114,8 @@ def _build_slack_message(self):
cmd['username'] = self.username
if self.icon_emoji:
cmd['icon_emoji'] = self.icon_emoji
if self.icon_url:
cmd['icon_url'] = self.icon_url
if self.link_names:
cmd['link_names'] = 1
if self.attachments:
Expand Down
5 changes: 5 additions & 0 deletions airflow/contrib/operators/slack_webhook_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class SlackWebhookOperator(SimpleHttpOperator):
:type username: str
:param icon_emoji: The emoji to use as icon for the user posting to Slack
:type icon_emoji: str
:param icon_url: The icon image URL string to use in place of the default icon.
:type icon_url: str
:param link_names: Whether or not to find and link channel and usernames in your
message
:type link_names: bool
Expand All @@ -66,6 +68,7 @@ def __init__(self,
channel=None,
username=None,
icon_emoji=None,
icon_url=None,
link_names=False,
proxy=None,
*args,
Expand All @@ -80,6 +83,7 @@ def __init__(self,
self.channel = channel
self.username = username
self.icon_emoji = icon_emoji
self.icon_url = icon_url
self.link_names = link_names
self.proxy = proxy
self.hook = None
Expand All @@ -96,6 +100,7 @@ def execute(self, context):
self.channel,
self.username,
self.icon_emoji,
self.icon_url,
self.link_names,
self.proxy
)
Expand Down
2 changes: 2 additions & 0 deletions tests/contrib/hooks/test_slack_webhook_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ class TestSlackWebhookHook(unittest.TestCase):
'channel': '#general',
'username': 'SlackMcSlackFace',
'icon_emoji': ':hankey:',
'icon_url': 'https://airflow.apache.org/_images/pin_large.png',
'link_names': True,
'proxy': 'https://my-horrible-proxy.proxyist.com:8080'
}
expected_message_dict = {
'channel': _config['channel'],
'username': _config['username'],
'icon_emoji': _config['icon_emoji'],
'icon_url': _config['icon_url'],
'link_names': 1,
'attachments': _config['attachments'],
'text': _config['message']
Expand Down
2 changes: 2 additions & 0 deletions tests/contrib/operators/test_slack_webhook_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class TestSlackWebhookOperator(unittest.TestCase):
'channel': '#general',
'username': 'SlackMcSlackFace',
'icon_emoji': ':hankey',
'icon_url': 'https://airflow.apache.org/_images/pin_large.png',
'link_names': True,
'proxy': 'https://my-horrible-proxy.proxyist.com:8080'
}
Expand All @@ -62,6 +63,7 @@ def test_execute(self):
self.assertEqual(self._config['channel'], operator.channel)
self.assertEqual(self._config['username'], operator.username)
self.assertEqual(self._config['icon_emoji'], operator.icon_emoji)
self.assertEqual(self._config['icon_url'], operator.icon_url)
self.assertEqual(self._config['link_names'], operator.link_names)
self.assertEqual(self._config['proxy'], operator.proxy)

Expand Down