Added support for Twist messaging.

development
Shawn Davis 4 years ago
parent 7df4edb7dc
commit a975bb2145
  1. 30
      scripttease/library/overlays/common.py
  2. 13
      tests/test_library_overlays_common.py

@ -10,6 +10,7 @@ __all__ = (
"python_virtualenv", "python_virtualenv",
"run", "run",
"slack", "slack",
"twist",
) )
# Functions # Functions
@ -70,6 +71,9 @@ def slack(message, url=None, **kwargs):
- url (str): The webhook URL. This is required. See documentation. - url (str): The webhook URL. This is required. See documentation.
""" """
if url is None:
raise ValueError("A url is required to use the slack command.")
kwargs.setdefault("comment", "send a message to slack") kwargs.setdefault("comment", "send a message to slack")
a = list() a = list()
@ -81,11 +85,37 @@ def slack(message, url=None, **kwargs):
return Command(" ".join(a), **kwargs) return Command(" ".join(a), **kwargs)
def twist(message, title="Notice", url=None, **kwargs):
"""Send a message to Twist.
- message (str): The message to be sent.
- title (str): The message title.
- url (str): The webhook URL. This is required. See documentation.
"""
if url is None:
raise ValueError("A url is required to use the twist command.")
kwargs.setdefault("comment", "send a message to twist")
a = list()
# curl -X POST -H 'Content-type: application/json' --data '{"content": "This is the message.", "title": "Message Title"}' "https://twist.com/api/v3/integration_incoming/post_data?install_id=116240&install_token=116240_bfb05bde51ecd0f728b4b161bee6fcee"
a.append("curl -X POST -H 'Content-type: application/json' --data")
data = '{"content": "%s", "title": "%s"}' % (message, title)
a.append("'%s'" % data)
a.append('"%s"' % url)
return Command(" ".join(a), **kwargs)
# Mappings # Mappings
COMMON_MAPPINGS = { COMMON_MAPPINGS = {
'pip': python_pip, 'pip': python_pip,
'run': run, 'run': run,
'slack': slack, 'slack': slack,
'twist': twist,
'virtualenv': python_virtualenv, 'virtualenv': python_virtualenv,
} }

@ -1,3 +1,4 @@
import pytest
from scripttease.library.overlays.common import * from scripttease.library.overlays.common import *
@ -23,8 +24,20 @@ def test_run():
def test_slack(): def test_slack():
with pytest.raises(ValueError):
slack("This is a test.")
c = slack("This is a test.", url="https://example.slack.com/asdf/1234") c = slack("This is a test.", url="https://example.slack.com/asdf/1234")
s = c.get_statement(suppress_comment=True) s = c.get_statement(suppress_comment=True)
assert "curl -X POST -H 'Content-type: application/json' --data" in s assert "curl -X POST -H 'Content-type: application/json' --data" in s
assert "This is a test." in s assert "This is a test." in s
assert "https://example.slack.com/asdf/1234" in s assert "https://example.slack.com/asdf/1234" in s
def test_twist():
with pytest.raises(ValueError):
twist("This is a test.")
c = twist("This is a test.", url="https://example.twist.com/asdf/1234")
s = c.get_statement(suppress_comment=True)
print(s)

Loading…
Cancel
Save