capistrano-deploybot 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 05b4947014385caab09399ef8ddc9c99746d6ace
4
+ data.tar.gz: 2b2b36cf0cb891aac9f4cf38a94afbabfc4cbce9
5
+ SHA512:
6
+ metadata.gz: 788b096095f3bcf20efa822fbf41218748811e702e6ece93e92d7b9babafe5246751a0a5e61e24fab0c0c4e63652ead94be6e33351a12ffa478cc74cc4a860f8
7
+ data.tar.gz: 6a429f9b1b5e5a39be80dd0b5b563abc542868979316a162382c1d0d2b42eae1f2e6f4975390192e8fe3f4761b76ec6e57581673e474de12967e72afe70bd6d8
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'capistrano-deploybot'
3
+ s.version = '0.0.1'
4
+ s.homepage = 'https://github.com/kbackowski/capistrano-deploybot'
5
+ s.description = 'Notify slack channel with list of deployed commits'
6
+ s.date = '2017-03-07'
7
+ s.summary = 'Capistrano deploy integration for slack'
8
+ s.authors = ['Kamil Baćkowski']
9
+ s.email = 'kbackowski@gmail.com'
10
+ s.files = `git ls-files`.split($/)
11
+ s.license = 'MIT'
12
+
13
+ s.add_dependency 'capistrano', '>= 3.5.0'
14
+ end
@@ -0,0 +1,4 @@
1
+ require 'capistrano-deploybot/version'
2
+
3
+ module CapistranoDeploybot
4
+ end
@@ -0,0 +1,64 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ load File.expand_path("../tasks/slack.rake", __FILE__)
5
+
6
+ module CapistranoDeploybot
7
+ class Capistrano
8
+ DEFAULT_OPTIONS = {
9
+ username: :autodeploy,
10
+ environments: %w(staging)
11
+ }
12
+
13
+ def initialize(env)
14
+ @env = env
15
+ @opts = DEFAULT_OPTIONS.merge(fetch(:deploybot, {}))
16
+ end
17
+
18
+ def run
19
+ current_revision = fetch(:current_revision)
20
+ previous_revision = fetch(:previous_revision)
21
+ rails_env = fetch(:rails_env)
22
+
23
+ return if !@opts[:environments].include?(rails_env.to_s) || current_revision == previous_revision
24
+
25
+ payload = {
26
+ username: @opts[:username],
27
+ text: payload_text(current_revision, previous_revision, rails_env)
28
+ }
29
+
30
+ @opts[:webhooks].each do |webhook|
31
+ post_to_webhook(payload.merge(webhook: webhook))
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def payload_text(current_revision, previous_revision, rails_env)
38
+ "Deployed to #{rails_env}:\n" + `git shortlog #{previous_revision}..#{current_revision}`
39
+ end
40
+
41
+ def post_to_webhook(payload)
42
+ begin
43
+ response = post_to_slack_as_webhook(payload)
44
+ rescue => e
45
+ backend.warn("[deploybot] Error notifying Slack!")
46
+ backend.warn("[deploybot] Error: #{e.inspect}")
47
+ end
48
+
49
+ if response && response.code !~ /^2/
50
+ warn("[deploybot] Slack API Failure!")
51
+ warn("[deploybot] URI: #{response.uri}")
52
+ warn("[deploybot] Code: #{response.code}")
53
+ warn("[deploybot] Message: #{response.message}")
54
+ warn("[deploybot] Body: #{response.body}") if response.message != response.body && response.body !~ /<html/
55
+ end
56
+ end
57
+
58
+ def post_to_slack_as_webhook(payload = {})
59
+ params = { payload: payload.to_json }
60
+ uri = URI(payload[:webhook])
61
+ Net::HTTP.post_form(uri, params)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,11 @@
1
+ namespace :slack do
2
+ namespace :deploy do
3
+ desc 'Notify about updated deploy'
4
+ task :updated do
5
+ CapistranoDeploybot::Capistrano.new(self).run
6
+ end
7
+ end
8
+ end
9
+
10
+ # before 'deploy', 'slack:deploy:updated'
11
+ after 'deploy:finishing', 'slack:deploy:updated'
@@ -0,0 +1,3 @@
1
+ module CapistranoDeploybot
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-deploybot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kamil Baćkowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.5.0
27
+ description: Notify slack channel with list of deployed commits
28
+ email: kbackowski@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - capistrano-deploybot.gemspec
34
+ - lib/capistrano-deploybot.rb
35
+ - lib/capistrano-deploybot/capistrano.rb
36
+ - lib/capistrano-deploybot/tasks/slack.rake
37
+ - lib/capistrano-deploybot/version.rb
38
+ homepage: https://github.com/kbackowski/capistrano-deploybot
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.4.6
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Capistrano deploy integration for slack
62
+ test_files: []