Class: GitCommitNotifier::Webhook
- Inherits:
-
Object
- Object
- GitCommitNotifier::Webhook
- Defined in:
- lib/git_commit_notifier/webhook.rb
Constant Summary collapse
- PARAMETERS =
%w(committer email message subject changed old_rev new_rev ref_name repo_name)
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(config, options = {}) ⇒ Webhook
constructor
A new instance of Webhook.
- #payload ⇒ Object
- #send ⇒ Object
Constructor Details
#initialize(config, options = {}) ⇒ Webhook
Returns a new instance of Webhook.
13 14 15 16 17 18 |
# File 'lib/git_commit_notifier/webhook.rb', line 13 def initialize(config, = {}) @config = config || {} PARAMETERS.each do |name| instance_variable_set("@#{name}".to_sym, [name.to_sym]) end end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
11 12 13 |
# File 'lib/git_commit_notifier/webhook.rb', line 11 def config @config end |
Instance Method Details
#payload ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/git_commit_notifier/webhook.rb', line 20 def payload pay = { 'repository' => { 'name' => @repo_name }, 'ref' => @ref_name, 'before' => @old_rev, 'after' => @new_rev, 'commits' => [ { 'added' => @changed[:a], 'modified' => @changed[:m], 'removed' => @changed[:d], 'renamed' => @changed[:r], 'committer' => { 'name' => @committer, 'email' => @email }, 'message' => CGI::escape(@message) } ] } Yajl::Encoder.encode(pay) end |
#send ⇒ Object
45 46 47 48 |
# File 'lib/git_commit_notifier/webhook.rb', line 45 def send Net::HTTP.post_form(URI.parse(@config['webhook']['url']), { 'payload' => payload }) nil end |