Prepare ProjectHooks to work with issues and merge_requests

* Add event scopes to ProjectHook
* Added Issuable#to_hook_data
* Project#execute_hooks now accept hook filter as argument

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
Dmitriy Zaporozhets 2013-12-03 11:31:56 +02:00
parent 0687ecb66d
commit 25951b9146
3 changed files with 15 additions and 2 deletions

View File

@ -111,4 +111,11 @@ module Issuable
end
users.concat(mentions.reduce([], :|)).uniq
end
def to_hook_data
{
object_kind: self.class.name.underscore,
object_attributes: self.attributes
}
end
end

View File

@ -298,8 +298,10 @@ class Project < ActiveRecord::Base
ProjectTransferService.new.transfer(self, new_namespace)
end
def execute_hooks(data)
hooks.each { |hook| hook.async_execute(data) }
def execute_hooks(data, hooks_scope = :push_hooks)
hooks.send(hooks_scope).each do |hook|
hook.async_execute(data)
end
end
def execute_services(data)

View File

@ -15,4 +15,8 @@ class ProjectHook < WebHook
belongs_to :project
attr_accessible :push_events, :issues_events, :merge_requests_events
scope :push_hooks, -> { where(push_events: true) }
scope :issue_hooks, -> { where(issues_events: true) }
scope :merge_request_hooks, -> { where(merge_requests_events: true) }
end