Module: Capistrano::Webhook
- Defined in:
- lib/capistrano/webhook.rb,
lib/capistrano/webhook/version.rb,
lib/capistrano/webhook/v2/tasks.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.extended(configuration) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/capistrano/webhook/v2/tasks.rb', line 5 def self.extended(configuration) configuration.load do namespace :webhook do task :before_deploy do do_webhooks_for_event :before_deploy end task :before_deploy_migrations do do_webhooks_for_event :before_deploy_migrations end task :after_deploy do do_webhooks_for_event :after_deploy end task :after_deploy_migrations do do_webhooks_for_event :after_deploy_migrations end end before 'deploy', 'webhook:before_deploy' before 'deploy:migrations', 'webhook:before_deploy_migrations' after 'deploy', 'webhook:after_deploy' after 'deploy:migrations', 'webhook:after_deploy_migrations' end end |
Instance Method Details
#do_webhook(hook) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/capistrano/webhook.rb', line 21 def do_webhook(hook) http_method = hook.shift.to_sym if Faraday::Connection::METHODS.include? http_method conn = Faraday.new(url: hook.first) do |faraday| faraday.response :logger faraday.adapter Faraday.default_adapter end resp = conn.send http_method, *hook else puts "Invalid HTTP method <#{http_method}>" end rescue => e puts "Error during webhook: #{e.}" end |
#do_webhooks_for_event(event) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/capistrano/webhook.rb', line 13 def do_webhooks_for_event(event) return unless webhooks[event] puts "Running webhook for event: #{event}" webhooks[event].each {|hook| do_webhook hook} end |
#webhooks ⇒ Object
9 10 11 |
# File 'lib/capistrano/webhook.rb', line 9 def webhooks fetch :webhooks, {} end |