Skip to content
This repository was archived by the owner on Jan 31, 2019. 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
4 changes: 2 additions & 2 deletions docs/talker
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Install Notes
1. url should be your room url, for example https://youraccount.talkerapp.com/rooms/ROOM_ID
2. token should be on your settings page
3. if digest is checked, all commits will be compressed in one message

Note: replace https with http on the url if you're on the Free plan as it doesn't include enhanced security (SSL).

Developer Notes
Expand All @@ -19,4 +19,4 @@ data
- digest (boolean)

payload
- refer to docs/github_payload
- refer to docs/github_payload
49 changes: 37 additions & 12 deletions services/talker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,44 @@ def receive_push
repository = payload['repository']['name']
branch = branch_name
commits = payload['commits']
token = data['token']

http.ssl[:verify] = false
http.headers["X-Talker-Token"] = token
http.url_prefix = data['url']

if data['digest'].to_i == 1 and commits.size > 1
http_post 'messages.json', :message => "#{summary_message} – #{summary_url}"
else
http_post 'messages.json', :message => "#{pusher_name} pushed the following commits:"
commit_messages.each do |message|
http_post 'messages.json', :message => message

prepare_http

say "#{summary_message} – #{summary_url}"
if data['digest'].to_i == 0
if distinct_commits.size == 1
commit = distinct_commits.first
say format_commit_message(commit)
else
distinct_commits.each do |commit|
say "#{format_commit_message(commit)} – #{commit['url']}"
end
end
end
end

def receive_pull_request
return unless opened?

prepare_http
say summary_message
end

def receive_issues
return unless opened?

prepare_http
say summary_message
end

private
def prepare_http
http.ssl[:verify] = false
http.headers["X-Talker-Token"] = data['token']
http.url_prefix = data['url']
end

def say(message)
http_post 'messages.json', :message => message
end
end
60 changes: 49 additions & 11 deletions test/talker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,59 @@ def setup
@stubs = Faraday::Adapter::Test::Stubs.new
end

def test_push
@stubs.post "/room/1/messages.json" do |env|
assert_equal 's.talkerapp.com', env[:url].host
assert_equal 't', env[:request_headers]['x-talker-token']
data = Rack::Utils.parse_nested_query(env[:body])
assert data.key?('message')
[200, {}, '']
end
def test_push_with_digest_on
stub_message_posting

svc = service({'url' => 'https://s.talkerapp.com/room/1', 'token' => 't'}, payload)
svc = service(:push, {'digest' => '1'}, push_payload)
svc.receive_push
end

def service(*args)
super Service::Talker, *args
def test_push_with_digest_off_and_several_distinct_commits
stub_message_posting

payload = push_payload
assert payload['commits'].size > 1

svc = service(:push, {'digest' => '0'}, payload)
svc.receive_push
end

def test_push_with_digest_off_and_a_single_distinct_commit
stub_message_posting

payload = push_payload
payload['commits'] = [payload['commits'].first]

svc = service(:push, {'digest' => '0'}, payload)
svc.receive_push
end

def test_pull_request
stub_message_posting
svc = service(:pull_request, {}, pull_payload)
svc.receive_pull_request
end

def test_issues
stub_message_posting
svc = service(:issues, {}, issues_payload)
svc.receive_issues
end

def service(event, options = {}, *args)
default_options = {'url' => 'https://s.talkerapp.com/room/1', 'token' => 't'}
super Service::Talker, event, default_options.merge(options), *args
end

private
def stub_message_posting
@stubs.post "/room/1/messages.json" do |env|
assert_equal 's.talkerapp.com', env[:url].host
assert_equal 't', env[:request_headers]['x-talker-token']
data = Rack::Utils.parse_nested_query(env[:body])
assert data.key?('message')
[200, {}, '']
end
end
end