Permalink
Browse files

show campfire messages when branches are created/deleted

  • Loading branch information...
tmm1 committed Mar 5, 2011
1 parent 5c4eebd commit 13a2ea40ecd370cde6b241d9a1d4879319d9440f
Showing with 39 additions and 21 deletions.
  1. +39 −21 services/campfire.rb
View
@@ -5,12 +5,16 @@
repository = payload['repository']['name']
owner = payload['repository']['owner']['name']
branch = payload['ref_name']
commits = payload['commits']
before = payload['before']
after = payload['after']
compare_url = payload['compare']
commits = payload['commits']
commits.reject! { |commit|
commit['message'].to_s.strip == '' || commit['distinct'] == false
}
next if commits.empty?
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
@@ -23,27 +27,41 @@
end
prefix = "[#{repository}/#{branch}]"
primary, others = commits[0..4], Array(commits[5..-1])
messages =
primary.map do |commit|
short = commit['message'].split("\n", 2).first
short += ' ...' if short != commit['message']
"#{prefix} #{short} - #{commit['author']['name']}"
end
messages = []
if messages.size > 1
before, after = payload['before'][0..6], payload['after'][0..6]
url = compare_url
summary =
if others.any?
"#{prefix} (+#{others.length} more) commits #{before}...#{after}: #{url}"
else
"#{prefix} commits #{before}...#{after}: #{url}"
if created
messages << "#{prefix} #{branch} created"
elsif deleted
messages << "#{prefix} #{branch} deleted"
elsif forced
messages << "#{prefix} #{branch} force-pushed"
end
if commits.any?
primary, others = commits[0..4], Array(commits[5..-1])
commit_messages =
primary.map do |commit|
short = commit['message'].split("\n", 2).first
short += ' ...' if short != commit['message']
"#{prefix} #{short} - #{commit['author']['name']}"
end
messages << summary
else
url = commits.first['url']
messages[0] = "#{messages.first} (#{url})"
if commit_messages.size > 1
before, after = payload['before'][0..6], payload['after'][0..6]
url = compare_url
summary =
if others.any?
"#{prefix} (+#{others.length} more) commits #{before}...#{after}: #{url}"
else
"#{prefix} commits #{before}...#{after}: #{url}"
end
commit_messages << summary
else
url = commits.first['url']
commit_messages[0] = "#{commit_messages.first} (#{url})"
end
messages += commit_messages
end
begin

0 comments on commit 13a2ea4

Please sign in to comment.