capistrano-webhook 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +58 -0
- data/Rakefile +1 -0
- data/capistrano-webhook.gemspec +26 -0
- data/lib/capistrano/webhook.rb +66 -0
- data/lib/capistrano/webhook/version.rb +5 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 38b5d46d2f0466186885538d311f50f3677aba57
|
4
|
+
data.tar.gz: e6eb51648254b187272654c24f9be1e546751aca
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d1ba3afbda8b71e0762c9165c9edd126b65a852128a8401291a199434e86a8fa0f0bd79d1031dbc4c96ba9f8f7be5bfdc09ba9a1d9497607fe6f311704d8f0d8
|
7
|
+
data.tar.gz: 92a4bda8eed793e26aae7a0d154be76b658295efb74cc3bbc4d8def5275ccb5ddfd12af5b939346df1f53b1c9a6b6a17adc3ac6977a44830e61ee7b95ea196e9
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Andrew Hammond
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Capistrano::Webhook
|
2
|
+
|
3
|
+
Simple webhooks for Capistrano deployments.
|
4
|
+
|
5
|
+
*Currently only supporting Capistrano 2.*
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile under the 'development' group:
|
10
|
+
|
11
|
+
gem 'capistrano-webhook', require: false
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
In your application's `deploy.rb` file, set a Capistrano variable called `webhooks` to a hash containing a set of callbacks you wish to run during your deployment. The hash keys should be event names (see supported events below) and they should map to arrays representing webhook arguments to send to Faraday. The first item in each webhook should be a valid Farday HTTP method (`:get`, `:post`, etc will map to `Faraday.get`, and `Faraday.post` respectively). All other arguments will be sent in to the Faraday method as arguments with as a splat.
|
16
|
+
|
17
|
+
```
|
18
|
+
require 'capistrano/webhook'
|
19
|
+
set(:webhooks) do
|
20
|
+
{
|
21
|
+
after_deploy: [
|
22
|
+
[:get, "https://ci.example.com", { sha: fetch(:current_revision), app: fetch(:application), env: fetch(:stage) }]
|
23
|
+
]
|
24
|
+
}
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
In this example, a `GET` request would be issued to `https://ci.example.com?sha=:current_revision&app=:application&env=:stage`
|
29
|
+
|
30
|
+
#### Supported Capistrano Events
|
31
|
+
|
32
|
+
```
|
33
|
+
:before_deploy # runs before 'deploy'
|
34
|
+
:before_deploy_migrations # runs before 'deploy:migrations'
|
35
|
+
:after_deploy # runs after 'deploy'
|
36
|
+
:after_deploy_migrations # runs after 'deploy:migrations'
|
37
|
+
```
|
38
|
+
|
39
|
+
#### See also:
|
40
|
+
|
41
|
+
For `get`, `head`, and `delete` requests, see: https://github.com/lostisland/faraday/blob/master/lib/faraday/connection.rb#L137
|
42
|
+
|
43
|
+
For `post`, `put`, and `patch` requests, see: https://github.com/lostisland/faraday/blob/master/lib/faraday/connection.rb#L174
|
44
|
+
|
45
|
+
## TODO
|
46
|
+
|
47
|
+
* Deeper Faraday support (POST body, headers, etc)
|
48
|
+
* Support for Cap 3
|
49
|
+
* Logging enhancements
|
50
|
+
* Support more events, maybe custom events
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
1. Fork it ( http://github.com/<my-github-username>/capistrano-webhook/fork )
|
55
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
57
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
58
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capistrano/webhook/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "capistrano-webhook"
|
8
|
+
spec.version = Capistrano::Webhook::VERSION
|
9
|
+
spec.authors = ["Andrew Hammond"]
|
10
|
+
spec.email = ["andrew@evertrue.com"]
|
11
|
+
spec.summary = %q{Simple webhooks for Capistrano deployments.}
|
12
|
+
spec.description = %q{Simple webhooks for Capistrano deployments.}
|
13
|
+
spec.homepage = "http://github.com/andrhamm"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "faraday"
|
22
|
+
spec.add_dependency "capistrano", "~> 2.15.5"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require "capistrano/webhook/version"
|
2
|
+
require 'capistrano'
|
3
|
+
require 'json'
|
4
|
+
require 'faraday'
|
5
|
+
|
6
|
+
module Capistrano
|
7
|
+
module Webhook
|
8
|
+
def self.extended(configuration)
|
9
|
+
configuration.load do
|
10
|
+
|
11
|
+
before 'deploy', 'webhook:before_deploy'
|
12
|
+
before 'deploy:migrations', 'webhook:before_deploy_migrations'
|
13
|
+
after 'deploy', 'webhook:after_deploy'
|
14
|
+
after 'deploy:migrations', 'webhook:after_deploy_migrations'
|
15
|
+
|
16
|
+
namespace :webhook do
|
17
|
+
task :before_deploy do
|
18
|
+
do_webhooks_for_event :before_deploy
|
19
|
+
end
|
20
|
+
task :before_deploy_migrations do
|
21
|
+
do_webhooks_for_event :before_deploy_migrations
|
22
|
+
end
|
23
|
+
task :after_deploy do
|
24
|
+
do_webhooks_for_event :after_deploy
|
25
|
+
end
|
26
|
+
task :after_deploy_migrations do
|
27
|
+
do_webhooks_for_event :after_deploy_migrations
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def webhooks
|
35
|
+
@webhooks ||= fetch(:webhooks, {})
|
36
|
+
end
|
37
|
+
|
38
|
+
def do_webhooks_for_event(event)
|
39
|
+
return unless webhooks[event]
|
40
|
+
|
41
|
+
puts "Running webhook for event: #{event}"
|
42
|
+
|
43
|
+
webhooks[event].each {|hook| do_webhook hook}
|
44
|
+
end
|
45
|
+
|
46
|
+
def do_webhook(hook)
|
47
|
+
http_method = hook.shift.to_sym
|
48
|
+
if Faraday::Connection::METHODS.include? http_method
|
49
|
+
conn = Faraday.new(url: hook.first) do |faraday|
|
50
|
+
faraday.response :logger
|
51
|
+
faraday.adapter Faraday.default_adapter
|
52
|
+
end
|
53
|
+
|
54
|
+
resp = conn.send http_method, *hook
|
55
|
+
else
|
56
|
+
puts "Invalid HTTP method <#{http_method}>"
|
57
|
+
end
|
58
|
+
rescue => e
|
59
|
+
puts "Error during webhook: #{e.message}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
if Capistrano::Configuration.instance
|
65
|
+
Capistrano::Configuration.instance.extend(Capistrano::Webhook)
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-webhook
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Hammond
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: capistrano
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.15.5
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.15.5
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Simple webhooks for Capistrano deployments.
|
70
|
+
email:
|
71
|
+
- andrew@evertrue.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- capistrano-webhook.gemspec
|
82
|
+
- lib/capistrano/webhook.rb
|
83
|
+
- lib/capistrano/webhook/version.rb
|
84
|
+
homepage: http://github.com/andrhamm
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.2.0
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Simple webhooks for Capistrano deployments.
|
108
|
+
test_files: []
|
109
|
+
has_rdoc:
|