Skip to content

Commit

Permalink
avoid logging into campfire when there are no messages to send
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Mar 5, 2011
1 parent 4dfd162 commit 9d81e4c
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions services/campfire.rb
Expand Up @@ -14,17 +14,6 @@
created, deleted, forced = payload.values_at('created','deleted','forced')
next unless created or deleted or forced or commits.any?

campfire = Tinder::Campfire.new(data['subdomain'], :ssl => true)
play_sound = data['play_sound'].to_i == 1

if !campfire.login(data['token'], 'X')
raise GitHub::ServiceConfigurationError, "Invalid token"
end

if (room = campfire.find_room_by_name(data['room'])).nil?
raise GitHub::ServiceConfigurationError, "No such room"
end

before, after = payload['before'][0..6], payload['after'][0..6]
url = compare_url
branch_url = url.gsub(/compare.+$/, "commits/#{branch}")
Expand Down Expand Up @@ -53,6 +42,7 @@
if commits.any?
prefix = "[#{repository}/#{branch}]"
primary, others = commits[0..4], Array(commits[5..-1])

commit_messages =
primary.map do |commit|
short = commit['message'].split("\n", 2).first
Expand All @@ -76,7 +66,20 @@
messages += commit_messages
end

next if messages.empty?

begin
campfire = Tinder::Campfire.new(data['subdomain'], :ssl => true)
play_sound = data['play_sound'].to_i == 1

if !campfire.login(data['token'], 'X')
raise GitHub::ServiceConfigurationError, "Invalid token"
end

if (room = campfire.find_room_by_name(data['room'])).nil?
raise GitHub::ServiceConfigurationError, "No such room"
end

messages.each { |line| room.speak line }
room.play "rimshot" if play_sound

Expand Down

0 comments on commit 9d81e4c

Please sign in to comment.