Module: Capistrano::Webhook

Defined in:
lib/capistrano/webhook.rb,
lib/capistrano/webhook/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(configuration) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/capistrano/webhook.rb', line 8

def self.extended(configuration)
  configuration.load do

    before 'deploy',            'webhook:before_deploy'
    before 'deploy:migrations', 'webhook:before_deploy_migrations'
    after  'deploy',            'webhook:after_deploy'
    after  'deploy:migrations', 'webhook:after_deploy_migrations'

    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

  end
end

Instance Method Details

#do_webhook(hook) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/capistrano/webhook.rb', line 46

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.message}"
end

#do_webhooks_for_event(event) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/capistrano/webhook.rb', line 38

def do_webhooks_for_event(event)
  return unless webhooks[event]

  puts "Running webhook for event: #{event}"

  webhooks[event].each {|hook| do_webhook hook}
end

#webhooksObject



34
35
36
# File 'lib/capistrano/webhook.rb', line 34

def webhooks
  @webhooks ||= fetch(:webhooks, {})
end