Skip to content

Commit

Permalink
adding 'icon_url' on slack web hook and slack operator (#5724)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sayed Mohammad Hossein Torabi authored and potiuk committed Aug 6, 2019
1 parent 64f8b24 commit 014e5fa
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
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 @@ -38,13 +38,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 @@ -37,6 +37,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 Down Expand Up @@ -64,6 +65,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

0 comments on commit 014e5fa

Please sign in to comment.