capfire 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -7,8 +7,8 @@ begin
7
7
  gem.name = "capfire"
8
8
  gem.summary = %Q{Send a notification to Campfire after a cap deploy}
9
9
  gem.description = %Q{Inspired by http://github.com/blog/609-tracking-deploys-with-compare-view}
10
- gem.email = "junkiesxl@gmail.com"
11
- gem.homepage = "http://github.com/pjaspers/Capfire"
10
+ gem.email = "piet@10to1.be"
11
+ gem.homepage = "http://github.com/pjaspers/capfire"
12
12
  gem.authors = ["pjaspers", "atog"]
13
13
  gem.files = FileList['[A-Z]*',
14
14
  'generators/**/*.*',
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -27,7 +27,8 @@ campfire:
27
27
  ssl: false
28
28
  room: #{options[:chat_room]}
29
29
  message: "I (#deployer#) deployed #application# with `cap #args#` (#compare_url#)"
30
- cowsay: true
30
+ idiot_message: "LATFH: #deployer# wanted to deploy #application#, but forgot to push first."
31
+ cowsay: false
31
32
  cow: random
32
33
  CONF
33
34
  unless campfire_file_exists?
@@ -0,0 +1,108 @@
1
+ # Gem for applications to automatically post to Campfire after an deploy.
2
+
3
+ class Capfire
4
+ # To see how it actually works take a gander at the generator
5
+ # or in the capistrano.rb
6
+ class << self
7
+ def config_file_exists?
8
+ File.exists?(File.join(ENV['HOME'],'.campfire'))
9
+ end
10
+
11
+ def valid_config?
12
+ config = self.config
13
+ config["message"] && config["room"] && config ["token"] && config["account"]
14
+ end
15
+
16
+ def config
17
+ YAML::load(File.open(File.join(ENV['HOME'],'.campfire')))["campfire"]
18
+ end
19
+
20
+ # Campfire room
21
+ def room
22
+ self.config["room"]
23
+ end
24
+
25
+ # Campfire account
26
+ def account
27
+ self.config["account"]
28
+ end
29
+
30
+ # Campfire token
31
+ def token
32
+ self.config["token"]
33
+ end
34
+
35
+ # `brew install cowsay && cowsay "capfire"`
36
+ # _________
37
+ #< capfire >
38
+ # ---------
39
+ # \ ^__^
40
+ # \ (oo)\_______
41
+ # (__)\ )\/\
42
+ # ||----w |
43
+ # || ||
44
+ def cowsay?
45
+ config["cowsay"] && self.bin_installed?("cowsay")
46
+ end
47
+
48
+ # Who is deploying
49
+ def deployer
50
+ Etc.getlogin
51
+ end
52
+
53
+ # Link to github's excellent Compare View
54
+ def github_compare_url(repo_url, first_commit, last_commit)
55
+ repo_url.gsub!(/git@/, 'http://')
56
+ repo_url.gsub!(/\.com:/,'.com/')
57
+ repo_url.gsub!(/\.git/, '')
58
+ "#{repo_url}/compare/#{first_commit}...#{last_commit}"
59
+ end
60
+
61
+ def default_idiot_message
62
+ "LATFH: #deployer# wanted to deploy #application#, but forgot to push first."
63
+ end
64
+
65
+ # Message to post on deploying without pushing
66
+ def idiot_message(application)
67
+ message = self.config["idiot_message"]
68
+ message = default_idiot_message unless message
69
+ message.gsub!(/#deployer#/, self.deployer)
70
+ message.gsub!(/#application#/, application)
71
+ message
72
+ end
73
+
74
+ # Message to post to campfire on deploy
75
+ def deploy_message(args,compare_url, application)
76
+ message = self.config["message"]
77
+ message.gsub!(/#deployer#/, deployer)
78
+ message.gsub!(/#application#/, application)
79
+ message.gsub!(/#args#/, args)
80
+ message.gsub!(/#compare_url#/, compare_url)
81
+ message
82
+ end
83
+
84
+ # Quick and irty way to check for installed bins
85
+ # Ideally this should also check if it's in the users
86
+ # path etc. Skipping for now.
87
+ def bin_installed?(bin_name)
88
+ !`which #{bin_name}`.empty?
89
+ end
90
+
91
+ # Initializes a broach campfire room
92
+ def broach_room
93
+ Broach.settings = {
94
+ 'account' => self.account,
95
+ 'token' => self.token,
96
+ 'use_ssl' => true
97
+ }
98
+ Broach::Room.find_by_name(self.room)
99
+ end
100
+
101
+ # Posts to campfire
102
+ def speak(message)
103
+ self.broach_room.speak(message)
104
+ end
105
+
106
+ end
107
+
108
+ end
@@ -1,49 +1,64 @@
1
- # Defines deploy:notify_campfire
1
+ # Capistrano task for posting to Campfire.
2
+ #
3
+ # There are two ways to use Capfire, either run the generator (see the README)
4
+ # or add 'require "capfire/capistrano"' to your deploy.rb.
2
5
 
3
6
  require 'broach'
7
+ require 'capfire'
4
8
 
5
9
  Capistrano::Configuration.instance(:must_exist).load do
6
-
7
10
  # Don't bother users who have capfire installed but don't have a ~/.campfire file
8
- if File.exists?(File.join(ENV['HOME'],'.campfire'))
9
- after "deploy:update_code", "deploy:notify_campfire"
11
+
12
+ if Capfire.config_file_exists?
13
+ if Capfire.valid_config?
14
+ before "deploy:update_code", "capfire:check_for_push"
15
+ after "deploy:update_code", "capfire:post_to_campfire"
16
+ else
17
+ logger.info "Not all required keys found in your .campfire file. Please regenerate."
18
+ end
19
+ else
20
+ logger.info "Couldn't find a .campfire in your home directory."
10
21
  end
11
22
 
12
- namespace :deploy do
13
- desc "Posting a message to Campfire"
14
- task :notify_campfire do
23
+ namespace :capfire do
24
+
25
+ desc "Check if local version was pushed to github"
26
+ task :check_for_push do
27
+ deployed_version = current_revision[0,7] rescue "0000000"
28
+ local_version = `git rev-parse HEAD`[0,7]
29
+ if deployed_version == local_version
30
+ `say -v "Cellos" fail` if Capfire.bin_installed?("say")
31
+ Capfire.speak(Capfire.idiot_message(application)) unless dry_run
32
+ logger.important "\nDidn't you forget something? A hint: `git push`."
33
+ exit
34
+ end
35
+ end
36
+
37
+ desc <<-DESC
38
+ This will post to the campfire room as specified in your ~/.campfire. \
39
+ The message posted will contain a link to Github's excellent compare view, \
40
+ the commiters name, the project name and the arguments supplied to cap.
41
+ DESC
42
+ task :post_to_campfire do
15
43
  begin
16
44
  source_repo_url = repository
17
- deployer = Etc.getlogin
18
- deploying = `git rev-parse HEAD`[0,7]
19
- begin
20
- deployed = previous_revision[0,7]
21
- rescue
22
- deployed = "000000"
45
+ deployed_version = previous_revision[0,7] rescue "000000"
46
+ local_version = `git rev-parse HEAD`[0,7]
47
+
48
+ compare_url = Capfire.github_compare_url source_repo_url, deployed_version, local_version
49
+ message = Capfire.deploy_message(ARGV.join(' '), compare_url, application)
50
+ message = `cowsay "#{message}"` if Capfire.cowsay?
51
+
52
+ if dry_run
53
+ logger.info "Capfire would have posted:\n#{message}"
54
+ else
55
+ Capfire.speak message
23
56
  end
24
- puts "Posting to Campfire"
25
- # Getting the github url
26
- github_url = repository.gsub(/git@/, 'http://').gsub(/\.com:/,'.com/').gsub(/\.git/, '')
27
- compare_url = "#{github_url}/compare/#{deployed}...#{deploying}"
28
-
29
- # Reading the config file and drill in on the campfire section of course.
30
- config = YAML::load(File.open(File.join(ENV['HOME'],'.campfire')))["campfire"]
31
-
32
- # Ugly but it does the job.
33
- message = config["message"].gsub(/#deployer#/, deployer).gsub(/#application#/, application).gsub(/#args#/, ARGV.join(' ')).gsub(/#compare_url#/,compare_url)
34
-
35
- message = `cowsay "#{message}"` if config["cowsay"]
36
-
37
- # Posting the message.
38
- Broach.settings = {
39
- 'account' => config["account"],
40
- 'token' => config["token"],
41
- 'use_ssl' => true
42
- }
43
- room = Broach::Room.find_by_name(config["room"])
44
- room.speak(message)
57
+ logger.info "Posting to Campfire"
45
58
  rescue => e
46
- puts e.message
59
+ # Making sure we don't make capistrano fail.
60
+ # Cause nothing sucks donkeyballs like not being able to deploy
61
+ logger.important e.message
47
62
  end
48
63
  end
49
64
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capfire
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - pjaspers
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-10-28 00:00:00 +02:00
19
+ date: 2011-03-05 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -50,7 +50,7 @@ dependencies:
50
50
  type: :runtime
51
51
  version_requirements: *id002
52
52
  description: Inspired by http://github.com/blog/609-tracking-deploys-with-compare-view
53
- email: junkiesxl@gmail.com
53
+ email: piet@10to1.be
54
54
  executables: []
55
55
 
56
56
  extensions: []
@@ -66,12 +66,12 @@ files:
66
66
  - generators/capfire_generator.rb
67
67
  - generators/lib/insert_commands.rb
68
68
  - generators/templates/capistrano_hook.rb
69
- - lib/Capfire.rb
69
+ - lib/capfire.rb
70
70
  - lib/capfire/capistrano.rb
71
71
  - test/helper.rb
72
72
  - test/test_Capfire.rb
73
73
  has_rdoc: true
74
- homepage: http://github.com/pjaspers/Capfire
74
+ homepage: http://github.com/pjaspers/capfire
75
75
  licenses: []
76
76
 
77
77
  post_install_message:
@@ -1,6 +0,0 @@
1
- # Gem for applications to automatically post to Campfire after an deploy.
2
- module Capfire
3
- # Nothing to see here, take a gander at the generator
4
- # or in the capistrano.rb
5
- end
6
-