Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9d56d29

Browse files
committed
campfire formatting tweaks
1 parent 53602db commit 9d56d29

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

services/campfire.rb

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,31 @@
1313
throw(:halt, 400) unless campfire && campfire.login(data['token'], 'X')
1414
throw(:halt, 400) unless room = campfire.find_room_by_name(data['room'])
1515

16-
message = "[#{owner}/#{repository}/#{branch}]\n"
17-
message += commits.map do |commit|
18-
short = commit['message'].split("\n", 2).first
19-
short += ' ...' if short != commit['message']
20-
"#{commit['id'][0..6]} #{short} - #{commit['author']['name']}"
21-
end.join("\n")
16+
prefix = "[#{repository}/#{branch}]"
17+
primary, others = commits[0..4], Array(commits[5..-1])
18+
messages =
19+
primary.map do |commit|
20+
short = commit['message'].split("\n", 2).first
21+
short += ' ...' if short != commit['message']
22+
"#{prefix} #{short} - #{commit['author']['name']}"
23+
end
2224

23-
if commits.size > 1
25+
if messages.size > 1
2426
before, after = payload['before'][0..6], payload['after'][0..6]
2527
url = payload['repository']['url'] + "/compare/#{before}...#{after}"
28+
summary =
29+
if others.any?
30+
"#{prefix} (+#{others.length} more) commits #{before}...#{after}: #{url}"
31+
else
32+
"#{prefix} commits #{before}...#{after}: #{url}"
33+
end
34+
messages << summary
2635
else
2736
url = commits.first['url']
37+
messages[0] = "#{messages.first} (#{url})"
2838
end
2939

30-
room.paste message
31-
room.speak url
40+
messages.each { |line| room.speak line }
3241
room.play "rimshot" if play_sound
3342

3443
room.leave

0 commit comments

Comments
 (0)