/
capfire.rb
111 lines (93 loc) · 2.73 KB
/
capfire.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Gem for applications to automatically post to Campfire after an deploy.
require 'broach'
require 'etc'
class Capfire
# To see how it actually works take a gander at the generator
# or in the capistrano.rb
class << self
def config_file_exists?
File.exists?(File.join(ENV['HOME'],'.campfire'))
end
def valid_config?
config = self.config
config["message"] && config["room"] && config ["token"] && config["account"]
end
def config
YAML::load(File.open(File.join(ENV['HOME'],'.campfire')))["campfire"]
end
# Campfire room
def room
self.config["room"]
end
# Campfire account
def account
self.config["account"]
end
# Campfire token
def token
self.config["token"]
end
# `brew install cowsay && cowsay "capfire"`
# _________
#< capfire >
# ---------
# \ ^__^
# \ (oo)\_______
# (__)\ )\/\
# ||----w |
# || ||
def cowsay?
config["cowsay"] && self.bin_installed?("cowsay")
end
# Who is deploying
def deployer
Etc.getlogin
end
# Link to github's excellent Compare View
def github_compare_url(repo_url, first_commit, last_commit)
repo_url.gsub!(/git@/, 'http://')
repo_url.gsub!(/\.com:/,'.com/')
repo_url.gsub!(/\.git/, '')
"#{repo_url}/compare/#{first_commit}...#{last_commit}"
end
def default_idiot_message
"LATFH: #deployer# wanted to deploy #application#, but forgot to push first."
end
# Message to post on deploying without pushing
def idiot_message(application)
message = self.config["idiot_message"]
message = default_idiot_message unless message
message.gsub!(/#deployer#/, self.deployer)
message.gsub!(/#application#/, application)
message
end
# Message to post to campfire on deploy
def deploy_message(args,compare_url, application)
message = self.config["message"]
message.gsub!(/#deployer#/, deployer)
message.gsub!(/#application#/, application)
message.gsub!(/#args#/, args)
message.gsub!(/#compare_url#/, compare_url)
message
end
# Quick and irty way to check for installed bins
# Ideally this should also check if it's in the users
# path etc. Skipping for now.
def bin_installed?(bin_name)
!`which #{bin_name}`.empty?
end
# Initializes a broach campfire room
def broach_room
Broach.settings = {
'account' => self.account,
'token' => self.token,
'use_ssl' => true
}
Broach::Room.find_by_name(self.room)
end
# Posts to campfire
def speak(message)
self.broach_room.speak(message)
end
end
end