capistrano-notify-hubot 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,42 @@
1
+ set :notify_hubot_log_level, "info"
2
+
3
+ def message_hubot
4
+ uri = URI.parse fetch(:hubot_uri)
5
+ http = Net::HTTP.new(uri.host, uri.port)
6
+ http.use_ssl = true
7
+ request = Net::HTTP::Post.new(uri.request_uri)
8
+ request.basic_auth fetch(:hubot_username), fetch(:hubot_password)
9
+ request.add_field "Content-Type", "application/json"
10
+ request.set_form_data({
11
+ "pretext" => "Deploy `#{fetch(:temp_id, "unset!")}` - by #{ENV['USER']}",
12
+ "title" => fetch(:title),
13
+ "text" => fetch(:message),
14
+ "color" => fetch(:color)
15
+ })
16
+ begin
17
+ response = http.request(request)
18
+ rescue Timeout::Error
19
+ error "Timed out"
20
+ rescue Errno::EHOSTUNREACH
21
+ error "Host unreachable"
22
+ rescue Errno::ECONNREFUSED
23
+ error "Connection refused"
24
+ rescue Net::SSH::AuthenticationFailed
25
+ error "Authentication failure"
26
+ rescue => err
27
+ error err
28
+ end
29
+ case response
30
+ when Net::HTTPSuccess then
31
+ info "Successfully notified Hubot"
32
+ when Net::HTTPBadGateway then
33
+ error "Bad Gateway, (is Hubot running?)"
34
+ when Net::HTTPNotFound then
35
+ error "Not Found, (wrong URI?)"
36
+ when Net::HTTPUnauthorized
37
+ error "Authentication failure"
38
+ else
39
+ error "Not able to message Hubot for some reason; continuing the deployment."
40
+ end
41
+ debug "Response is #{response.inspect}"
42
+ end
@@ -0,0 +1,52 @@
1
+ namespace :notify_hubot do
2
+ namespace :deploy do
3
+
4
+ task :set_log_level do
5
+ on roles(:notify_hubot) do |host|
6
+ log_level = SSHKit.config.output_verbosity
7
+ log_level = "info" if log_level.nil?
8
+ set :temp_log_level, log_level
9
+ SSHKit.config.output_verbosity = fetch(:notify_hubot_log_level)
10
+ end
11
+ end
12
+
13
+ task :unset_log_level do
14
+ on roles(:notify_hubot) do |host|
15
+ SSHKit.config.output_verbosity = fetch(:temp_log_level)
16
+ end
17
+ end
18
+
19
+ task :started => :set_log_level do
20
+ on roles(:notify_hubot) do |host|
21
+ set :temp_id, Digest::SHA1.hexdigest(Time.now.to_f.to_s)[8..16]
22
+ set :title, "Begin Deploy"
23
+ set :message, "Application: `#{fetch(:application)}`\nHost: #{host}"
24
+ set :color, "0000CC"
25
+ message_hubot
26
+ end
27
+ end
28
+ after :started, :unset_log_level
29
+
30
+ task :updated => :set_log_level do
31
+ on roles(:notify_hubot) do |host|
32
+ set :title, "Code Updated, finishing up"
33
+ set :message, "Application: `#{fetch(:application)}`\nHost: #{host}"
34
+ set :color, "9900CC"
35
+ message_hubot
36
+ end
37
+ end
38
+ after :updated, :unset_log_level
39
+
40
+ task :finished => :set_log_level do
41
+ on roles(:notify_hubot) do |host|
42
+ set :title, "Successful Deploy"
43
+ set :message, "Application: `#{fetch(:application)}`\nHost: #{host}"
44
+ set :color, "good"
45
+ message_hubot
46
+ end
47
+ end
48
+ after :finished, :unset_log_level
49
+
50
+
51
+ end
52
+ end
@@ -0,0 +1,23 @@
1
+ namespace :notify_hubot do
2
+ namespace :check do
3
+
4
+ desc 'Ensure all notify_hubot specific settings are set, and warn and exit if not.'
5
+ before 'deploy:started', :settings do
6
+ {
7
+ (File.dirname(__FILE__) + "/examples/config/deploy.rb") => 'config/deploy.rb'
8
+ }.each do |abs, rel|
9
+ Rake::Task['deployinator:settings'].invoke(abs, rel)
10
+ Rake::Task['deployinator:settings'].reenable
11
+ end
12
+ end
13
+
14
+ namespace :settings do
15
+ desc 'Print example notify_hubot specific settings for comparison.'
16
+ task :print do
17
+ set :print_all, true
18
+ Rake::Task['notify_hubot:check:settings'].invoke
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,4 @@
1
+ # Load DSL and Setup Up Stages
2
+ require 'capistrano/setup'
3
+
4
+ require 'capistrano-notify-hubot'
@@ -0,0 +1,14 @@
1
+ # config valid only for Capistrano 3.2.1
2
+ lock '3.2.1'
3
+
4
+ ##### capistrano-notify-hubot
5
+ ### ------------------------------------------------------------------
6
+ set :deployment_username, ENV['USER']
7
+ before 'deploy:started', 'notify_hubot:deploy:started'
8
+ after 'deploy:updated', 'notify_hubot:deploy:updated'
9
+ after 'deploy:finished', 'notify_hubot:deploy:finished'
10
+ set :hubot_room, "hackery"
11
+ set :hubot_uri, "https://127.0.0.1:9001/hubot/message/#{fetch(:hubot_room)}"
12
+ set :hubot_username, "my-user" # hubot basic auth
13
+ set :hubot_password, "my-pass" # hubot basic auth
14
+ ### ------------------------------------------------------------------
@@ -0,0 +1,7 @@
1
+ require 'capistrano/setup'
2
+ require 'digest'
3
+ require 'net/http'
4
+
5
+ load 'capistrano-notify-hubot/capistrano-notify-hubot.rb'
6
+ load 'capistrano-notify-hubot/check.rb'
7
+ load 'capistrano-notify-hubot/built-in.rb'
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-notify-hubot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - david amick
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-08-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: deployinator
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.1.3
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.1.3
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 10.3.2
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 10.3.2
62
+ - !ruby/object:Gem::Dependency
63
+ name: sshkit
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.5.1
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.5.1
78
+ description: Send Notifications to Hubot about Capistrano start, finish, etc.
79
+ email: davidamick@ctisolutionsinc.com
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files: []
83
+ files:
84
+ - lib/capistrano-notify-hubot.rb
85
+ - lib/capistrano-notify-hubot/capistrano-notify-hubot.rb
86
+ - lib/capistrano-notify-hubot/check.rb
87
+ - lib/capistrano-notify-hubot/built-in.rb
88
+ - lib/capistrano-notify-hubot/examples/Capfile
89
+ - lib/capistrano-notify-hubot/examples/config/deploy.rb
90
+ homepage: https://github.com/snarlysodboxer/capistrano-notify-hubot
91
+ licenses:
92
+ - GNU
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: 1.9.3
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements:
110
+ - A Hubot instance
111
+ rubyforge_project:
112
+ rubygems_version: 1.8.23.2
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: Notify Hubot during Capistrano Deployments
116
+ test_files: []
117
+ has_rdoc: