capistrano-blaze 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -1
- data/.travis.yml +12 -0
- data/README.md +4 -18
- data/capistrano-blaze.gemspec +2 -0
- data/lib/capistrano/blaze.rb +18 -42
- data/lib/capistrano/blaze/configuration.rb +38 -0
- data/lib/capistrano/blaze/message.rb +75 -0
- data/lib/capistrano/blaze/recipes.rb +8 -3
- data/lib/capistrano/blaze/version.rb +1 -1
- data/spec/blaze_spec.rb +33 -0
- data/spec/configuration_spec.rb +20 -0
- data/spec/message_spec.rb +68 -0
- metadata +36 -7
- data/spec/camp_spec.rb +0 -63
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm 1.9.3@capistrano-blaze
|
1
|
+
rvm 1.9.3-p125@capistrano-blaze
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# Capistrano::Blaze
|
2
2
|
|
3
|
-
|
4
|
-
my attempt at making it easier.
|
3
|
+
[![Build Status](https://secure.travis-ci.org/iain/capistrano-blaze.png?branch=master)](http://travis-ci.org/iain/capistrano-blaze)
|
5
4
|
|
6
|
-
This gem
|
7
|
-
|
5
|
+
This tiny gem notifies you on Campfire when you use Capistrano. The only
|
6
|
+
thing you have to configure is your Campfire credentials, the proper hooks are
|
7
|
+
automatically added.
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -14,20 +14,6 @@ Add this line to your application's Gemfile:
|
|
14
14
|
gem 'capistrano-blaze', :require => false
|
15
15
|
```
|
16
16
|
|
17
|
-
And then execute:
|
18
|
-
|
19
|
-
``` shell
|
20
|
-
$ bundle
|
21
|
-
```
|
22
|
-
|
23
|
-
Or install it yourself as:
|
24
|
-
|
25
|
-
``` shell
|
26
|
-
$ gem install capistrano-blaze
|
27
|
-
```
|
28
|
-
|
29
|
-
## Usage
|
30
|
-
|
31
17
|
Add to your `config/deploy.rb`:
|
32
18
|
|
33
19
|
``` ruby
|
data/capistrano-blaze.gemspec
CHANGED
data/lib/capistrano/blaze.rb
CHANGED
@@ -1,68 +1,44 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'json'
|
3
|
-
require 'ostruct'
|
4
3
|
require 'capistrano/blaze/version'
|
4
|
+
require 'capistrano/blaze/message'
|
5
|
+
require 'capistrano/blaze/configuration'
|
5
6
|
require 'capistrano/blaze/recipes' if defined?(Capistrano::Configuration)
|
6
7
|
|
7
8
|
module Capistrano
|
8
9
|
module Blaze
|
9
10
|
extend self
|
10
11
|
|
11
|
-
def configure
|
12
|
-
|
13
|
-
|
12
|
+
def configure
|
13
|
+
yield configuration
|
14
|
+
end
|
15
|
+
|
16
|
+
def configuration
|
17
|
+
@configuration ||= Configuration.new
|
14
18
|
end
|
15
19
|
|
16
20
|
def speak(message)
|
17
|
-
|
21
|
+
configuration.validate!
|
22
|
+
port = configuration.ssl ? 443 : 80
|
18
23
|
|
19
|
-
req = Net::HTTP::Post.new("/room/#{
|
20
|
-
req.basic_auth
|
24
|
+
req = Net::HTTP::Post.new("/room/#{configuration.room_id}/speak.json")
|
25
|
+
req.basic_auth configuration.token, 'X'
|
21
26
|
req.body = { :message => { :body => message } }.to_json
|
22
27
|
req.content_type = "application/json"
|
28
|
+
req["User-Agent"] = "Capistrano::Blaze"
|
23
29
|
|
24
|
-
res = Net::HTTP.start("#{
|
30
|
+
res = Net::HTTP.start("#{configuration.account}.campfirenow.com", port, :use_ssl => configuration.ssl) do |http|
|
25
31
|
http.request(req)
|
26
32
|
end
|
27
33
|
|
28
34
|
if res.is_a?(Net::HTTPSuccess)
|
29
|
-
|
35
|
+
warn "Campfire message sent!"
|
30
36
|
else
|
31
|
-
|
32
|
-
|
33
|
-
|
37
|
+
warn "Campfire communication failed!"
|
38
|
+
warn res.inspect
|
39
|
+
warn res.body.inspect
|
34
40
|
end
|
35
41
|
end
|
36
42
|
|
37
|
-
def failure(context, exception)
|
38
|
-
speak ":warning: #{user} failed to deploy #{stage(context)}#{context.application}, via `#{command}`: #{exception.to_s} (#{exception.class.inspect})"
|
39
|
-
end
|
40
|
-
|
41
|
-
def success(context)
|
42
|
-
speak "#{user} succesfully deployed #{stage(context)}#{context.application}, via `#{command}`"
|
43
|
-
end
|
44
|
-
|
45
|
-
def test(context)
|
46
|
-
speak ":heart: #{context.application}!"
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def stage(context)
|
52
|
-
if context.respond_to?(:stage)
|
53
|
-
"to the #{context.stage} stage of "
|
54
|
-
else
|
55
|
-
""
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def user
|
60
|
-
`whoami`.strip
|
61
|
-
end
|
62
|
-
|
63
|
-
def command
|
64
|
-
[ 'cap', *$* ] * ' '
|
65
|
-
end
|
66
|
-
|
67
43
|
end
|
68
44
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Capistrano
|
2
|
+
module Blaze
|
3
|
+
|
4
|
+
class Configuration
|
5
|
+
|
6
|
+
attr_accessor :account, :room_id, :token, :ssl
|
7
|
+
|
8
|
+
def []=(option, value)
|
9
|
+
send "#{option}=", value
|
10
|
+
end
|
11
|
+
|
12
|
+
def [](option)
|
13
|
+
send option
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate!
|
17
|
+
%w(account room_id token).each do |option|
|
18
|
+
if send(option).nil?
|
19
|
+
fail MissingOption.new(option)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class MissingOption < RuntimeError
|
25
|
+
|
26
|
+
def initialize(option)
|
27
|
+
@option = option
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
"Please specify the #{@option} option"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Capistrano
|
2
|
+
module Blaze
|
3
|
+
class Message
|
4
|
+
|
5
|
+
def self.start(context)
|
6
|
+
new(context).start
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.failure(context, exception)
|
10
|
+
new(context, exception).failure
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.success(context)
|
14
|
+
new(context).success
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.test(context)
|
18
|
+
new(context).test
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :context, :exception
|
22
|
+
|
23
|
+
def initialize(context, exception = nil)
|
24
|
+
@context, @exception = context, exception
|
25
|
+
end
|
26
|
+
|
27
|
+
def start
|
28
|
+
speak "#{user} is deploying #{what}, via `#{command}`"
|
29
|
+
end
|
30
|
+
|
31
|
+
def failure
|
32
|
+
speak ":warning: #{user} failed to deploy #{what}, via `#{command}`: #{exception_message}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def success
|
36
|
+
speak "#{user} succesfully deployed #{what}, via `#{command}`"
|
37
|
+
end
|
38
|
+
|
39
|
+
def test
|
40
|
+
speak ":heart: #{context.application}!"
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def exception_message
|
46
|
+
"#{exception.to_s} (#{exception.class.inspect})"
|
47
|
+
end
|
48
|
+
|
49
|
+
def speak(message)
|
50
|
+
Blaze.speak(message)
|
51
|
+
end
|
52
|
+
|
53
|
+
def what
|
54
|
+
stage + context.application
|
55
|
+
end
|
56
|
+
|
57
|
+
def stage
|
58
|
+
if context.respond_to?(:stage)
|
59
|
+
"to the #{context.stage} stage of "
|
60
|
+
else
|
61
|
+
""
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def user
|
66
|
+
`whoami`.strip
|
67
|
+
end
|
68
|
+
|
69
|
+
def command
|
70
|
+
[ 'cap', *ARGV ] * ' '
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -2,23 +2,28 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
2
2
|
|
3
3
|
at_exit do
|
4
4
|
if exception = $!
|
5
|
-
Capistrano::Blaze.failure(self, exception)
|
5
|
+
Capistrano::Blaze::Message.failure(self, exception)
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
9
|
namespace :campfire do
|
10
10
|
|
11
|
+
task :start do
|
12
|
+
Capistrano::Blaze::Message.start(self)
|
13
|
+
end
|
14
|
+
|
11
15
|
task :success do
|
12
|
-
Capistrano::Blaze.success(self)
|
16
|
+
Capistrano::Blaze::Message.success(self)
|
13
17
|
end
|
14
18
|
|
15
19
|
desc "Sends a test message to Campfire"
|
16
20
|
task :test_config do
|
17
|
-
Capistrano::Blaze.test(self)
|
21
|
+
Capistrano::Blaze::Message.test(self)
|
18
22
|
end
|
19
23
|
|
20
24
|
end
|
21
25
|
|
26
|
+
before "deploy", "campfire:start"
|
22
27
|
after "deploy:restart", "campfire:success"
|
23
28
|
|
24
29
|
end
|
data/spec/blaze_spec.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'capistrano/blaze'
|
2
|
+
require 'webmock'
|
3
|
+
|
4
|
+
describe Capistrano::Blaze do
|
5
|
+
include WebMock::API
|
6
|
+
|
7
|
+
around do |example|
|
8
|
+
$stderr = StringIO.new
|
9
|
+
example.run
|
10
|
+
$stderr = STDERR
|
11
|
+
end
|
12
|
+
|
13
|
+
it "can speak" do
|
14
|
+
token = "abc"
|
15
|
+
room_id = 1234
|
16
|
+
account = "abcd"
|
17
|
+
|
18
|
+
stub_request(:post, "http://#{token}:X@#{account}.campfirenow.com/room/#{room_id}/speak.json").
|
19
|
+
with(:body => "{\"message\":{\"body\":\"Ik ben een gem aan het maken\"}}",
|
20
|
+
:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Capistrano::Blaze'}).
|
21
|
+
to_return(:status => 200, :body => "", :headers => {})
|
22
|
+
|
23
|
+
subject.configure do |config|
|
24
|
+
config.account = account
|
25
|
+
config.room_id = room_id
|
26
|
+
config.token = token
|
27
|
+
config.ssl = false
|
28
|
+
end
|
29
|
+
|
30
|
+
subject.speak "Ik ben een gem aan het maken"
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'capistrano/blaze/configuration'
|
2
|
+
|
3
|
+
describe Capistrano::Blaze::Configuration do
|
4
|
+
|
5
|
+
REQUIRED = %W(account room_id token)
|
6
|
+
|
7
|
+
before do
|
8
|
+
REQUIRED.each do |option|
|
9
|
+
subject[option] = "foo"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
REQUIRED.each do |option|
|
14
|
+
it "requires #{option} to be set" do
|
15
|
+
subject[option] = nil
|
16
|
+
expect { subject.validate! }.to raise_error("Please specify the #{option} option")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'capistrano/blaze/message'
|
2
|
+
|
3
|
+
describe Capistrano::Blaze::Message do
|
4
|
+
|
5
|
+
subject { Capistrano::Blaze::Message }
|
6
|
+
let(:exception) { RuntimeError.new("woops") }
|
7
|
+
|
8
|
+
before do
|
9
|
+
subject.any_instance.stub(:user) { "your mom" }
|
10
|
+
end
|
11
|
+
|
12
|
+
it "sends a test message" do
|
13
|
+
should_speak(":heart: basecamp!")
|
14
|
+
context = stub(:application => "basecamp")
|
15
|
+
subject.test(context)
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with multistage extension" do
|
19
|
+
|
20
|
+
let(:context) { stub(:stage => "production", :application => "basecamp") }
|
21
|
+
|
22
|
+
it "displays a start message" do
|
23
|
+
should_speak("your mom is deploying to the production stage of basecamp, via `#{command}`")
|
24
|
+
subject.start(context)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "displays a failure message" do
|
28
|
+
should_speak(":warning: your mom failed to deploy to the production stage of basecamp, via `#{command}`: woops (RuntimeError)")
|
29
|
+
subject.failure(context, exception)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "displays success message" do
|
33
|
+
should_speak("your mom succesfully deployed to the production stage of basecamp, via `#{command}`")
|
34
|
+
subject.success(context)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
context "without multistage extension" do
|
40
|
+
|
41
|
+
let(:context) { stub(:application => "basecamp") }
|
42
|
+
|
43
|
+
it "displays a start message" do
|
44
|
+
should_speak("your mom is deploying basecamp, via `#{command}`")
|
45
|
+
subject.start(context)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "displays success message" do
|
49
|
+
should_speak("your mom succesfully deployed basecamp, via `#{command}`")
|
50
|
+
subject.success(context)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "displays failure message" do
|
54
|
+
should_speak(":warning: your mom failed to deploy basecamp, via `#{command}`: woops (RuntimeError)")
|
55
|
+
subject.failure(context, exception)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
def command
|
61
|
+
[ 'cap', *ARGV ] * ' '
|
62
|
+
end
|
63
|
+
|
64
|
+
def should_speak(message)
|
65
|
+
Capistrano::Blaze.should_receive(:speak).with(message)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-blaze
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2012-04-05 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
17
|
-
requirement: &
|
17
|
+
requirement: &70252880436580 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '2.9'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70252880436580
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: webmock
|
28
|
-
requirement: &
|
28
|
+
requirement: &70252880436080 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,7 +33,29 @@ dependencies:
|
|
33
33
|
version: 1.8.4
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70252880436080
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rake
|
39
|
+
requirement: &70252880435620 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 0.9.2
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70252880435620
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: json
|
50
|
+
requirement: &70252880435240 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *70252880435240
|
37
59
|
description: A simple campfire plugin for capistrano
|
38
60
|
email:
|
39
61
|
- iain@iain.nl
|
@@ -44,15 +66,20 @@ files:
|
|
44
66
|
- .gitignore
|
45
67
|
- .rspec
|
46
68
|
- .rvmrc
|
69
|
+
- .travis.yml
|
47
70
|
- Gemfile
|
48
71
|
- MIT-LICENSE
|
49
72
|
- README.md
|
50
73
|
- Rakefile
|
51
74
|
- capistrano-blaze.gemspec
|
52
75
|
- lib/capistrano/blaze.rb
|
76
|
+
- lib/capistrano/blaze/configuration.rb
|
77
|
+
- lib/capistrano/blaze/message.rb
|
53
78
|
- lib/capistrano/blaze/recipes.rb
|
54
79
|
- lib/capistrano/blaze/version.rb
|
55
|
-
- spec/
|
80
|
+
- spec/blaze_spec.rb
|
81
|
+
- spec/configuration_spec.rb
|
82
|
+
- spec/message_spec.rb
|
56
83
|
homepage: https://github.com/iain/capistrano-blaze
|
57
84
|
licenses: []
|
58
85
|
post_install_message:
|
@@ -78,4 +105,6 @@ signing_key:
|
|
78
105
|
specification_version: 3
|
79
106
|
summary: A simple campfire plugin for capistrano
|
80
107
|
test_files:
|
81
|
-
- spec/
|
108
|
+
- spec/blaze_spec.rb
|
109
|
+
- spec/configuration_spec.rb
|
110
|
+
- spec/message_spec.rb
|
data/spec/camp_spec.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'capistrano/blaze'
|
2
|
-
require 'webmock'
|
3
|
-
|
4
|
-
describe Capistrano::Blaze do
|
5
|
-
include WebMock::API
|
6
|
-
|
7
|
-
it "can speak" do
|
8
|
-
token = "abc"
|
9
|
-
room_id = 1234
|
10
|
-
account = "abcd"
|
11
|
-
|
12
|
-
stub_request(:post, "https://#{token}:X@#{account}.campfirenow.com/room/#{room_id}/speak.json").
|
13
|
-
with(:body => "{\"message\":{\"body\":\"Ik ben een gem aan het maken\"}}",
|
14
|
-
:headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}).
|
15
|
-
to_return(:status => 200, :body => "", :headers => {})
|
16
|
-
|
17
|
-
subject.configure do |config|
|
18
|
-
config.account = account
|
19
|
-
config.room_id = room_id
|
20
|
-
config.token = token
|
21
|
-
config.ssl = true
|
22
|
-
end
|
23
|
-
subject.speak "Ik ben een gem aan het maken"
|
24
|
-
end
|
25
|
-
|
26
|
-
before do
|
27
|
-
subject.stub(:user) { "iain" }
|
28
|
-
end
|
29
|
-
|
30
|
-
it "displays a failure message" do
|
31
|
-
subject.should_receive(:speak).with(":warning: iain failed to deploy to the production stage of basecamp, via `cap #{ARGV.join(' ')}`: woops (RuntimeError)")
|
32
|
-
context = stub(:stage => "production", :application => "basecamp")
|
33
|
-
exception = RuntimeError.new("woops")
|
34
|
-
subject.failure(context, exception)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "displays success message" do
|
38
|
-
subject.should_receive(:speak).with("iain succesfully deployed to the production stage of basecamp, via `cap #{ARGV.join(' ')}`")
|
39
|
-
context = stub(:stage => "production", :application => "basecamp")
|
40
|
-
subject.success(context)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "sends a test message" do
|
44
|
-
subject.should_receive(:speak).with(":heart: basecamp!")
|
45
|
-
context = stub(:application => "basecamp")
|
46
|
-
subject.test(context)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "displays success message without a stage" do
|
50
|
-
subject.should_receive(:speak).with("iain succesfully deployed basecamp, via `cap #{ARGV.join(' ')}`")
|
51
|
-
context = stub(:application => "basecamp")
|
52
|
-
subject.success(context)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "displays failure message without a stage" do
|
56
|
-
subject.should_receive(:speak).with(":warning: iain failed to deploy basecamp, via `cap #{ARGV.join(' ')}`: woops (RuntimeError)")
|
57
|
-
context = stub(:application => "basecamp")
|
58
|
-
exception = RuntimeError.new("woops")
|
59
|
-
subject.failure(context, exception)
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
end
|