webhooks/raygun: Improve punctuation and message formatting.

This commit is contained in:
Eeshan Garg
2019-05-09 13:49:50 -02:30
committed by Tim Abbott
parent 44038fc431
commit 6d62522ff0
2 changed files with 76 additions and 85 deletions

View File

@@ -10,11 +10,11 @@ class RaygunHookTests(WebhookTestCase):
def test_status_changed_message(self) -> None:
expected_topic = u"test"
expected_message = u"[Error](https://app.raygun.com/error-url) " \
u"status changed to: Ignored by Emma Cat\n" \
u"Timestamp: Wed Jan 28 01:49:36 1970\n" \
u"Application details: " \
u"[Best App](http://app.raygun.io/application-url)"
expected_message = """
[Error](https://app.raygun.com/error-url) status changed to **Ignored** by Emma Cat:
* **Timestamp**: Wed Jan 28 01:49:36 1970
* **Application details**: [Best App](http://app.raygun.io/application-url)
""".strip()
self.send_and_test_stream_message('error_status_changed',
expected_topic,
@@ -24,13 +24,15 @@ class RaygunHookTests(WebhookTestCase):
def test_comment_added_to_error_message(self) -> None:
expected_topic = u"test"
expected_message = u"Anita Peacock left a comment on " \
u"[Error](https://app.raygun.com/error-url): " \
u"Ignoring these errors\n" \
u"Timestamp: Wed Jan 28 01:49:36 1970\n" \
u"Application details: " \
u"[application name]" \
u"(http://app.raygun.io/application-url)"
expected_message = """
Anita Peacock commented on [Error](https://app.raygun.com/error-url):
``` quote
Ignoring these errors
```
* **Timestamp**: Wed Jan 28 01:49:36 1970
* **Application details**: [application name](http://app.raygun.io/application-url)
""".strip()
self.send_and_test_stream_message('comment_added_to_error',
expected_topic,
@@ -40,13 +42,11 @@ class RaygunHookTests(WebhookTestCase):
def test_error_assigned_to_user_message(self) -> None:
expected_topic = u"test"
expected_message = u"Amy Loondon assigned " \
u"[Error](https://app.raygun.com/error-url) " \
u"to Kyle Kenny\n" \
u"Timestamp: Wed Jan 28 01:49:36 1970\n" \
u"Application details: " \
u"[application name]" \
u"(http://app.raygun.io/application-url)"
expected_message = """
Amy Loondon assigned [Error](https://app.raygun.com/error-url) to Kyle Kenny:
* **Timestamp**: Wed Jan 28 01:49:36 1970
* **Application details**: [application name](http://app.raygun.io/application-url)
""".strip()
self.send_and_test_stream_message('error_assigned_to_user',
expected_topic,
@@ -56,15 +56,13 @@ class RaygunHookTests(WebhookTestCase):
def test_one_minute_followup_error_message(self) -> None:
expected_topic = u"test"
expected_message = u"One minute " \
u"[follow-up error]" \
u"(http://app.raygun.io/error-url)\n" \
u"First occurred: Wed Jan 28 01:49:36 1970\n" \
u"Last occurred: Wed Jan 28 01:49:36 1970\n" \
u"1 users affected with 1 total occurrences\n" \
u"Application details: " \
u"[application name]" \
u"(http://app.raygun.io/application-url)"
expected_message = """
One minute [follow-up error](http://app.raygun.io/error-url):
* **First occurred**: Wed Jan 28 01:49:36 1970
* **Last occurred**: Wed Jan 28 01:49:36 1970
* 1 users affected with 1 total occurrences
* **Application details**: [application name](http://app.raygun.io/application-url)
""".strip()
self.send_and_test_stream_message('one_minute_followup_error',
expected_topic,
@@ -74,15 +72,13 @@ class RaygunHookTests(WebhookTestCase):
def test_hourly_followup_error_message(self) -> None:
expected_topic = u"test"
expected_message = u"Hourly " \
u"[follow-up error]" \
u"(http://app.raygun.io/error-url)\n" \
u"First occurred: Wed Jan 28 01:49:36 1970\n" \
u"Last occurred: Wed Jan 28 01:49:36 1970\n" \
u"1 users affected with 1 total occurrences\n" \
u"Application details: " \
u"[application name]" \
u"(http://app.raygun.io/application-url)"
expected_message = """
Hourly [follow-up error](http://app.raygun.io/error-url):
* **First occurred**: Wed Jan 28 01:49:36 1970
* **Last occurred**: Wed Jan 28 01:49:36 1970
* 1 users affected with 1 total occurrences
* **Application details**: [application name](http://app.raygun.io/application-url)
""".strip()
self.send_and_test_stream_message('hourly_followup_error',
expected_topic,
@@ -92,18 +88,17 @@ class RaygunHookTests(WebhookTestCase):
def test_new_error_message(self) -> None:
expected_topic = u"test"
expected_message = u"**New [Error](http://app.raygun.io/error-url) " \
u"occurred!**\n" \
u"First occurred: Wed Jan 28 01:49:36 1970\n" \
u"Last occurred: Wed Jan 28 01:49:36 1970\n" \
u"1 users affected with 1 total occurrences\n" \
u"Tags: test, error-page, v1.0.1, env:staging\n" \
u"Affected user: a9b7d8...33846\n" \
u"pageName: Error Page\n" \
u"userLoggedIn: True\n" \
u"Application details: " \
u"[application name]" \
u"(http://app.raygun.io/application-url)"
expected_message = """
New [Error](http://app.raygun.io/error-url) occurred:
* **First occurred**: Wed Jan 28 01:49:36 1970
* **Last occurred**: Wed Jan 28 01:49:36 1970
* 1 users affected with 1 total occurrences
* **Tags**: test, error-page, v1.0.1, env:staging
* **Affected user**: a9b7d8...33846
* **pageName**: Error Page
* **userLoggedIn**: True
* **Application details**: [application name](http://app.raygun.io/application-url)
""".strip()
self.send_and_test_stream_message('new_error',
expected_topic,
@@ -113,18 +108,17 @@ class RaygunHookTests(WebhookTestCase):
def test_reoccurred_error_message(self) -> None:
expected_topic = u"test"
expected_message = u"[Error](http://app.raygun.io/error-url) " \
u"reoccurred.\n" \
u"First occurred: Wed Jan 28 01:49:36 1970\n" \
u"Last occurred: Wed Jan 28 01:49:36 1970\n" \
u"1 users affected with 1 total occurrences\n" \
u"Tags: test, error-page, v1.0.1, env:staging\n" \
u"Affected user: a9b7d8...33846\n" \
u"pageName: Error Page\n" \
u"userLoggedIn: True\n" \
u"Application details: " \
u"[application name]" \
u"(http://app.raygun.io/application-url)"
expected_message = """
[Error](http://app.raygun.io/error-url) reoccurred:
* **First occurred**: Wed Jan 28 01:49:36 1970
* **Last occurred**: Wed Jan 28 01:49:36 1970
* 1 users affected with 1 total occurrences
* **Tags**: test, error-page, v1.0.1, env:staging
* **Affected user**: a9b7d8...33846
* **pageName**: Error Page
* **userLoggedIn**: True
* **Application details**: [application name](http://app.raygun.io/application-url)
""".strip()
self.send_and_test_stream_message('reoccurred_error',
expected_topic,

View File

@@ -56,7 +56,7 @@ def make_user_stats_chunk(error_dict: Dict[str, Any]) -> str:
total_occurrences = error_dict['totalOccurrences']
# One line is subjectively better than two lines for this.
return "{} users affected with {} total occurrences\n".format(
return "* {} users affected with {} total occurrences\n".format(
users_affected, total_occurrences)
@@ -77,8 +77,8 @@ def make_time_chunk(error_dict: Dict[str, Any]) -> str:
time_last = parse_time(error_dict['lastOccurredOn'])
# Provide time information about this error,
return "First occurred: {}\nLast occurred: {}\n".format(time_first,
time_last)
return "* **First occurred**: {}\n* **Last occurred**: {}\n".format(
time_first, time_last)
def make_message_chunk(message: str) -> str:
@@ -92,7 +92,7 @@ def make_message_chunk(message: str) -> str:
returns an empty string.
"""
# "Message" shouldn't be included if there is none supplied.
return "Message: {}\n".format(message) if message != "" else ""
return "* **Message**: {}\n".format(message) if message != "" else ""
def make_app_info_chunk(app_dict: Dict[str, str]) -> str:
@@ -104,7 +104,7 @@ def make_app_info_chunk(app_dict: Dict[str, str]) -> str:
"""
app_name = app_dict['name']
app_url = app_dict['url']
return "Application details: [{}]({})\n".format(app_name, app_url)
return "* **Application details**: [{}]({})\n".format(app_name, app_url)
def notification_message_follow_up(payload: Dict[str, Any]) -> str:
@@ -128,7 +128,7 @@ def notification_message_follow_up(payload: Dict[str, Any]) -> str:
# minute", where "FiveMinuteFollowUp" is "Five minute".
prefix = followup_type[:len(followup_type) - 14] + " minute"
message += "{} {}\n".format(prefix, followup_link_md)
message += "{} {}:\n".format(prefix, followup_link_md)
# Get the message of the error.
payload_msg = payload['error']['message']
@@ -154,9 +154,9 @@ def notification_message_error_occurred(payload: Dict[str, Any]) -> str:
# Stylize the message based on the event type of the error.
if payload['eventType'] == "NewErrorOccurred":
message += "**{}**\n".format("New {} occurred!".format(error_link_md))
message += "{}:\n".format("New {} occurred".format(error_link_md))
elif payload['eventType'] == "ErrorReoccurred":
message += "{}\n".format("{} reoccurred.".format(error_link_md))
message += "{}:\n".format("{} reoccurred".format(error_link_md))
# Get the message of the error. This value can be empty (as in "").
payload_msg = payload['error']['message']
@@ -182,18 +182,18 @@ def notification_message_error_occurred(payload: Dict[str, Any]) -> str:
custom_data = error_instance['customData']
if tags is not None:
message += "Tags: {}\n".format(", ".join(tags))
message += "* **Tags**: {}\n".format(", ".join(tags))
if affected_user is not None:
user_uuid = affected_user['UUID']
message += "Affected user: {}...{}\n".format(user_uuid[:6],
user_uuid[-5:])
message += "* **Affected user**: {}...{}\n".format(
user_uuid[:6], user_uuid[-5:])
if custom_data is not None:
# We don't know what the keys and values beforehand, so we are forced
# to iterate.
for key in sorted(custom_data.keys()):
message += "{}: {}\n".format(key, custom_data[key])
message += "* **{}**: {}\n".format(key, custom_data[key])
message += make_app_info_chunk(payload['application'])
@@ -242,22 +242,19 @@ def activity_message(payload: Dict[str, Any]) -> str:
user = payload['error']['user']
if event_type == "StatusChanged":
error_status = payload['error']['status']
message += "{} status changed to: {} by {}\n".format(error_link_md,
error_status,
user)
message += "{} status changed to **{}** by {}:\n".format(
error_link_md, error_status, user)
elif event_type == "CommentAdded":
comment = payload['error']['comment']
message += "{} left a comment on {}: {}\n".format(user,
error_link_md,
comment)
message += "{} commented on {}:\n\n``` quote\n{}\n```\n".format(
user, error_link_md, comment)
elif event_type == "AssignedToUser":
assigned_to = payload['error']['assignedTo']
message += "{} assigned {} to {}\n".format(user,
error_link_md,
assigned_to)
message += "{} assigned {} to {}:\n".format(
user, error_link_md, assigned_to)
message += "Timestamp: {}\n".format(parse_time(payload['error']
['activityDate']))
message += "* **Timestamp**: {}\n".format(
parse_time(payload['error']['activityDate']))
message += make_app_info_chunk(payload['application'])
@@ -286,7 +283,7 @@ def compose_activity_message(payload: Dict[str, Any]) -> str:
or event_type == "CommentAdded":
return activity_message(payload)
else:
return "Unsupported event_type type: {}".format(event_type)
raise UnexpectedWebhookEventType('Raygun', event_type)
def parse_time(timestamp: str) -> str: