capistrano-hook 0.3.4 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b80c4faf5076514a2e20ceb5a515f973934c0e952102807233d03f31eac28a42
4
- data.tar.gz: a0c638091a9edad6c551fdf4e412ed262e1279b8c9010b5fc0caf2cffcc83696
3
+ metadata.gz: 99bc36d1c0f7464499165ef8406b0b28a13c58410c7c9f7aabd566c17550339a
4
+ data.tar.gz: a3f5b8ab947dada284400bbe0e09596ca3cb3b07649c8a5bceef9fad2845b4bf
5
5
  SHA512:
6
- metadata.gz: 065e963486d4e78e1efcc71fd14f77e1e003634d9ddb845a98d64aca9b666b4d2074e1f673550deadc8214c570c5643dd7e89b418a5d3969d96b0e4da1062363
7
- data.tar.gz: 88fe744384f7d9fee5ce19a16cec95509743163ab92f9115fb53a644e264e8c065ef73cb184357b03820904487e323d37f8dc0fc66a73f8947f2798ce557a20c
6
+ metadata.gz: f242724c1176a34f71b0000456d4d813d62c63f7f67799bc02b4650f2e60d9dd4a358f0c376a585ae69f252b67372ed1a55b57c667c7d971b841ba698dac7021
7
+ data.tar.gz: 8addfb5040dbd8ecdefea9c25eb06fbf28b0d77172a0f02321f893633789c68ca0abb456d143822eb8948361d55ade6dbde990fd4c14d1c5bbfc27c25a3218ca
@@ -1,12 +1,13 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
1
3
  Metrics/BlockLength:
2
- Max: 76
4
+ Max: 100
3
5
 
4
6
  Metrics/LineLength:
5
- Max: 104
7
+ Max: 160
6
8
 
7
9
  Style/Documentation:
8
10
  Enabled: false
9
11
 
10
- Style/SpaceBeforeFirstArg:
12
+ Layout/SpaceBeforeFirstArg:
11
13
  Enabled: false
12
-
@@ -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.
@@ -1,10 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.3.8
4
- - 2.4.7
5
- - 2.5.6
6
- - 2.6.4
7
- before_install: gem install bundler -v 1.12.5
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
8
9
  script:
9
10
  - bundle exec rake
10
11
  - bundle exec rubocop
data/Capfile CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'capistrano/setup'
4
4
  require 'capistrano/deploy'
5
+ require 'capistrano/scm/git'
5
6
  require 'capistrano/hook'
6
7
 
8
+ install_plugin Capistrano::SCM::Git
7
9
  # Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
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
@@ -15,7 +15,11 @@ Gem::Specification.new do |spec|
15
15
  spec.homepage = 'https://github.com/yulii/capistrano-hook'
16
16
  spec.license = 'MIT'
17
17
 
18
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
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
19
23
  spec.bindir = 'exe'
20
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
25
  spec.require_paths = ['lib']
@@ -25,6 +29,7 @@ Gem::Specification.new do |spec|
25
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 'rake', '~> 10.0'
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
@@ -1,14 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # config valid only for current version of Capistrano
4
- lock '3.4.0'
4
+ # lock '3.4.0'
5
5
 
6
6
  set :application, 'capistrano-hook'
7
7
  set :repo_url, 'git@github.com:yulii/capistrano-hook.git'
8
8
  set :branch, :master
9
9
 
10
10
  set :deploy_to, '/tmp'
11
- set :scm, :git
12
11
  set :format, :pretty
13
12
  set :log_level, :debug
14
13
 
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  # server-based syntax
3
4
  # ======================
4
5
  # Defines a single server with a list of roles and multiple properties.
@@ -22,26 +23,14 @@
22
23
 
23
24
  # Configuration
24
25
  # =============
25
- # You can set any configuration variable like in config/deploy.rb
26
- # These variables are then only loaded and set in this stage.
27
- # For available Capistrano configuration variables see the documentation page.
28
- # http://capistranorb.com/documentation/getting-started/configuration/
29
- # Feel free to add new variables to customise your setup.
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!'
30
33
 
31
- # Custom SSH Options
32
- # ==================
33
- # You may pass any option but keep in mind that net/ssh understands a
34
- # limited set of options, consult the Net::SSH documentation.
35
- # http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
36
- #
37
- # Global options
38
- # --------------
39
- # set :ssh_options, {
40
- # keys: %w(/home/rlisowski/.ssh/id_rsa),
41
- # forward_agent: false,
42
- # auth_methods: %w(password)
43
- # }
44
- #
45
34
  # The server-based syntax can be used to override options:
46
35
  # ------------------------------------
47
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
+ # }
@@ -23,7 +23,7 @@
23
23
 
24
24
  # Configuration
25
25
  # =============
26
- set :webhook_url, MOCK_URL[(ENV['STATUS_CODE'] || '200')]
26
+ set :webhook_url, ENV.fetch('WEBHOOK_URL') { MOCK_URL[(ENV['STATUS_CODE'] || '200')] }
27
27
  set :webhook_starting_payload, text: '[production] Now, deploying...'
28
28
  set :webhook_finished_payload, text: '[production] Deployment has been completed!'
29
29
  set :webhook_failed_payload, text: '[production] Oops! something went wrong.'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Capistrano
4
4
  module Hook
5
- VERSION = '0.3.4'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
@@ -5,34 +5,49 @@ require 'net/http'
5
5
  module Capistrano
6
6
  module Hook
7
7
  class Web
8
+ attr_reader :uri, :http, :request, :headers
8
9
  private_class_method :new
9
10
 
10
- def initialize(url)
11
- @uri = URI.parse(url).freeze
12
- @http = Net::HTTP.new(@uri.host, @uri.port)
13
- @http.use_ssl = @uri.is_a?(URI::HTTPS)
11
+ def initialize(url, headers)
12
+ @uri = URI.parse(url).freeze
13
+ @headers = headers
14
+ initialize_http
15
+ initialize_request
14
16
  end
15
17
 
16
18
  def post(params)
17
- # TODO: rescue / logger
18
19
  http.start do
19
- http.request(request(params))
20
+ request.body = params.to_json
21
+ http.request(request)
20
22
  end
21
23
  end
22
24
 
23
- def request(params)
24
- Net::HTTP::Post.new(uri.path).tap do |o|
25
- o.set_form_data(payload: params.to_json)
26
- end
25
+ def self.client(url, headers = {})
26
+ new(url, headers.is_a?(Hash) ? headers : {})
27
27
  end
28
28
 
29
- def self.client(url)
30
- new(url)
29
+ private
30
+
31
+ def path
32
+ return '/' if uri.path.nil?
33
+ return '/' if uri.path.empty?
34
+
35
+ uri.path
31
36
  end
32
37
 
33
- protected
38
+ def default_headers
39
+ { 'Content-Type' => 'application/json' }
40
+ end
34
41
 
35
- attr_reader :uri, :http
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
36
51
  end
37
52
  end
38
53
  end
@@ -12,11 +12,11 @@
12
12
  # set :webhook_rollbacked_payload, { text: 'Rollback has been completed!' }
13
13
 
14
14
  namespace :webhook do
15
- def webhook(url, payload)
15
+ def webhook(url, payload, headers = {})
16
16
  return if url.nil? || payload.nil? || payload.empty?
17
17
 
18
18
  info "POST #{url} payload='#{payload}'"
19
- result = Capistrano::Hook::Web.client(url).post(payload)
19
+ result = Capistrano::Hook::Web.client(url, headers).post(payload)
20
20
  message = "HTTP #{result.code} #{result.message} body='#{result.body}'; "
21
21
  if result.is_a?(Net::HTTPSuccess)
22
22
  info message
@@ -30,6 +30,7 @@ namespace :webhook do
30
30
  task :list do
31
31
  run_locally do
32
32
  keys = %i[webhook_url
33
+ webhook_http_headers
33
34
  webhook_starting_payload
34
35
  webhook_finished_payload
35
36
  webhook_failed_payload
@@ -51,7 +52,8 @@ namespace :webhook do
51
52
  run_locally do
52
53
  url = fetch(:webhook_url)
53
54
  payload = fetch(:webhook_starting_payload)
54
- webhook(url, payload)
55
+ headers = fetch(:webhook_http_headers)
56
+ webhook(url, payload, headers)
55
57
  end
56
58
  end
57
59
 
@@ -60,7 +62,8 @@ namespace :webhook do
60
62
  run_locally do
61
63
  url = fetch(:webhook_url)
62
64
  payload = fetch(:webhook_finished_payload)
63
- webhook(url, payload)
65
+ headers = fetch(:webhook_http_headers)
66
+ webhook(url, payload, headers)
64
67
  end
65
68
  end
66
69
 
@@ -69,7 +72,8 @@ namespace :webhook do
69
72
  run_locally do
70
73
  url = fetch(:webhook_url)
71
74
  payload = fetch(:webhook_failed_payload)
72
- webhook(url, payload)
75
+ headers = fetch(:webhook_http_headers)
76
+ webhook(url, payload, headers)
73
77
  end
74
78
  end
75
79
 
@@ -78,7 +82,8 @@ namespace :webhook do
78
82
  run_locally do
79
83
  url = fetch(:webhook_url)
80
84
  payload = fetch(:webhook_reverting_payload)
81
- webhook(url, payload)
85
+ headers = fetch(:webhook_http_headers)
86
+ webhook(url, payload, headers)
82
87
  end
83
88
  end
84
89
 
@@ -87,7 +92,8 @@ namespace :webhook do
87
92
  run_locally do
88
93
  url = fetch(:webhook_url)
89
94
  payload = fetch(:webhook_rollbacked_payload)
90
- webhook(url, payload)
95
+ headers = fetch(:webhook_http_headers)
96
+ webhook(url, payload, headers)
91
97
  end
92
98
  end
93
99
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-hook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
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: 2019-10-22 00:00:00.000000000 Z
11
+ date: 2020-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
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: '10.0'
82
+ version: 12.3.3
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rubocop
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Notification hooks include start, finish and fail of deployments.
98
112
  email:
99
113
  - yone.info@gmail.com
@@ -103,6 +117,7 @@ extra_rdoc_files: []
103
117
  files:
104
118
  - ".gitignore"
105
119
  - ".rubocop.yml"
120
+ - ".rubocop_todo.yml"
106
121
  - ".travis.yml"
107
122
  - CODE_OF_CONDUCT.md
108
123
  - Capfile
@@ -116,8 +131,9 @@ files:
116
131
  - bin/test
117
132
  - capistrano-hook.gemspec
118
133
  - config/deploy.rb
119
- - config/deploy/production.rb
120
- - config/deploy/staging.rb
134
+ - config/deploy/all.rb
135
+ - config/deploy/discord.rb
136
+ - config/deploy/slack.rb
121
137
  - lib/capistrano/hook.rb
122
138
  - lib/capistrano/hook/load.rb
123
139
  - lib/capistrano/hook/version.rb