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:
parent
0687ecb66d
commit
25951b9146
3 changed files with 15 additions and 2 deletions
|
@ -111,4 +111,11 @@ module Issuable
|
||||||
end
|
end
|
||||||
users.concat(mentions.reduce([], :|)).uniq
|
users.concat(mentions.reduce([], :|)).uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_hook_data
|
||||||
|
{
|
||||||
|
object_kind: self.class.name.underscore,
|
||||||
|
object_attributes: self.attributes
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -298,8 +298,10 @@ class Project < ActiveRecord::Base
|
||||||
ProjectTransferService.new.transfer(self, new_namespace)
|
ProjectTransferService.new.transfer(self, new_namespace)
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute_hooks(data)
|
def execute_hooks(data, hooks_scope = :push_hooks)
|
||||||
hooks.each { |hook| hook.async_execute(data) }
|
hooks.send(hooks_scope).each do |hook|
|
||||||
|
hook.async_execute(data)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute_services(data)
|
def execute_services(data)
|
||||||
|
|
|
@ -15,4 +15,8 @@ class ProjectHook < WebHook
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
|
|
||||||
attr_accessible :push_events, :issues_events, :merge_requests_events
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue