Commit 25951b91 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

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: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 0687ecb6
...@@ -111,4 +111,11 @@ module Issuable ...@@ -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 ...@@ -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 ...@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment