-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.4.0 - added slack preamble message, fixed git logic
- Loading branch information
1 parent
602c499
commit 719f2da
Showing
13 changed files
with
148 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[flake8] | ||
max-line-length = 100 | ||
max-line-length = 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
import sys | ||
import slack | ||
|
||
|
||
SLACK_BOT_TOKEN = os.getenv('SLACK_BOT_TOKEN') | ||
SLACK_CHANNEL = os.getenv('SLACK_CHANNEL') | ||
|
||
|
||
class Message(): | ||
@classmethod | ||
def send_slack_message(cls, message): | ||
"""Send a Slack message via a Slackbot | ||
""" | ||
slack_client = slack.WebClient(SLACK_BOT_TOKEN) | ||
try: | ||
slack_client.chat_postMessage( | ||
channel=SLACK_CHANNEL, | ||
text=message | ||
) | ||
print('Slack message sent!') | ||
except slack.errors.SlackApiError: | ||
final_output = 'Harvey could not send the Slack message.' | ||
print(final_output) | ||
sys.exit(final_output) | ||
|
||
@classmethod | ||
def send_email(cls, message): | ||
"""Send an email message | ||
""" | ||
# TODO: Add email functionality | ||
raise NotImplementedError() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import mock | ||
import pytest | ||
import slack | ||
from harvey.message import Message | ||
|
||
|
||
@mock.patch('harvey.message.SLACK_CHANNEL', 'mock-channel') | ||
@mock.patch('harvey.message.SLACK_BOT_TOKEN', '123') | ||
@mock.patch('slack.WebClient.chat_postMessage') | ||
def test_send_slack_message_success(mock_slack): | ||
message = 'mock message' | ||
Message.send_slack_message(message) | ||
mock_slack.assert_called_once_with(channel='mock-channel', text=message) | ||
|
||
|
||
@mock.patch('sys.exit') | ||
@mock.patch('slack.WebClient.chat_postMessage', | ||
side_effect=slack.errors.SlackApiError( | ||
message='The request to the Slack API failed.', | ||
response={'ok': False, 'error': 'not_authed'} | ||
)) | ||
def test_send_slack_message_exception(mock_slack, mock_sys_exit): | ||
message = 'mock message' | ||
Message.send_slack_message(message) | ||
mock_sys_exit.assert_called_once_with('Harvey could not send the Slack message.') | ||
|
||
|
||
def test_send_email(): | ||
message = 'mock message' | ||
with pytest.raises(NotImplementedError): | ||
Message.send_email(message) |