capfire 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 pjaspers
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,27 @@
1
+ = Capfire
2
+
3
+ Inspired by http://github.com/blog/609-tracking-deploys-with-compare-view we , http://10to1.be, wanted the same for our deploys without having to copy paste each deploy script.
4
+
5
+ This gem adds a way to send a message to campfire after a deploy, in the message is the app-name, the github-compare view url and the deployer.
6
+
7
+ == Install
8
+ `gem install capfire`
9
+
10
+ `script/generate capfire -k "campfire_token" -r "chat_room" -a "campfire_account"`
11
+ This will generate a ~/.campfire file containing these settings. Feel free to edit it by hand, or run the generator with bogus data, it's a simple yaml file.
12
+
13
+ If the user doesn't have a ~/.campfire file it won't try to send a message to Campfire.
14
+
15
+ == Note on Patches/Pull Requests
16
+
17
+ * Fork the project.
18
+ * Make your feature addition or bug fix.
19
+ * Add tests for it. This is important so I don't break it in a
20
+ future version unintentionally.
21
+ * Commit, do not mess with rakefile, version, or history.
22
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
23
+ * Send me a pull request. Bonus points for topic branches.
24
+
25
+ == Copyright
26
+
27
+ Copyright (c) 2010 Piet Jaspers 10to1. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "capfire"
8
+ gem.summary = %Q{Send a notification to Campfire after a deploy}
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"
12
+ gem.authors = ["pjaspers"]
13
+ gem.files = FileList['[A-Z]*',
14
+ 'generators/**/*.*',
15
+ 'lib/**/*.rb',
16
+ 'lib/templates/*.erb']
17
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
18
+ gem.add_dependency('broach', '>= 0.1.4')
19
+ end
20
+ Jeweler::GemcutterTasks.new
21
+ rescue LoadError
22
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
+ end
24
+
25
+ require 'rake/testtask'
26
+ Rake::TestTask.new(:test) do |test|
27
+ test.libs << 'lib' << 'test'
28
+ test.pattern = 'test/**/test_*.rb'
29
+ test.verbose = true
30
+ end
31
+
32
+ begin
33
+ require 'rcov/rcovtask'
34
+ Rcov::RcovTask.new do |test|
35
+ test.libs << 'test'
36
+ test.pattern = 'test/**/test_*.rb'
37
+ test.verbose = true
38
+ end
39
+ rescue LoadError
40
+ task :rcov do
41
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
42
+ end
43
+ end
44
+
45
+ task :test => :check_dependencies
46
+
47
+ task :default => :test
48
+
49
+ require 'rake/rdoctask'
50
+ Rake::RDocTask.new do |rdoc|
51
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
52
+
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = "Capfire #{version}"
55
+ rdoc.rdoc_files.include('README*')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,48 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
2
+
3
+ class CapfireGenerator < Rails::Generator::Base
4
+ def add_options!(opt)
5
+ puts "Adding options"
6
+ opt.on('-a', '--account=account', String, "Your account") {|v| options[:campfire_account] = v}
7
+ opt.on('-k', '--token=token', String, "Your token key") {|v| options[:campfire_token] = v}
8
+ opt.on('-r', '--chatroom=room', String, "The chatroom") {|v| options[:chat_room] = v}
9
+ end
10
+
11
+ def manifest
12
+ if campfire_file_exists?
13
+ puts "You already have a ~/.campfire file, please remove this to use the generator"
14
+ exit
15
+ end
16
+ if !options[:campfire_token] && !options[:chat_room] && !options[:campfire_account]
17
+ puts options.inspect
18
+ puts "Token and chat room are required"
19
+ exit
20
+ end
21
+
22
+ record do |m|
23
+ if ['config/deploy.rb', 'Capfile'].all? { |file| File.exists?(file) }
24
+ m.append_to 'config/deploy.rb', capistrano_hook
25
+ end
26
+
27
+ conf = <<-CONF
28
+ campfire:
29
+ account: #{options[:campfire_account]}
30
+ token: #{options[:campfire_token]}
31
+ room: #{options[:chat_room]}
32
+ CONF
33
+ puts options.inspect
34
+ File.open(File.join(ENV['HOME'],'.campfire'), 'w') do |out|
35
+ out.write(conf)
36
+ end
37
+ end
38
+ end
39
+
40
+
41
+ def campfire_file_exists?
42
+ File.exists?(File.join(ENV['HOME'],'.campfire'))
43
+ end
44
+
45
+ def capistrano_hook
46
+ IO.read(source_path('capistrano_hook.rb'))
47
+ end
48
+ end
@@ -0,0 +1,35 @@
1
+ # Completely pinched from the hoptoad-notifier
2
+ # Mostly pinched from http://github.com/ryanb/nifty-generators/tree/master
3
+
4
+ Rails::Generator::Commands::Base.class_eval do
5
+ def file_contains?(relative_destination, line)
6
+ File.read(destination_path(relative_destination)).include?(line)
7
+ end
8
+ end
9
+
10
+ Rails::Generator::Commands::Create.class_eval do
11
+ def append_to(file, line)
12
+ logger.insert "#{line} appended to #{file}"
13
+ unless options[:pretend] || file_contains?(file, line)
14
+ File.open(file, "a") do |file|
15
+ file.puts
16
+ file.puts line
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ Rails::Generator::Commands::Destroy.class_eval do
23
+ def append_to(file, line)
24
+ logger.remove "#{line} removed from #{file}"
25
+ unless options[:pretend]
26
+ gsub_file file, "\n#{line}", ''
27
+ end
28
+ end
29
+ end
30
+
31
+ Rails::Generator::Commands::List.class_eval do
32
+ def append_to(file, line)
33
+ logger.insert "#{line} appended to #{file}"
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ Dir[File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'capfire-*')].each do |vendored_notifier|
2
+ $: << File.join(vendored_notifier, 'lib')
3
+ end
4
+
5
+ require 'capfire/capistrano'
data/lib/capfire.rb ADDED
@@ -0,0 +1,7 @@
1
+
2
+
3
+ # Gem for applications to automatically post errors to the Hoptoad of their choice.
4
+ module Capfire
5
+
6
+ end
7
+
@@ -0,0 +1,32 @@
1
+ # Defines deploy:notify_hoptoad which will send information about the deploy to Hoptoad.
2
+
3
+ Capistrano::Configuration.instance(:must_exist).load do
4
+
5
+ if File.exists?(File.join(ENV['HOME'],'.campfire'))
6
+ after "deploy:update_code", "deploy:notify_campfire"
7
+ end
8
+
9
+ namespace :deploy do
10
+ desc "Posting a message to Campfire"
11
+ task :notify_campfire do
12
+ source_repo_url = repository
13
+ deployer = Etc.getlogin
14
+ deploying = `git rev-parse HEAD`[0,7]
15
+ begin
16
+ deployed = previous_revision[0,7]
17
+ rescue
18
+ deployed = "000000"
19
+ end
20
+ puts "Posting to Campfire"
21
+ # Getting the github url
22
+ github_url = repository.gsub(/git@/, 'http://').gsub(/\.com:/,'.com/').gsub(/\.git/, '')
23
+ compare_url = "#{github_url}/compare/#{deployed}...#{deploying}"
24
+ config = YAML::load(File.open(File.join(ENV['HOME'],'.campfire')))
25
+ Broach.settings = { 'account' => config["campfire"]["account"], 'token' => config["campfire"]["token"] }
26
+ Broach.speak(campfire_room,
27
+ "I (#{deployer}) deployed #{application} " +
28
+ "with `cap #{ARGV.join(' ')}` (#{compare_url})"
29
+ )
30
+ end
31
+ end
32
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'Capfire'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestCapfire < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capfire
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - pjaspers
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-25 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: thoughtbot-shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :development
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: broach
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ - 1
42
+ - 4
43
+ version: 0.1.4
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ description: Inspired by http://github.com/blog/609-tracking-deploys-with-compare-view
47
+ email: junkiesxl@gmail.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - LICENSE
54
+ - README.rdoc
55
+ files:
56
+ - LICENSE
57
+ - README.rdoc
58
+ - Rakefile
59
+ - VERSION
60
+ - generators/capfire_generator.rb
61
+ - generators/lib/insert_commands.rb
62
+ - generators/templates/capistrano_hook.rb
63
+ - lib/capfire.rb
64
+ - lib/capfire/capistrano.rb
65
+ has_rdoc: true
66
+ homepage: http://github.com/pjaspers/Capfire
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --charset=UTF-8
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ requirements: []
89
+
90
+ rubyforge_project:
91
+ rubygems_version: 1.3.6
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Send a notification to Campfire after a deploy
95
+ test_files:
96
+ - test/helper.rb
97
+ - test/test_Capfire.rb