graphite-notify 0.0.1 → 0.0.2

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/.gitignore CHANGED
@@ -1,2 +1,7 @@
1
1
  .git
2
2
  *.swp
3
+ .bundle
4
+ doc
5
+ .rbenv-version
6
+ .yardoc
7
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/README.md CHANGED
@@ -17,9 +17,6 @@ require "graphite-notify/capistrano"
17
17
 
18
18
  graphite: http://readthedocs.org/docs/graphite
19
19
 
20
- curl: http://curl.haxx.se/
21
-
22
-
23
20
  ## Tricks
24
21
 
25
22
  As it is a capistrano task you can call it directly:
@@ -27,4 +24,4 @@ As it is a capistrano task you can call it directly:
27
24
  ```
28
25
  cap graphite:notify_deploy
29
26
  ```
30
-
27
+
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'spec/rake/spectask'
4
+ require 'yard'
5
+
6
+ Spec::Rake::SpecTask.new(:spec) do |spec|
7
+ spec.spec_files = FileList['spec/*_spec.rb']
8
+ spec.spec_opts = ['--options', 'spec/spec.opts']
9
+ end
10
+
11
+ YARD::Rake::YardocTask.new do |t|
12
+ t.files = ['lib/**/*.rb']
13
+ end
@@ -20,4 +20,11 @@ Gem::Specification.new do |s|
20
20
  git_files = `git ls-files`.split("\n") rescue ''
21
21
  s.files = git_files
22
22
  s.require_paths = ["lib"]
23
+
24
+ s.add_dependency "capistrano"
25
+ s.add_development_dependency "rspec", "~> 1.3.2"
26
+ s.add_development_dependency "webmock"
27
+ s.add_development_dependency "capistrano-spec"
28
+ s.add_development_dependency "yard"
29
+ s.add_development_dependency "redcarpet"
23
30
  end
@@ -1,9 +1,49 @@
1
- # Just add "require 'graphite-notify/capistrano'" in your Capistrano deploy.rb, and
2
- # Bundler will be activated after each new deployment.
3
- require 'graphite-notify/deployment'
4
-
5
- Capistrano::Configuration.instance(:must_exist).load do
6
- after "deploy:restart", "graphite:notify_deploy"
7
- after "rollback:restart", "graphite:notify_rollback"
8
- GraphiteNotify::Deployment.define_task(self, :task, :except => { :no_release => true })
1
+ require 'net/http'
2
+ require 'capistrano'
3
+ module Capistrano
4
+ module Graphite
5
+ # Called when a Capistrano::Configuration.instance exists. Will define two tasks:
6
+ # * graphite:notify_deploy to notify graphite that a deploy occured with the app, the user, the stage in tags and message
7
+ # * graphite:notify_restart to notify graphite that a rollback occured with the app, the user, the stage in tags and message
8
+ # @param [Capistrano::Configuration] configuration the current capistrano configuration instance
9
+ def self.load_into(configuration)
10
+ configuration.load do
11
+
12
+ after "deploy:restart", "graphite:notify_deploy"
13
+ after "rollback:restart", "graphite:notify_rollback"
14
+
15
+ local_user = ENV['USER'] || ENV['USERNAME']
16
+
17
+ namespace :graphite do
18
+ desc 'notify graphite that a deployment occured'
19
+ task :notify_deploy, :on_error => :continue do
20
+ uri = URI(graphite_url)
21
+ Net::HTTP.start(uri.host, uri.port) do |http|
22
+ if respond_to?(:stage)
23
+ http.post(uri.path, "{\"what\": \"deploy #{application} in #{stage}\", \"tags\": \"#{application},#{stage},#{real_revision},deploy\", \"data\": \"#{local_user}\"}")
24
+ else
25
+ http.post(uri.path, "{\"what\": \"deploy #{application}\", \"tags\": \"#{application},#{real_revision},deploy\", \"data\": \"#{local_user}\"}")
26
+ end
27
+ end
28
+ end
29
+
30
+ desc 'notify graphite that a rollback occured'
31
+ task :notify_rollback, :on_error => :continue do
32
+ uri = URI(graphite_url)
33
+ Net::HTTP.start(uri.host, uri.port) do |http|
34
+ if respond_to?(:stage)
35
+ http.post(uri.path, "{\"what\": \"rollback #{application} in #{stage}\", \"tags\": \"#{application},#{stage},#{real_revision},rollback\", \"data\": \"#{local_user}\"}")
36
+ else
37
+ http.post(uri.path, "{\"what\": \"rollback #{application}\", \"tags\": \"#{application},#{real_revision},rollback\", \"data\": \"#{local_user}\"}")
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ if Capistrano::Configuration.instance
48
+ Capistrano::Graphite.load_into(Capistrano::Configuration.instance)
9
49
  end
@@ -1,3 +1,3 @@
1
1
  module GraphiteNotify
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1 @@
1
+ require 'graphite-notify/capistrano'
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ require './lib/graphite-notify/capistrano'
4
+
5
+ describe Capistrano::Graphite, "loaded into a configuration" do
6
+ before do
7
+ ENV['USER'] = 'testuser'
8
+ @configuration = Capistrano::Configuration.new
9
+ @configuration.set :graphite_url, 'http://localhost/'
10
+ @configuration.set :application, 'testapp'
11
+ @configuration.set :real_revision, 'randomsha'
12
+ Capistrano::Graphite.load_into(@configuration)
13
+ end
14
+
15
+ it 'should define callbacks' do
16
+ @configuration.should callback('graphite:notify_deploy').after('deploy:restart')
17
+ @configuration.should callback('graphite:notify_rollback').after('deploy:rollback')
18
+ end
19
+
20
+ context 'without capistrano-multistage support' do
21
+ it 'should notify graphite of a deploy' do
22
+ stub_request(:post, "http://localhost/").
23
+ with(:body => "{\"what\": \"deploy testapp\", \"tags\": \"testapp,randomsha,deploy\", \"data\": \"testuser\"}",
24
+ :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
25
+ to_return(:status => 200, :body => "", :headers => {})
26
+ @configuration.find_and_execute_task('graphite:notify_deploy')
27
+
28
+ end
29
+
30
+ it 'should notify graphite of a rollback' do
31
+ stub_request(:post, "http://localhost/").
32
+ with(:body => "{\"what\": \"rollback testapp\", \"tags\": \"testapp,randomsha,rollback\", \"data\": \"testuser\"}",
33
+ :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
34
+ to_return(:status => 200, :body => "", :headers => {})
35
+ @configuration.find_and_execute_task('graphite:notify_rollback')
36
+ end
37
+ end
38
+
39
+ context 'with capistrano-multistage support' do
40
+ before do
41
+ @configuration.set :stage, 'test'
42
+ end
43
+ it 'should notify graphite of a deploy' do
44
+ stub_request(:post, "http://localhost/").
45
+ with(:body => "{\"what\": \"deploy testapp in test\", \"tags\": \"testapp,test,randomsha,deploy\", \"data\": \"testuser\"}",
46
+ :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
47
+ to_return(:status => 200, :body => "", :headers => {})
48
+ @configuration.find_and_execute_task('graphite:notify_deploy')
49
+
50
+ end
51
+
52
+ it 'should notify graphite of a rollback' do
53
+ stub_request(:post, "http://localhost/").
54
+ with(:body => "{\"what\": \"rollback testapp in test\", \"tags\": \"testapp,test,randomsha,rollback\", \"data\": \"testuser\"}",
55
+ :headers => {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
56
+ to_return(:status => 200, :body => "", :headers => {})
57
+ @configuration.find_and_execute_task('graphite:notify_rollback')
58
+ end
59
+ end
60
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --backtrace
3
+ --format specdoc
@@ -0,0 +1,7 @@
1
+ require 'webmock/rspec'
2
+ require 'capistrano-spec'
3
+
4
+ Spec::Runner.configure do |config|
5
+ config.include Capistrano::Spec::Matchers
6
+ config.include Capistrano::Spec::Helpers
7
+ end
metadata CHANGED
@@ -1,73 +1,123 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: graphite-notify
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 1
9
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Vincent Hellot
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2012-06-11 00:00:00 +02:00
18
- default_executable:
19
- dependencies: []
20
-
12
+ date: 2012-10-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: &70344867339180 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70344867339180
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70344867338620 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.3.2
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70344867338620
36
+ - !ruby/object:Gem::Dependency
37
+ name: webmock
38
+ requirement: &70344867338160 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70344867338160
47
+ - !ruby/object:Gem::Dependency
48
+ name: capistrano-spec
49
+ requirement: &70344867337680 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70344867337680
58
+ - !ruby/object:Gem::Dependency
59
+ name: yard
60
+ requirement: &70344867337260 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70344867337260
69
+ - !ruby/object:Gem::Dependency
70
+ name: redcarpet
71
+ requirement: &70344867336820 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70344867336820
21
80
  description: notify graphite on deploy or rollback
22
- email:
81
+ email:
23
82
  - hellvinz@gmail.com
24
83
  executables: []
25
-
26
84
  extensions: []
27
-
28
85
  extra_rdoc_files: []
29
-
30
- files:
86
+ files:
31
87
  - .gitignore
88
+ - Gemfile
32
89
  - README.md
90
+ - Rakefile
33
91
  - graphite-notify.gemspec
34
92
  - lib/graphite-notify.rb
35
93
  - lib/graphite-notify/capistrano.rb
36
- - lib/graphite-notify/deployment.rb
37
94
  - lib/graphite-notify/version.rb
38
- has_rdoc: true
95
+ - spec/capistrano_spec.rb
96
+ - spec/spec.opts
97
+ - spec/spec_helper.rb
39
98
  homepage: https://github.com/hellvinz/graphite-notify
40
99
  licenses: []
41
-
42
100
  post_install_message:
43
101
  rdoc_options: []
44
-
45
- require_paths:
102
+ require_paths:
46
103
  - lib
47
- required_ruby_version: !ruby/object:Gem::Requirement
48
- requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- segments:
52
- - 1
53
- - 8
54
- - 7
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
55
109
  version: 1.8.7
56
- required_rubygems_version: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- segments:
61
- - 1
62
- - 3
63
- - 6
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
64
115
  version: 1.3.6
65
116
  requirements: []
66
-
67
117
  rubyforge_project:
68
- rubygems_version: 1.3.6
118
+ rubygems_version: 1.8.11
69
119
  signing_key:
70
120
  specification_version: 3
71
121
  summary: notify graphite on deploy or rollback
72
122
  test_files: []
73
-
123
+ has_rdoc:
@@ -1,39 +0,0 @@
1
- module GraphiteNotify
2
- class Deployment
3
- def self.define_task(context, task_method = :task, opts = {})
4
- if defined?(Capistrano) && context.is_a?(Capistrano::Configuration)
5
- context_name = "capistrano"
6
- role_default = "{:except => {:no_release => true}}"
7
- error_type = ::Capistrano::CommandError
8
- end
9
-
10
- graphite_url = context.fetch(:graphite_url, false)
11
- raise "Missing graphite_url" unless graphite_url
12
-
13
- local_user = ENV['USER'] || ENV['USERNAME']
14
-
15
- context.send :namespace, :graphite do
16
- send :desc, <<-DESC
17
- notify graphite that a deployment occured
18
- DESC
19
- send task_method, :notify_deploy, :on_error => :continue do
20
- if exists?(:stage)
21
- `curl -s -X POST #{graphite_url} -d '{"what": "deploy #{application} in #{stage}", "tags": "#{application},#{stage},#{real_revision},deploy", "data": "#{local_user}"}'`
22
- else
23
- `curl -s -X POST #{graphite_url} -d '{"what": "deploy #{application}", "tags": "#{application},#{real_revision},deploy", "data": "#{local_user}"}'`
24
- end
25
- end
26
- send :desc, <<-DESC
27
- notify graphite that a rollback occured
28
- DESC
29
- send task_method, :notify_rollback, :on_error => :continue do
30
- if exists?(:stage)
31
- `curl -s -X POST #{graphite_url} -d '{"what": "rollback #{application} in #{environment}", "tags": "#{application},#{stage},#{real_revision},rollback", "data": "#{local_user}"}'`
32
- else
33
- `curl -s -X POST #{graphite_url} -d '{"what": "rollback #{application}", "tags": "#{application},#{real_revision},rollback", "data": "#{local_user}"}'`
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end