capistrano-hook 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rubocop.yml +7 -3
- data/.rubocop_todo.yml +7 -0
- data/.travis.yml +6 -13
- data/Capfile +4 -0
- data/Gemfile +2 -0
- data/README.md +55 -22
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/bin/rubocop-auto-correct +2 -1
- data/bin/setup +4 -0
- data/capistrano-hook.gemspec +13 -8
- data/config/deploy.rb +9 -2
- data/config/deploy/{staging.rb → all.rb} +9 -19
- data/config/deploy/discord.rb +44 -0
- data/config/deploy/{production.rb → slack.rb} +8 -4
- data/lib/capistrano/hook.rb +3 -1
- data/lib/capistrano/hook/load.rb +2 -0
- data/lib/capistrano/hook/version.rb +3 -1
- data/lib/capistrano/hook/web.rb +33 -11
- data/lib/capistrano/tasks/webhook.rake +76 -47
- metadata +27 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 99bc36d1c0f7464499165ef8406b0b28a13c58410c7c9f7aabd566c17550339a
|
4
|
+
data.tar.gz: a3f5b8ab947dada284400bbe0e09596ca3cb3b07649c8a5bceef9fad2845b4bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f242724c1176a34f71b0000456d4d813d62c63f7f67799bc02b4650f2e60d9dd4a358f0c376a585ae69f252b67372ed1a55b57c667c7d971b841ba698dac7021
|
7
|
+
data.tar.gz: 8addfb5040dbd8ecdefea9c25eb06fbf28b0d77172a0f02321f893633789c68ca0abb456d143822eb8948361d55ade6dbde990fd4c14d1c5bbfc27c25a3218ca
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2020-05-26 17:01:17 +0000 using RuboCop version 0.75.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
data/.travis.yml
CHANGED
@@ -1,18 +1,11 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
-
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
-
-
|
8
|
-
|
9
|
-
- rbx-2
|
10
|
-
matrix:
|
11
|
-
allow_failures:
|
12
|
-
- rvm: ruby-head
|
13
|
-
- rvm: jruby-19mode
|
14
|
-
- rvm: rbx-2
|
15
|
-
before_install: gem install bundler -v 1.10.5
|
3
|
+
- 2.3.8
|
4
|
+
- 2.4.10
|
5
|
+
- 2.5.8
|
6
|
+
- 2.6.6
|
7
|
+
- 2.7.1
|
8
|
+
before_install: gem install bundler -v 2.1.4
|
16
9
|
script:
|
17
10
|
- bundle exec rake
|
18
11
|
- bundle exec rubocop
|
data/Capfile
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,18 @@
|
|
1
1
|
# Capistrano::Hook
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/capistrano-hook.svg)](http://badge.fury.io/rb/capistrano-hook)
|
4
|
-
[![Build Status](https://travis-ci.org/yulii/capistrano-hook.svg)](https://travis-ci.org/yulii/capistrano-hook)
|
5
|
-
[![
|
4
|
+
[![Build Status](https://travis-ci.org/yulii/capistrano-hook.svg?branch=master)](https://travis-ci.org/yulii/capistrano-hook)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/yulii/capistrano-hook/badges/gpa.svg)](https://codeclimate.com/github/yulii/capistrano-hook)
|
6
6
|
|
7
7
|
Notification hooks include start, finish and fail of deployments.
|
8
8
|
|
9
|
+
## Features
|
10
|
+
|
11
|
+
### Webhoook
|
12
|
+
|
13
|
+
Notify Capistrano deployments via webhook API.
|
14
|
+
Just set the webhook URL and message.
|
15
|
+
|
9
16
|
## Installation
|
10
17
|
|
11
18
|
Add this line to your application's Gemfile:
|
@@ -22,49 +29,75 @@ Add this line to your Capfile:
|
|
22
29
|
require 'capistrano/hook'
|
23
30
|
```
|
24
31
|
|
25
|
-
|
32
|
+
Notification will not be run with no settings. You can setting the variables shown below.
|
26
33
|
|
27
34
|
```ruby
|
28
|
-
set :webhook_url, '
|
29
|
-
set :webhook_starting_payload,
|
30
|
-
set :webhook_finished_payload,
|
31
|
-
set :webhook_failed_payload,
|
35
|
+
set :webhook_url, 'https://yulii.github.io/services'
|
36
|
+
set :webhook_starting_payload, { text: 'Now, deploying...' }
|
37
|
+
set :webhook_finished_payload, { text: 'Deployment has been completed!' }
|
38
|
+
set :webhook_failed_payload, { text: 'Oops! something went wrong.' }
|
39
|
+
set :webhook_reverting_payload, { text: 'Reverting...' }
|
40
|
+
set :webhook_rollbacked_payload, { text: 'Rollback has been completed!' }
|
41
|
+
```
|
42
|
+
|
43
|
+
See [capistrano-hook/config](https://github.com/yulii/capistrano-hook/tree/master/config)
|
44
|
+
|
45
|
+
## Testing
|
46
|
+
|
47
|
+
Test your setup by running:
|
48
|
+
|
32
49
|
```
|
50
|
+
# List the webhook configured variables
|
51
|
+
$ cap production webhook:config:list
|
52
|
+
|
53
|
+
# Post a starting message
|
54
|
+
$ cap production webhook:post:starting
|
33
55
|
|
34
|
-
|
56
|
+
# Post a finished message
|
57
|
+
$ cap production webhook:post:finished
|
35
58
|
|
36
|
-
|
59
|
+
# Post a failed message
|
60
|
+
$ cap production webhook:post:failed
|
61
|
+
|
62
|
+
# Post a reverting message
|
63
|
+
$ cap production webhook:post:reverting
|
64
|
+
|
65
|
+
# Post a rollbacked message
|
66
|
+
$ cap production webhook:post:rollbacked
|
67
|
+
```
|
68
|
+
|
69
|
+
If you want to see all capistrano hook commands, please run `cap -T`. :)
|
70
|
+
|
71
|
+
## Example
|
72
|
+
|
73
|
+
### Slack incoming webhook
|
74
|
+
|
75
|
+
Send notifications to Slack via incoming webhook.
|
76
|
+
|
77
|
+
[Slack API - Incoming Webhooks](https://api.slack.com/incoming-webhooks)
|
37
78
|
|
38
79
|
```ruby
|
39
|
-
set :webhook_url, '
|
80
|
+
set :webhook_url, '#{YOUR WEBHOOK URL}'
|
40
81
|
set :webhook_starting_payload, {
|
41
82
|
username: 'Capistrano',
|
42
|
-
icon_emoji: ':
|
83
|
+
icon_emoji: ':rocket:',
|
43
84
|
text: 'Now, deploying...'
|
44
85
|
}
|
45
86
|
set :webhook_finished_payload, {
|
46
87
|
username: 'Capistrano',
|
47
|
-
icon_emoji: ':
|
88
|
+
icon_emoji: ':rocket:',
|
48
89
|
text: 'Deployment has been completed!'
|
49
90
|
}
|
50
91
|
set :webhook_failed_payload, {
|
51
92
|
username: 'Capistrano',
|
52
|
-
icon_emoji: ':
|
93
|
+
icon_emoji: ':rotating_light:',
|
53
94
|
text: 'Oops! something went wrong.'
|
54
95
|
}
|
55
96
|
```
|
56
97
|
|
57
|
-
[Slack API - Incoming Webhooks](https://api.slack.com/incoming-webhooks)
|
58
|
-
|
59
|
-
## Development
|
60
|
-
|
61
|
-
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.
|
62
|
-
|
63
|
-
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).
|
64
|
-
|
65
98
|
## Contributing
|
66
99
|
|
67
|
-
|
100
|
+
Fork, fix, then send a pull request and attach test code.
|
68
101
|
|
69
102
|
|
70
103
|
## License
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/bin/rubocop-auto-correct
CHANGED
data/bin/setup
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
set -euo pipefail
|
3
3
|
IFS=$'\n\t'
|
4
4
|
|
5
|
+
VERSION=$(ruby -e "require './lib/capistrano/hook/version'; print Capistrano::Hook::VERSION")
|
6
|
+
|
5
7
|
bundle install
|
8
|
+
bundle exec rake build
|
9
|
+
gem install pkg/capistrano-hook-${VERSION}.gem
|
6
10
|
|
7
11
|
# Do any other automated setup that you need to do here
|
data/capistrano-hook.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'capistrano/hook/version'
|
5
6
|
|
@@ -9,22 +10,26 @@ Gem::Specification.new do |spec|
|
|
9
10
|
spec.authors = ['yulii']
|
10
11
|
spec.email = ['yone.info@gmail.com']
|
11
12
|
|
12
|
-
spec.summary = 'Simple
|
13
|
+
spec.summary = 'Simple webhooks for Capistrano deployments.'
|
13
14
|
spec.description = 'Notification hooks include start, finish and fail of deployments.'
|
14
15
|
spec.homepage = 'https://github.com/yulii/capistrano-hook'
|
15
16
|
spec.license = 'MIT'
|
16
17
|
|
17
|
-
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
18
23
|
spec.bindir = 'exe'
|
19
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
25
|
spec.require_paths = ['lib']
|
21
26
|
|
22
|
-
spec.add_dependency 'capistrano', '
|
27
|
+
spec.add_dependency 'capistrano', '>= 3.0'
|
23
28
|
|
24
|
-
spec.add_development_dependency 'bundler'
|
25
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'bundler'
|
26
30
|
spec.add_development_dependency 'minitest'
|
27
31
|
spec.add_development_dependency 'minitest-reporters'
|
28
|
-
spec.add_development_dependency '
|
32
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
29
33
|
spec.add_development_dependency 'rubocop'
|
34
|
+
spec.add_development_dependency 'webmock'
|
30
35
|
end
|
data/config/deploy.rb
CHANGED
@@ -1,17 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# config valid only for current version of Capistrano
|
2
|
-
lock '3.4.0'
|
4
|
+
# lock '3.4.0'
|
3
5
|
|
4
6
|
set :application, 'capistrano-hook'
|
5
7
|
set :repo_url, 'git@github.com:yulii/capistrano-hook.git'
|
6
8
|
set :branch, :master
|
7
9
|
|
8
10
|
set :deploy_to, '/tmp'
|
9
|
-
set :scm, :git
|
10
11
|
set :format, :pretty
|
11
12
|
set :log_level, :debug
|
12
13
|
|
13
14
|
set :keep_releases, 5
|
14
15
|
|
16
|
+
# API Mock URL
|
17
|
+
MOCK_URL = {
|
18
|
+
'200' => 'http://www.mocky.io/v2/55d33a90ec91e92b0e5e8e18',
|
19
|
+
'406' => 'http://www.mocky.io/v2/55d6557a54774eed102a494c'
|
20
|
+
}.freeze
|
21
|
+
|
15
22
|
namespace :deploy do
|
16
23
|
after :restart, :clear_cache do
|
17
24
|
on roles(:web), in: :groups, limit: 3, wait: 10 do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# server-based syntax
|
2
4
|
# ======================
|
3
5
|
# Defines a single server with a list of roles and multiple properties.
|
@@ -21,26 +23,14 @@
|
|
21
23
|
|
22
24
|
# Configuration
|
23
25
|
# =============
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
set :webhook_url, ENV.fetch('WEBHOOK_URL') { MOCK_URL[(ENV['STATUS_CODE'] || '200')] }
|
27
|
+
set :webhook_http_headers, 'Content-Type' => 'application/x-www-form-urlencoded'
|
28
|
+
set :webhook_starting_payload, params: '[production] Now, deploying...'
|
29
|
+
set :webhook_finished_payload, params: '[production] Deployment has been completed!'
|
30
|
+
set :webhook_failed_payload, params: '[production] Oops! something went wrong.'
|
31
|
+
set :webhook_reverting_payload, params: '[production] Reverting...'
|
32
|
+
set :webhook_rollbacked_payload, params: '[production] Rollback has been completed!'
|
29
33
|
|
30
|
-
# Custom SSH Options
|
31
|
-
# ==================
|
32
|
-
# You may pass any option but keep in mind that net/ssh understands a
|
33
|
-
# limited set of options, consult the Net::SSH documentation.
|
34
|
-
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
|
35
|
-
#
|
36
|
-
# Global options
|
37
|
-
# --------------
|
38
|
-
# set :ssh_options, {
|
39
|
-
# keys: %w(/home/rlisowski/.ssh/id_rsa),
|
40
|
-
# forward_agent: false,
|
41
|
-
# auth_methods: %w(password)
|
42
|
-
# }
|
43
|
-
#
|
44
34
|
# The server-based syntax can be used to override options:
|
45
35
|
# ------------------------------------
|
46
36
|
# server 'example.com',
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# server-based syntax
|
4
|
+
# ======================
|
5
|
+
# Defines a single server with a list of roles and multiple properties.
|
6
|
+
# You can define all roles on a single server, or split them:
|
7
|
+
|
8
|
+
# server 'example.com', user: 'deploy', roles: %w{app db web}, my_property: :my_value
|
9
|
+
# server 'example.com', user: 'deploy', roles: %w{app web}, other_property: :other_value
|
10
|
+
# server 'db.example.com', user: 'deploy', roles: %w{db}
|
11
|
+
|
12
|
+
# role-based syntax
|
13
|
+
# ==================
|
14
|
+
|
15
|
+
# Defines a role with one or multiple servers. The primary server in each
|
16
|
+
# group is considered to be the first unless any hosts have the primary
|
17
|
+
# property set. Specify the username and a domain or IP for the server.
|
18
|
+
# Don't use `:all`, it's a meta role.
|
19
|
+
|
20
|
+
# role :app, %w{deploy@example.com}, my_property: :my_value
|
21
|
+
# role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value
|
22
|
+
# role :db, %w{deploy@example.com}
|
23
|
+
|
24
|
+
# Configuration
|
25
|
+
# =============
|
26
|
+
set :webhook_url, ENV.fetch('WEBHOOK_URL') { MOCK_URL[(ENV['STATUS_CODE'] || '200')] }
|
27
|
+
set :webhook_starting_payload, content: '[production] Now, deploying...'
|
28
|
+
set :webhook_finished_payload, content: '[production] Deployment has been completed!'
|
29
|
+
set :webhook_failed_payload, content: '[production] Oops! something went wrong.'
|
30
|
+
set :webhook_reverting_payload, content: '[production] Reverting...'
|
31
|
+
set :webhook_rollbacked_payload, content: '[production] Rollback has been completed!'
|
32
|
+
|
33
|
+
# The server-based syntax can be used to override options:
|
34
|
+
# ------------------------------------
|
35
|
+
# server 'example.com',
|
36
|
+
# user: 'user_name',
|
37
|
+
# roles: %w{web app},
|
38
|
+
# ssh_options: {
|
39
|
+
# user: 'user_name', # overrides user setting above
|
40
|
+
# keys: %w(/home/user_name/.ssh/id_rsa),
|
41
|
+
# forward_agent: false,
|
42
|
+
# auth_methods: %w(publickey password)
|
43
|
+
# # password: 'please use keys'
|
44
|
+
# }
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# server-based syntax
|
2
4
|
# ======================
|
3
5
|
# Defines a single server with a list of roles and multiple properties.
|
@@ -21,10 +23,12 @@
|
|
21
23
|
|
22
24
|
# Configuration
|
23
25
|
# =============
|
24
|
-
set :webhook_url,
|
25
|
-
set :webhook_starting_payload,
|
26
|
-
set :webhook_finished_payload,
|
27
|
-
set :webhook_failed_payload,
|
26
|
+
set :webhook_url, ENV.fetch('WEBHOOK_URL') { MOCK_URL[(ENV['STATUS_CODE'] || '200')] }
|
27
|
+
set :webhook_starting_payload, text: '[production] Now, deploying...'
|
28
|
+
set :webhook_finished_payload, text: '[production] Deployment has been completed!'
|
29
|
+
set :webhook_failed_payload, text: '[production] Oops! something went wrong.'
|
30
|
+
set :webhook_reverting_payload, text: '[production] Reverting...'
|
31
|
+
set :webhook_rollbacked_payload, text: '[production] Rollback has been completed!'
|
28
32
|
|
29
33
|
# The server-based syntax can be used to override options:
|
30
34
|
# ------------------------------------
|
data/lib/capistrano/hook.rb
CHANGED
data/lib/capistrano/hook/load.rb
CHANGED
data/lib/capistrano/hook/web.rb
CHANGED
@@ -1,31 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json'
|
4
|
+
require 'net/http'
|
2
5
|
module Capistrano
|
3
6
|
module Hook
|
4
7
|
class Web
|
8
|
+
attr_reader :uri, :http, :request, :headers
|
5
9
|
private_class_method :new
|
6
10
|
|
7
|
-
def initialize(url)
|
8
|
-
@uri
|
9
|
-
@
|
10
|
-
|
11
|
+
def initialize(url, headers)
|
12
|
+
@uri = URI.parse(url).freeze
|
13
|
+
@headers = headers
|
14
|
+
initialize_http
|
15
|
+
initialize_request
|
11
16
|
end
|
12
17
|
|
13
18
|
def post(params)
|
14
|
-
# TODO: rescue / logger
|
15
19
|
http.start do
|
16
|
-
request =
|
17
|
-
request.set_form_data(payload: params.to_json)
|
20
|
+
request.body = params.to_json
|
18
21
|
http.request(request)
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
22
|
-
def self.client(url)
|
23
|
-
new(url)
|
25
|
+
def self.client(url, headers = {})
|
26
|
+
new(url, headers.is_a?(Hash) ? headers : {})
|
24
27
|
end
|
25
28
|
|
26
|
-
|
29
|
+
private
|
30
|
+
|
31
|
+
def path
|
32
|
+
return '/' if uri.path.nil?
|
33
|
+
return '/' if uri.path.empty?
|
27
34
|
|
28
|
-
|
35
|
+
uri.path
|
36
|
+
end
|
37
|
+
|
38
|
+
def default_headers
|
39
|
+
{ 'Content-Type' => 'application/json' }
|
40
|
+
end
|
41
|
+
|
42
|
+
def initialize_http
|
43
|
+
@http = Net::HTTP.new(uri.host, uri.port)
|
44
|
+
http.use_ssl = uri.is_a?(URI::HTTPS)
|
45
|
+
end
|
46
|
+
|
47
|
+
def initialize_request
|
48
|
+
@request = Net::HTTP::Post.new(path)
|
49
|
+
request.initialize_http_header(default_headers.merge(headers))
|
50
|
+
end
|
29
51
|
end
|
30
52
|
end
|
31
53
|
end
|
@@ -1,77 +1,106 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Capistrano hook will not be run with no settings.
|
4
|
+
#
|
5
|
+
# You can setting the variables shown below.
|
6
|
+
#
|
7
|
+
# set :webhook_url, 'https://yulii.github.io'
|
8
|
+
# set :webhook_starting_payload, { text: 'Now, deploying...' }
|
9
|
+
# set :webhook_finished_payload, { text: 'Deployment has been completed!' }
|
10
|
+
# set :webhook_failed_payload, { text: 'Oops! something went wrong.' }
|
11
|
+
# set :webhook_reverting_payload, { text: 'Reverting...' }
|
12
|
+
# set :webhook_rollbacked_payload, { text: 'Rollback has been completed!' }
|
4
13
|
|
5
|
-
|
14
|
+
namespace :webhook do
|
15
|
+
def webhook(url, payload, headers = {})
|
16
|
+
return if url.nil? || payload.nil? || payload.empty?
|
6
17
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
18
|
+
info "POST #{url} payload='#{payload}'"
|
19
|
+
result = Capistrano::Hook::Web.client(url, headers).post(payload)
|
20
|
+
message = "HTTP #{result.code} #{result.message} body='#{result.body}'; "
|
21
|
+
if result.is_a?(Net::HTTPSuccess)
|
22
|
+
info message
|
23
|
+
else
|
24
|
+
error message
|
25
|
+
end
|
26
|
+
end
|
11
27
|
|
12
|
-
|
28
|
+
namespace :config do
|
29
|
+
desc 'List the webhook configured variables'
|
30
|
+
task :list do
|
31
|
+
run_locally do
|
32
|
+
keys = %i[webhook_url
|
33
|
+
webhook_http_headers
|
34
|
+
webhook_starting_payload
|
35
|
+
webhook_finished_payload
|
36
|
+
webhook_failed_payload
|
37
|
+
webhook_reverting_payload
|
38
|
+
webhook_rollbacked_payload].sort
|
39
|
+
padding = keys.max_by(&:length).length
|
40
|
+
keys.each do |key|
|
41
|
+
next if fetch(key).nil? || fetch(key).empty?
|
13
42
|
|
14
|
-
|
15
|
-
|
43
|
+
puts ":#{key.to_s.ljust(padding)} => #{fetch(key)}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
16
47
|
end
|
17
48
|
|
18
49
|
namespace :post do
|
50
|
+
desc 'Post a starting message if :webhook_url and :webhook_starting_payload are present'
|
19
51
|
task :starting do
|
20
52
|
run_locally do
|
21
53
|
url = fetch(:webhook_url)
|
22
54
|
payload = fetch(:webhook_starting_payload)
|
23
|
-
|
24
|
-
|
25
|
-
result = Capistrano::Hook::Web.client(url).post(payload)
|
26
|
-
if result.is_a?(Net::HTTPSuccess)
|
27
|
-
info response_message(result, payload)
|
28
|
-
else
|
29
|
-
error response_message(result, payload)
|
30
|
-
end
|
31
|
-
rescue StandardError => e
|
32
|
-
error "[webhook:post:starting] #{e.class} #{e.message}"
|
33
|
-
end
|
55
|
+
headers = fetch(:webhook_http_headers)
|
56
|
+
webhook(url, payload, headers)
|
34
57
|
end
|
35
58
|
end
|
36
59
|
|
60
|
+
desc 'Post a finished message if :webhook_url and :webhook_finished_payload are present'
|
37
61
|
task :finished do
|
38
62
|
run_locally do
|
39
63
|
url = fetch(:webhook_url)
|
40
64
|
payload = fetch(:webhook_finished_payload)
|
41
|
-
|
42
|
-
|
43
|
-
result = Capistrano::Hook::Web.client(url).post(payload)
|
44
|
-
if result.is_a?(Net::HTTPSuccess)
|
45
|
-
info response_message(result, payload)
|
46
|
-
else
|
47
|
-
error response_message(result, payload)
|
48
|
-
end
|
49
|
-
rescue StandardError => e
|
50
|
-
error "[webhook:post:finishing] #{e.class} #{e.message}"
|
51
|
-
end
|
65
|
+
headers = fetch(:webhook_http_headers)
|
66
|
+
webhook(url, payload, headers)
|
52
67
|
end
|
53
68
|
end
|
54
69
|
|
70
|
+
desc 'Post a failed message if :webhook_url and :webhook_failed_payload are present'
|
55
71
|
task :failed do
|
56
72
|
run_locally do
|
57
73
|
url = fetch(:webhook_url)
|
58
74
|
payload = fetch(:webhook_failed_payload)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
75
|
+
headers = fetch(:webhook_http_headers)
|
76
|
+
webhook(url, payload, headers)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
desc 'Post a reverting message if :webhook_url and :webhook_reverting_payload are present'
|
81
|
+
task :reverting do
|
82
|
+
run_locally do
|
83
|
+
url = fetch(:webhook_url)
|
84
|
+
payload = fetch(:webhook_reverting_payload)
|
85
|
+
headers = fetch(:webhook_http_headers)
|
86
|
+
webhook(url, payload, headers)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
desc 'Post a rollbacked message if :webhook_url and :webhook_rollbacked_payload are present'
|
91
|
+
task :rollbacked do
|
92
|
+
run_locally do
|
93
|
+
url = fetch(:webhook_url)
|
94
|
+
payload = fetch(:webhook_rollbacked_payload)
|
95
|
+
headers = fetch(:webhook_http_headers)
|
96
|
+
webhook(url, payload, headers)
|
70
97
|
end
|
71
98
|
end
|
72
99
|
|
73
|
-
before 'deploy:starting',
|
74
|
-
after 'deploy:finishing',
|
75
|
-
after 'deploy:failed',
|
100
|
+
before 'deploy:starting', 'webhook:post:starting'
|
101
|
+
after 'deploy:finishing', 'webhook:post:finished'
|
102
|
+
after 'deploy:failed', 'webhook:post:failed'
|
103
|
+
before 'deploy:reverting', 'webhook:post:reverting'
|
104
|
+
after 'deploy:finishing_rollback', 'webhook:post:rollbacked'
|
76
105
|
end
|
77
106
|
end
|
metadata
CHANGED
@@ -1,59 +1,59 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-hook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yulii
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '3.
|
19
|
+
version: '3.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '3.
|
26
|
+
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: minitest
|
56
|
+
name: minitest-reporters
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,21 +67,21 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 12.3.3
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 12.3.3
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rubocop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: webmock
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -117,6 +117,7 @@ extra_rdoc_files: []
|
|
117
117
|
files:
|
118
118
|
- ".gitignore"
|
119
119
|
- ".rubocop.yml"
|
120
|
+
- ".rubocop_todo.yml"
|
120
121
|
- ".travis.yml"
|
121
122
|
- CODE_OF_CONDUCT.md
|
122
123
|
- Capfile
|
@@ -130,8 +131,9 @@ files:
|
|
130
131
|
- bin/test
|
131
132
|
- capistrano-hook.gemspec
|
132
133
|
- config/deploy.rb
|
133
|
-
- config/deploy/
|
134
|
-
- config/deploy/
|
134
|
+
- config/deploy/all.rb
|
135
|
+
- config/deploy/discord.rb
|
136
|
+
- config/deploy/slack.rb
|
135
137
|
- lib/capistrano/hook.rb
|
136
138
|
- lib/capistrano/hook/load.rb
|
137
139
|
- lib/capistrano/hook/version.rb
|
@@ -156,9 +158,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
158
|
- !ruby/object:Gem::Version
|
157
159
|
version: '0'
|
158
160
|
requirements: []
|
159
|
-
|
160
|
-
rubygems_version: 2.4.5
|
161
|
+
rubygems_version: 3.0.3
|
161
162
|
signing_key:
|
162
163
|
specification_version: 4
|
163
|
-
summary: Simple
|
164
|
+
summary: Simple webhooks for Capistrano deployments.
|
164
165
|
test_files: []
|