capistrano-deploy_hooks 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: eef0dba2366fd955fe2910134db796ef5ef10a03
4
+ data.tar.gz: c8efd9a22fcfa713509f5e7349691298896cdf95
5
+ SHA512:
6
+ metadata.gz: f3f2ae079d008c472b72fb9b3bb4c3cc73a6db806c2b0d53fb60d053a933dc80769b509a5238aafe6d15c3edd4017dcce260b74fa4e0c9f65d85ab851364a47b
7
+ data.tar.gz: 400bf8e27d8406cb7d75de8deebf3461e5b8f24dc175f872d584df0911cd0dc6047b66ead83651a107855e42f466bc06d8cddf4f990c0ce160c6380727b4c58f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-deploy_hooks.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Capistrano::DeployHooks
2
+
3
+ This is a small framework for generating webhooks for the various stages of a Capistrano deploy. It comes with some messengers prepacked, for example Mattermost.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'capistrano-deploy_hooks'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ In your Capfile:
20
+
21
+ ```ruby
22
+ require 'capistrano/deploy_hooks'
23
+ ```
24
+
25
+ In your Capistrano config:
26
+
27
+ ```ruby
28
+ # or another messenger from somewhere
29
+ require 'capistrano/deploy_hooks/messengers/mattermost'
30
+
31
+ if ENV['WEBHOOK_URI']
32
+ set :deploy_hooks, {
33
+ messenger: Capistrano::DeployHooks::Messengers::Mattermost,
34
+ webhook_uri: ENV['WEBHOOK_URI'],
35
+ }
36
+ end
37
+ ```
38
+
39
+ ## Messengers
40
+
41
+ Messengers should respond to `payload_for(action)`, and return Hash 'payloads', with the following optional actions: updating, reverting, updated, reverted, failed. They should also respond to `webhook_for(action)` and return a URI to post the webhook to. See `capistrano/deploy_hooks/messengers/mattermost.rb` as an example of this. Messengers are initialized with the hash config passed to capistrano's `set :deploy_hooks` call.
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
46
+
47
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/capistrano-mattermost.
52
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "capistrano/deploy_hooks"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/deploy_hooks/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capistrano-deploy_hooks"
8
+ spec.version = Capistrano::DeployHooks::VERSION
9
+ spec.authors = ["Mike Campbell"]
10
+ spec.email = ["mike.campbell@meritec.co.uk"]
11
+
12
+ spec.summary = %q{Configurable deploy hooks for Capistrano}
13
+ spec.homepage = "https://www.github.com/meritec/capistrano-deploy_hooks"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "capistrano", ">= 3.3.0"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest", "~> 5.0"
25
+ end
@@ -0,0 +1,29 @@
1
+ require 'json'
2
+
3
+ module Capistrano
4
+ module DeployHooks
5
+ class Main
6
+ extend Forwardable
7
+ def_delegators :@cap, :fetch, :run_locally
8
+
9
+ def initialize(cap)
10
+ @env = cap
11
+ opts = fetch(:deploy_hooks, {}).dup
12
+
13
+ @messenger = opts.delete(:messenger).new(cap, opts)
14
+ end
15
+
16
+ def run(action)
17
+ _self = self
18
+ run_locally{ _self.process(action) }
19
+ end
20
+
21
+ def process(action)
22
+ uri = URI(@messenger.webhook_for(action))
23
+ @messenger.payloads_for(action).each do |payload|
24
+ Net::HTTP.post_form(uri, { 'payload' => payload.to_json })
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,70 @@
1
+ module Capistrano
2
+ module DeployHooks
3
+ module Messengers
4
+ class Mattermost
5
+ extend Forwardable
6
+ def_delegators :@cap, :fetch
7
+
8
+ attr_reader :opts
9
+
10
+ def initialize(cap, opts)
11
+ @cap = cap
12
+ @opts = opts
13
+ end
14
+
15
+ def payloads_for(action)
16
+ method = "payload_for_#{action}"
17
+ return if !respond_to?(method)
18
+
19
+ pl = (opts[:payload] || {}).merge(username: "Capistrano").merge(send(method))
20
+
21
+ channels = Array(opts[:channels])
22
+
23
+ payloads = channels.map{ |c| pl.merge(channel: c) }
24
+ payloads = [pl] if payloads.empty?
25
+ payloads
26
+ end
27
+
28
+ def payload_for_updating
29
+ { text: "#{deployer} has started deploying branch #{branch} of #{application} to #{stage}" }
30
+ end
31
+
32
+ def payload_for_reverting
33
+ { text: "#{deployer} has started rolling back branch #{branch} of #{application} to #{stage}" }
34
+ end
35
+
36
+ def payload_for_updated
37
+ { text: "#{deployer} has finished deploying branch #{branch} of #{application} to #{stage}" }
38
+ end
39
+
40
+ def payload_for_reverted
41
+ { text: "#{deployer} has finished rolling back branch of #{application} to #{stage}" }
42
+ end
43
+
44
+ def payload_for_failed
45
+ { text: "#{deployer} has failed to #{deploying? ? 'deploy' : 'rollback'} branch #{branch} of #{application} to #{stage}" }
46
+ end
47
+
48
+ def webhook_for(_)
49
+ opts[:webhook_uri]
50
+ end
51
+
52
+ def deployer
53
+ ENV["USER"] || ENV["USERNAME"]
54
+ end
55
+
56
+ def branch
57
+ fetch(:branch)
58
+ end
59
+
60
+ def application
61
+ fetch(:application)
62
+ end
63
+
64
+ def stage
65
+ fetch(:stage, '')
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,2 @@
1
+ require 'capistrano/deploy_hooks/main'
2
+ load File.expand_path("../../tasks/deploy_hooks.rake", __FILE__)
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module DeployHooks
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "capistrano/deploy_hooks/version"
2
+ require "capistrano/deploy_hooks/tasks"
@@ -0,0 +1,33 @@
1
+ namespace :deploy_hooks do
2
+ namespace :deploy do
3
+ task :updating do
4
+ Capistrano::DeployHooks::Main.new(self).run(:updating)
5
+ end
6
+
7
+ task :reverting do
8
+ Capistrano::DeployHooks::Main.new(self).run(:reverting)
9
+ end
10
+
11
+ task :updated do
12
+ Capistrano::DeployHooks::Main.new(self).run(:updated)
13
+ end
14
+
15
+ task :reverted do
16
+ Capistrano::DeployHooks::Main.new(self).run(:reverted)
17
+ end
18
+
19
+ task :failed do
20
+ Capistrano::DeployHooks::Main.new(self).run(:failed)
21
+ end
22
+
23
+ task :test => %i[updating updated reverting reverted failed] do
24
+ # all tasks run as dependencies
25
+ end
26
+ end
27
+ end
28
+
29
+ before 'deploy:updating', 'deploy_hooks:deploy:updating'
30
+ before 'deploy:reverting', 'deploy_hooks:deploy:reverting'
31
+ after 'deploy:finishing', 'deploy_hooks:deploy:updated'
32
+ after 'deploy:finishing_rollback', 'deploy_hooks:deploy:reverted'
33
+ after 'deploy:failed', 'deploy_hooks:deploy:failed'
File without changes
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-deploy_hooks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Campbell
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-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.3.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.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description:
70
+ email:
71
+ - mike.campbell@meritec.co.uk
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - README.md
80
+ - Rakefile
81
+ - bin/console
82
+ - bin/setup
83
+ - capistrano-deploy_hooks.gemspec
84
+ - lib/capistrano-deploy_hooks.rb
85
+ - lib/capistrano/deploy_hooks.rb
86
+ - lib/capistrano/deploy_hooks/main.rb
87
+ - lib/capistrano/deploy_hooks/messengers/mattermost.rb
88
+ - lib/capistrano/deploy_hooks/tasks.rb
89
+ - lib/capistrano/deploy_hooks/version.rb
90
+ - lib/capistrano/tasks/deploy_hooks.rake
91
+ homepage: https://www.github.com/meritec/capistrano-deploy_hooks
92
+ licenses: []
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.6
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Configurable deploy hooks for Capistrano
114
+ test_files: []