lita-capistrano 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1be7f607b6e7ad5ebdbe44ec9ee12c9d8bc625bb
4
+ data.tar.gz: fd1606aec7d6587a7262dd632b35b005ff3747c4
5
+ SHA512:
6
+ metadata.gz: 611b9e2e08efa083bc20417143af6c8f9b1cd5746ee3632f14a259a13cc7f01b350a046a751fa9c689e34a5fc436c8f58a00621b1d4097e2bdc7ee358f32f928
7
+ data.tar.gz: 8d8f3b0b1ebd09c8132adf68781cc88a98ea2b54030058733afa1b64cacc5df5307fe9308f7d98620fc76f68d39ca1d15d501489d09a617b46017617799e11c7
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # lita-capistrano
2
+
3
+ TODO: Add a description of the plugin.
4
+
5
+ ## Installation
6
+
7
+ Add lita-capistrano to your Lita instance's Gemfile:
8
+
9
+ ``` ruby
10
+ gem "lita-capistrano"
11
+ ```
12
+
13
+ ## Configuration
14
+
15
+ TODO: Describe any configuration attributes the plugin exposes.
16
+
17
+ ## Usage
18
+
19
+ TODO: Describe the plugin's features and how to use them.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,180 @@
1
+ require 'net/ssh'
2
+
3
+ module Lita
4
+ module Handlers
5
+ class Capistrano < Handler
6
+
7
+ config :server, type: String, required: true
8
+ config :server_user, type: String, required: true
9
+ config :server_password, type: String, required: true
10
+ config :deploy_tree, type: Hash, required: true
11
+
12
+ on :deploy_checked, :deploy_exec
13
+ on :deploy_aborted, :deploy_abort
14
+
15
+ route(
16
+ /^deploy\s+list/,
17
+ :deploy_list, command: false,
18
+ restrict_to: [:admins, :deploy],
19
+ help: { "deploy list [APP] " => "List available apps for deploy"}
20
+ )
21
+
22
+ route(
23
+ /^deploy\s+(.+)\s+(.+)\s+(.+)\s+(.+)/,
24
+ :deploy_request, command: true,
25
+ restrict_to: [:admins, :deploy],
26
+ help: { "deploy APP AREA ENV TAG " => "Executa deploy"}
27
+ )
28
+
29
+ # Not in use
30
+ def teste
31
+ p "teste"
32
+ config.deploy_tree.each do |key, value|
33
+ route(
34
+ /^deploy\s+#{key.to_s}\s+(.+)\s+(.+)\s+(.+)/,
35
+ :deploy_request, command: true,
36
+ restrict_to: [:admins, value[:deploy_group]],
37
+ help: { "deploy #{key.to_s} AREA ENV TAG " => "Executa deploy"}
38
+ )
39
+ end
40
+ end
41
+
42
+ def deploy_list_apps(response)
43
+ response.reply_privately('Available apps:')
44
+ response.reply_privately(config.deploy_tree.keys)
45
+ end
46
+
47
+ def deploy_list(response)
48
+ requested_app = response.args[1]
49
+ if requested_app.nil?
50
+ apps = config.deploy_tree.keys.join("\n")
51
+ response.reply_privately("Available apps:\n#{apps}")
52
+ else
53
+ app_tree = get_app_tree(config.deploy_tree[requested_app.to_sym])
54
+ response.reply_privately("Available tree for #{requested_app}: \n #{app_tree}")
55
+ end
56
+ end
57
+
58
+ def deploy_request(response)
59
+ app = response.matches[0][0]
60
+ area = response.matches[0][1]
61
+ env = response.matches[0][2]
62
+ tag = response.matches[0][3]
63
+
64
+ unless area_exists?(area)
65
+ return response.reply("A área informada é inválida.")
66
+ end
67
+ unless env_exists?(area, env)
68
+ return response.reply("O ambiente informado é inválido.")
69
+ end
70
+
71
+ # Pre deploy check
72
+ deploy_in_progress?(app, area, env, tag, response)
73
+ end
74
+
75
+
76
+ def area_exists?(area)
77
+ config.deploy_tree[:commerce].include?(area.to_sym)
78
+ end
79
+
80
+ def env_exists?(area, env)
81
+ config.deploy_tree[:commerce][area.to_sym][:envs].include?(env)
82
+ end
83
+
84
+ def get_app_tree(config_tree)
85
+ app_tree = {}
86
+ config_tree.each do |key, value|
87
+ app_tree.store(key.to_s, value[:envs].map { |e| ">#{e}\n" }.join)
88
+ end
89
+ app_tree.flatten.map { |e| "#{e}\n" }.join
90
+ end
91
+
92
+ # If a deploy is in progress the deploy_tracker handler will return a
93
+ # reponse to chat and will interrupt further using the interrupt_deploy
94
+ # method
95
+ def deploy_in_progress?(app, area, env, tag, response)
96
+ robot.trigger(:deploy_in_progress?, app: app, area: area, env: env, tag: tag, response: response)
97
+ end
98
+
99
+ def deploy_abort(payload)
100
+ return payload[:response].reply(payload[:msg])
101
+ end
102
+
103
+ def deploy_exec(payload)
104
+ app = payload[:app]
105
+ area = payload[:area]
106
+ env = payload[:env]
107
+ tag = payload[:tag]
108
+ response = payload[:response]
109
+ dir = config.deploy_tree[app.to_sym][area.to_sym][:dir]
110
+
111
+ # Deploy start
112
+ response.reply("#{response.user.mention_name}: Deploy da tag #{tag} iniciado no ambiente #{env}.")
113
+ start_time = Time.now
114
+ robot.trigger(:deploy_started,
115
+ app: app,
116
+ area: area,
117
+ env: env,
118
+ tag: tag,
119
+ responsible: response.user.mention_name,
120
+ start_time: start_time)
121
+
122
+ # Deploy execution
123
+ output = deploy(dir, env, tag)
124
+ # After deploy stopped
125
+ finish_time =Time.now
126
+
127
+ # The deploy:restart could be in two positions depending on the
128
+ # capistrano config
129
+ if (output.lines.last.include? "deploy:restart") || (output.lines.last(5)[0].include? "deploy:restart")
130
+ robot.trigger(:deploy_finished,
131
+ app: app,
132
+ area: area,
133
+ env: env,
134
+ tag: tag,
135
+ responsible: response.user.mention_name,
136
+ start_time: start_time,
137
+ finish_time: finish_time,
138
+ status: 'success')
139
+ return response.reply("#{response.user.mention_name}: Deploy da tag #{tag} no ambiente #{env} realizado com sucesso!")
140
+ elsif output.lines.last.include? "status code 32768"
141
+ robot.trigger(:deploy_finished,
142
+ app: app,
143
+ area: area,
144
+ env: env,
145
+ tag: tag,
146
+ responsible: response.user.mention_name,
147
+ start_time: start_time,
148
+ finish_time: finish_time,
149
+ status: 'invalid tag')
150
+ return response.reply("#{response.user.mention_name}: A tag #{tag} informada não existe. Deploy não realizado.")
151
+ else
152
+ robot.trigger(:deploy_finished,
153
+ app: app,
154
+ area: area,
155
+ env: env,
156
+ tag: tag,
157
+ responsible: response.user.mention_name,
158
+ start_time: start_time,
159
+ finish_time: finish_time,
160
+ status: 'error')
161
+ return response.reply("#{response.user.mention_name}: Ocorreu um erro na execução do deploy da tag #{tag} no ambiente #{env}.")
162
+ end
163
+ end
164
+
165
+ def deploy(dir, env, tag)
166
+ output = ssh_exec("cd #{dir}; cap #{env} deploy tag=#{tag}")
167
+ end
168
+
169
+ def ssh_exec(cmd)
170
+ #TODO tornar acesso ao servidor dinamico entro prod e test
171
+ Net::SSH.start(config.server, config.server_user, :password => config.server_password) do |ssh|
172
+ @output = ssh.exec!(cmd)
173
+ end
174
+ @output
175
+ end
176
+
177
+ Lita.register_handler(self)
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,12 @@
1
+ require "lita"
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join("..", "..", "locales", "*.yml"), __FILE__
5
+ )]
6
+
7
+ require "lita/handlers/capistrano"
8
+
9
+ Lita::Handlers::Capistrano.template_root File.expand_path(
10
+ File.join("..", "..", "templates"),
11
+ __FILE__
12
+ )
@@ -0,0 +1,23 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "lita-capistrano"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["Alexandre Gomes"]
5
+ spec.email = ["alejdg@outlook.com.br"]
6
+ spec.summary = "A Lita handler to integrate with Capistrano.rb"
7
+ spec.homepage = "https://github.com/alejdg/lita-capistrano.git"
8
+ spec.metadata = { "lita_plugin_type" => "handler" }
9
+
10
+ spec.files = `git ls-files`.split($/)
11
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
12
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
13
+ spec.require_paths = ["lib"]
14
+
15
+ spec.add_runtime_dependency "lita", " ~> 4.6"
16
+ spec.add_runtime_dependency 'net-ssh'
17
+
18
+ spec.add_development_dependency "bundler", "~> 1.3"
19
+ spec.add_development_dependency "pry-byebug"
20
+ spec.add_development_dependency "rake"
21
+ spec.add_development_dependency "rack-test"
22
+ spec.add_development_dependency "rspec", "~> 3.0"
23
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,4 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ capistrano:
@@ -0,0 +1,5 @@
1
+ require "spec_helper"
2
+
3
+ describe Lita::Handlers::Capistrano, lita_handler: true do
4
+ it { is_expected.to route ("cap commerce list").to(:cap_list)}
5
+ end
@@ -0,0 +1,6 @@
1
+ require "lita-capistrano"
2
+ require "lita/rspec"
3
+
4
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
5
+ # was generated with Lita 4, the compatibility mode should be left disabled.
6
+ Lita.version_3_compatibility_mode = false
File without changes
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-capistrano
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexandre Gomes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: net-ssh
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ description:
112
+ email:
113
+ - alejdg@outlook.com.br
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - README.md
121
+ - Rakefile
122
+ - lib/lita-capistrano.rb
123
+ - lib/lita/handlers/capistrano.rb
124
+ - lita-capistrano.gemspec
125
+ - locales/en.yml
126
+ - spec/lita/handlers/capistrano_spec.rb
127
+ - spec/spec_helper.rb
128
+ - templates/.gitkeep
129
+ homepage: https://github.com/alejdg/lita-capistrano.git
130
+ licenses: []
131
+ metadata:
132
+ lita_plugin_type: handler
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.4.8
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: A Lita handler to integrate with Capistrano.rb
153
+ test_files:
154
+ - spec/lita/handlers/capistrano_spec.rb
155
+ - spec/spec_helper.rb