From 107847a4bb19e316e74172d1c0963e4224091f85 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Tue, 16 Dec 2014 14:34:43 +0200 Subject: [PATCH] Fix Slack notification setup to support the new slack web hook format and convert all existing data to use the new format (so we only have one code path) --- .../5b84373e5db_convert_slack_webhook_data.py | 24 +++++++++ endpoints/notificationmethod.py | 17 ++---- .../create-external-notification-dialog.html | 5 +- static/js/app.js | 19 +++---- tools/migrateslackwebhook.py | 54 +++++++++++++++++++ 5 files changed, 97 insertions(+), 22 deletions(-) create mode 100644 data/migrations/versions/5b84373e5db_convert_slack_webhook_data.py create mode 100644 tools/migrateslackwebhook.py diff --git a/data/migrations/versions/5b84373e5db_convert_slack_webhook_data.py b/data/migrations/versions/5b84373e5db_convert_slack_webhook_data.py new file mode 100644 index 000000000..87aaf84a3 --- /dev/null +++ b/data/migrations/versions/5b84373e5db_convert_slack_webhook_data.py @@ -0,0 +1,24 @@ +"""Convert slack webhook data + +Revision ID: 5b84373e5db +Revises: 1c5b738283a5 +Create Date: 2014-12-16 12:02:55.167744 + +""" + +# revision identifiers, used by Alembic. +revision = '5b84373e5db' +down_revision = '1c5b738283a5' + +from alembic import op +import sqlalchemy as sa + +from tools.migrateslackwebhook import run_slackwebhook_migration + + +def upgrade(tables): + run_slackwebhook_migration() + + +def downgrade(tables): + pass diff --git a/endpoints/notificationmethod.py b/endpoints/notificationmethod.py index d7085f1f0..52464fda0 100644 --- a/endpoints/notificationmethod.py +++ b/endpoints/notificationmethod.py @@ -363,11 +363,8 @@ class SlackMethod(NotificationMethod): return 'slack' def validate(self, repository, config_data): - if not config_data.get('token', ''): - raise CannotValidateNotificationMethodException('Missing Slack Token') - - if not config_data.get('subdomain', '').isalnum(): - raise CannotValidateNotificationMethodException('Missing Slack Subdomain Name') + if not config_data.get('url', ''): + raise CannotValidateNotificationMethodException('Missing Slack Callback URL') def format_for_slack(self, message): message = message.replace('\n', '') @@ -378,10 +375,8 @@ class SlackMethod(NotificationMethod): def perform(self, notification, event_handler, notification_data): config_data = json.loads(notification.config_json) - token = config_data.get('token', '') - subdomain = config_data.get('subdomain', '') - - if not token or not subdomain: + url = config_data.get('url', '') + if not url: return owner = model.get_user_or_org(notification.repository.namespace_user.username) @@ -389,8 +384,6 @@ class SlackMethod(NotificationMethod): # Something went wrong. return - url = 'https://%s.slack.com/services/hooks/incoming-webhook?token=%s' % (subdomain, token) - level = event_handler.get_level(notification_data['event_data'], notification_data) color = { 'info': '#ffffff', @@ -426,5 +419,5 @@ class SlackMethod(NotificationMethod): raise NotificationMethodPerformException(error_message) except requests.exceptions.RequestException as ex: - logger.exception('Slack method was unable to be sent: %s' % ex.message) + logger.exception('Slack method was unable to be sent: %s', ex.message) raise NotificationMethodPerformException(ex.message) diff --git a/static/directives/create-external-notification-dialog.html b/static/directives/create-external-notification-dialog.html index 650862690..03479015b 100644 --- a/static/directives/create-external-notification-dialog.html +++ b/static/directives/create-external-notification-dialog.html @@ -73,7 +73,7 @@
- {{ field.title }}: + {{ field.title }}:
@@ -81,6 +81,9 @@ +