Skip to content

Commit

Permalink
Fix slackbot (#54457)
Browse files Browse the repository at this point in the history
Typo in the payload being sent to the webhook, hence the 400 status code
error.
I added better testing, as well as not raising an error (as to keep the
automator running in case this fails again).
  • Loading branch information
kneeyo1 authored Aug 9, 2023
1 parent 6ba95b8 commit 0dead08
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/sentry/options/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -1455,3 +1455,9 @@
default=[],
flags=FLAG_PRIORITIZE_DISK | FLAG_AUTOMATOR_MODIFIABLE,
)

register(
"options_automator_slack_webhook_enabled",
default=True,
flags=FLAG_AUTOMATOR_MODIFIABLE,
)
9 changes: 7 additions & 2 deletions src/sentry/runner/commands/presenters/slackpresenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import requests
from django.conf import settings

from sentry import options
from sentry.runner.commands.presenters.optionspresenter import OptionsPresenter
from sentry.utils import json

Expand All @@ -29,15 +30,19 @@ def __init__(self) -> None:

@staticmethod
def is_slack_enabled():
if not settings.OPTIONS_AUTOMATOR_SLACK_WEBHOOK_URL:

if not (
options.get("options_automator_slack_webhook_enabled")
and settings.OPTIONS_AUTOMATOR_SLACK_WEBHOOK_URL
):
return False
try:
test_payload: dict = {
"drifted_options": [],
"updated_options": [],
"set_options": [],
"unset_options": [],
"not_writable": [],
"not_writable_options": [],
"unregistered_options": [],
"invalid_type_options": [],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def setup(self):
def test_is_slack_enabled(self):
responses.add(responses.POST, "https://test/", status=200)

assert self.slackPresenter.is_slack_enabled()
self.slackPresenter.set("option1", "value1")
self.slackPresenter.set("option2", "value2")

Expand Down Expand Up @@ -75,5 +76,5 @@ def test_is_slack_enabled(self):
],
}

assert responses.calls[0].response.status_code == 200
assert expected_json_data == json.loads(responses.calls[0].request.body)
assert responses.calls[1].response.status_code == 200
assert expected_json_data == json.loads(responses.calls[1].request.body)

0 comments on commit 0dead08

Please sign in to comment.