diff options
author | bugagazavr <kirik910@gmail.com> | 2015-01-24 03:10:43 +0300 |
---|---|---|
committer | Kirill Zaitsev <kirik910@gmail.com> | 2015-05-08 16:49:03 +0300 |
commit | acac7889023de96af61d293d855c33996bd780a1 (patch) | |
tree | 83d3d7ef3e7a12eca12843bccf92b6bd080b648a /app/models | |
parent | 0fc6f0b5d406f530e9ad8a35f0188536f6525cb9 (diff) | |
download | gitlab-ce-acac7889023de96af61d293d855c33996bd780a1.tar.gz |
Added X-GitLab-Event header for web hooks
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/hooks/service_hook.rb | 4 | ||||
-rw-r--r-- | app/models/hooks/web_hook.rb | 16 | ||||
-rw-r--r-- | app/models/project.rb | 2 |
3 files changed, 16 insertions, 6 deletions
diff --git a/app/models/hooks/service_hook.rb b/app/models/hooks/service_hook.rb index 2e11239c40b..5b38ade2e6b 100644 --- a/app/models/hooks/service_hook.rb +++ b/app/models/hooks/service_hook.rb @@ -17,4 +17,8 @@ class ServiceHook < WebHook belongs_to :service + + def execute(data) + super(data, 'service_hook') + end end diff --git a/app/models/hooks/web_hook.rb b/app/models/hooks/web_hook.rb index 315d96af1b9..e9fd441352d 100644 --- a/app/models/hooks/web_hook.rb +++ b/app/models/hooks/web_hook.rb @@ -30,12 +30,15 @@ class WebHook < ActiveRecord::Base validates :url, presence: true, format: { with: /\A#{URI.regexp(%w(http https))}\z/, message: "should be a valid url" } - def execute(data) + def execute(data, hook_name) parsed_url = URI.parse(url) if parsed_url.userinfo.blank? WebHook.post(url, body: data.to_json, - headers: { "Content-Type" => "application/json" }, + headers: { + "Content-Type" => "application/json", + "X-Gitlab-Event" => hook_name.singularize.titleize + }, verify: false) else post_url = url.gsub("#{parsed_url.userinfo}@", "") @@ -45,7 +48,10 @@ class WebHook < ActiveRecord::Base } WebHook.post(post_url, body: data.to_json, - headers: { "Content-Type" => "application/json" }, + headers: { + "Content-Type" => "application/json", + "X-Gitlab-Event" => hook_name.singularize.titleize + }, verify: false, basic_auth: auth) end @@ -54,7 +60,7 @@ class WebHook < ActiveRecord::Base false end - def async_execute(data) - Sidekiq::Client.enqueue(ProjectWebHookWorker, id, data) + def async_execute(data, hook_name) + Sidekiq::Client.enqueue(ProjectWebHookWorker, id, data, hook_name) end end diff --git a/app/models/project.rb b/app/models/project.rb index e866681aab9..bc77e7217ee 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -483,7 +483,7 @@ class Project < ActiveRecord::Base def execute_hooks(data, hooks_scope = :push_hooks) hooks.send(hooks_scope).each do |hook| - hook.async_execute(data) + hook.async_execute(data, hooks_scope.to_s) end end |