Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/cc/services/slack.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class CC::Service::Slack < CC::Service
class Config < CC::Service::Config
attribute :url, String,
attribute :webhook_url, String,
label: "Webhook URL",
description: "The Slack webhook URL you would like message posted to"

Expand Down Expand Up @@ -42,6 +42,7 @@ def speak(message, options = {})
body[:channel] = config.channel
end

http_post(config.url, body)
http.headers['Content-Type'] = 'application/json'
http_post(config.webhook_url, body.to_json)
end
end
17 changes: 17 additions & 0 deletions service_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env ruby
#
# Ad-hoc script for sending the test event to service classes
#
###
require 'cc/services'
CC::Service.load_services

def test_service(klass, config)
service = klass.new(:test, config, { repo_name: "Example" })
service.receive
end

test_service(CC::Service::Slack, {
webhook_url: "...",
channel: "..."
})
4 changes: 2 additions & 2 deletions test/slack_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def test_multiple_vulnerabilities

def assert_slack_receives(event_name, emoji, event_data, expected_body)
@stubs.post '/token' do |env|
body = Hash[URI.decode_www_form(env[:body])]
body = JSON.parse(env[:body])
assert_equal "Code Climate", body["username"]
assert_equal emoji, body["icon_emoji"] # may be nil
assert_equal expected_body, body["text"]
Expand All @@ -109,7 +109,7 @@ def assert_slack_receives(event_name, emoji, event_data, expected_body)
receive(
CC::Service::Slack,
event_name,
{ url: "http://api.slack.com/token", channel: "#general" },
{ webhook_url: "http://api.slack.com/token", channel: "#general" },
event_data
)
end
Expand Down