From bf30b755cf6ef1161d1f74086058932b7c6360c2 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 15 Apr 2019 17:56:01 +0100 Subject: [PATCH] Remove HipChat integration As of February 15th, HipChat has been declared end-of-life. For more information, see https://community.atlassian.com/t5/Stride-articles/Stride-and-Hipchat-Cloud-have-reached-End-of-Life-updated/ba-p/940248 --- config/locales/client.en.yml | 16 ---- config/locales/server.en.yml | 7 -- config/settings.yml | 10 -- lib/discourse_chat/provider.rb | 1 - .../provider/hipchat/hipchat_provider.rb | 93 ------------------- .../provider/hipchat/hipchat_provider_spec.rb | 28 ------ 6 files changed, 155 deletions(-) delete mode 100644 lib/discourse_chat/provider/hipchat/hipchat_provider.rb delete mode 100644 spec/lib/discourse_chat/provider/hipchat/hipchat_provider_spec.rb diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index c9d626a..0659168 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -112,22 +112,6 @@ en: title: Webhook URL help: The webhook URL created in your Discord server settings - ####################################### - ########### HIPCHAT STRINGS ########### - ####################################### - hipchat: - title: "HipChat" - param: - name: - title: "Name" - help: "A name to describe the channel. It is not used for the connection to HipChat." - webhook_url: - title: Webhook URL - help: The webhook URL created in your HipChat integration - color: - title: Color - help: The colour of the message in HipChat. Must be one of yellow,green,red,purple,gray,random - ####################################### ######### MATTERMOST STRINGS ########## ####################################### diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 6f23bc7..60fc99a 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -32,13 +32,6 @@ en: chat_integration_discord_message_content: "The message to include above the summary when sending a notification to Discord" chat_integration_discord_excerpt_length: "Discord post excerpt length" - ####################################### - ########## HIPCHAT SETTINGS ########### - ####################################### - chat_integration_hipchat_enabled: "Enable the Hipchat chat-integration provider" - chat_integration_hipchat_icon_url: "Icon for posts to Hipchat (defaults to forum logo)" - chat_integration_hipchat_excerpt_length: "Hipchat post excerpt length" - ####################################### ######## MATTERMOST SETTINGS ########## ####################################### diff --git a/config/settings.yml b/config/settings.yml index 6aea712..e16c92c 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -50,16 +50,6 @@ chat_integration: chat_integration_discord_excerpt_length: default: 400 -####################################### -########## HIPCHAT SETTINGS ########### -####################################### - chat_integration_hipchat_enabled: - default: false - chat_integration_hipchat_icon_url: - default: '' - chat_integration_hipchat_excerpt_length: - default: 400 - ####################################### ######## MATTERMOST SETTINGS ########## ####################################### diff --git a/lib/discourse_chat/provider.rb b/lib/discourse_chat/provider.rb index 648feb9..84cffdc 100644 --- a/lib/discourse_chat/provider.rb +++ b/lib/discourse_chat/provider.rb @@ -92,7 +92,6 @@ end require_relative "provider/slack/slack_provider" require_relative "provider/telegram/telegram_provider" require_relative "provider/discord/discord_provider" -require_relative "provider/hipchat/hipchat_provider" require_relative "provider/mattermost/mattermost_provider" require_relative "provider/matrix/matrix_provider" require_relative "provider/zulip/zulip_provider" diff --git a/lib/discourse_chat/provider/hipchat/hipchat_provider.rb b/lib/discourse_chat/provider/hipchat/hipchat_provider.rb deleted file mode 100644 index a32da2a..0000000 --- a/lib/discourse_chat/provider/hipchat/hipchat_provider.rb +++ /dev/null @@ -1,93 +0,0 @@ -module DiscourseChat - module Provider - module HipchatProvider - PROVIDER_NAME = "hipchat".freeze - PROVIDER_ENABLED_SETTING = :chat_integration_hipchat_enabled - CHANNEL_PARAMETERS = [ - { key: "name", regex: '^\S+' }, - { key: "webhook_url", regex: '^\S+$', unique: true, hidden: true }, - { key: "color", regex: '^(yellow|green|red|purple|gray|random)$' } - ] - - def self.send_message(url, message) - uri = URI(url) - - http = Net::HTTP.new(uri.host, uri.port) - http.use_ssl = true - - req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json') - req.body = message.to_json - response = http.request(req) - - return response - end - - def self.generate_hipchat_message(post) - - display_name = "@#{post.user.username}" - full_name = post.user.name || "" - - if !(full_name.strip.empty?) && (full_name.strip.gsub(' ', '_').casecmp(post.user.username) != 0) && (full_name.strip.gsub(' ', '').casecmp(post.user.username) != 0) - display_name = "#{full_name} @#{post.user.username}" - end - - topic = post.topic - - message_text = I18n.t( - "chat_integration.provider.hipchat.message", - user: display_name, - post_url: post.full_url, - title: CGI::escapeHTML(topic.title), - ) - - icon_url = - if SiteSetting.chat_integration_hipchat_icon_url.present? - UrlHelper.absolute(SiteSetting.chat_integration_hipchat_icon_url) - elsif (url = (SiteSetting.try(:site_logo_small_url) || SiteSetting.logo_small_url)).present? - UrlHelper.absolute(url) - end - - message = { - message: message_text, # Fallback for clients that don't support the card markup - notify: true, - - card: { - style: "application", - url: post.full_url, - format: "medium", - id: "discoursecard:#{post.id}", - title: topic.title, - description: post.excerpt(SiteSetting.chat_integration_hipchat_excerpt_length, text_entities: true, strip_links: true, remap_emoji: true), - icon: { - url: icon_url, - }, - activity: { - html: message_text - } - } - - } - - return message - end - - def self.trigger_notification(post, channel) - - webhook_url = channel.data['webhook_url'] - - message = generate_hipchat_message(post) - - message[:color] = channel.data['color'] - - response = send_message(webhook_url, message) - - if !response.kind_of?(Net::HTTPSuccess) - error_key = nil - raise ::DiscourseChat::ProviderError.new info: { error_key: error_key, message: message, response_body: response.body } - end - - end - - end - end -end diff --git a/spec/lib/discourse_chat/provider/hipchat/hipchat_provider_spec.rb b/spec/lib/discourse_chat/provider/hipchat/hipchat_provider_spec.rb deleted file mode 100644 index 41e35aa..0000000 --- a/spec/lib/discourse_chat/provider/hipchat/hipchat_provider_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'rails_helper' - -RSpec.describe DiscourseChat::Provider::HipchatProvider do - let(:post) { Fabricate(:post) } - - describe '.trigger_notifications' do - before do - SiteSetting.chat_integration_hipchat_enabled = true - end - - let(:chan1) { DiscourseChat::Channel.create!(provider: 'hipchat', data: { name: "Awesome Channel", webhook_url: 'https://blah.hipchat.com/abcd', color: "red" }) } - - it 'sends a webhook request' do - stub1 = stub_request(:post, 'https://blah.hipchat.com/abcd').to_return(status: 200) - described_class.trigger_notification(post, chan1) - expect(stub1).to have_been_requested.once - end - - it 'handles errors correctly' do - stub1 = stub_request(:post, "https://blah.hipchat.com/abcd").to_return(status: 400) - expect(stub1).to have_been_requested.times(0) - expect { described_class.trigger_notification(post, chan1) }.to raise_exception(::DiscourseChat::ProviderError) - expect(stub1).to have_been_requested.once - end - - end - -end