Skip to content

Commit

Permalink
better created/deleted/forced messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Mar 5, 2011
1 parent 001aa02 commit 4dfd162
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions services/campfire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

repository = payload['repository']['name']
owner = payload['repository']['owner']['name']
pusher = payload['pusher']['name']
branch = payload['ref_name']
before = payload['before']
after = payload['after']
compare_url = payload['compare']
commits = payload['commits']
commits.reject! { |commit|
Expand All @@ -26,18 +25,33 @@
raise GitHub::ServiceConfigurationError, "No such room"
end

prefix = "[#{repository}/#{branch}]"
before, after = payload['before'][0..6], payload['after'][0..6]
url = compare_url
branch_url = url.gsub(/compare.+$/, "commits/#{branch}")
messages = []

if created
messages << "#{prefix} branch created"
messages << "[#{repository}] #{pusher} created #{branch}"
messages[0] += " from #{payload['base']}" if payload['base']

if commits.empty?
messages[0] += " at #{after}" unless payload['base']
messages[0] += ": #{branch_url}"
else
messages[0] += " (+#{commits.size} new commits)"
end

elsif deleted
messages << "#{prefix} branch deleted"
commit_url = url.gsub(/compare.+$/, "commit/#{payload['before']}")
messages << "[#{repository}] #{pusher} deleted #{branch} at #{before}: #{commit_url}"

elsif forced
messages << "#{prefix} branch force-pushed"
messages << "[#{repository}] #{pusher} force-pushed #{branch} from #{before} to #{after}"
messages[0] += ": #{branch_url}" if commits.empty?
end

if commits.any?
prefix = "[#{repository}/#{branch}]"
primary, others = commits[0..4], Array(commits[5..-1])
commit_messages =
primary.map do |commit|
Expand All @@ -47,8 +61,6 @@
end

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}"
Expand Down

0 comments on commit 4dfd162

Please sign in to comment.