Commit bc9ba523 authored by Valery Sizov's avatar Valery Sizov

Revert "Added X-GitLab-Event header for web hooks"

This reverts commit 548f1828.
parent bb8c1cad
...@@ -11,7 +11,6 @@ v 7.11.0 (unreleased) ...@@ -11,7 +11,6 @@ v 7.11.0 (unreleased)
- Add "Reply quoting selected text" shortcut key (`r`) - Add "Reply quoting selected text" shortcut key (`r`)
- Fix bug causing `@whatever` inside an issue's first code block to be picked up as a user mention. - Fix bug causing `@whatever` inside an issue's first code block to be picked up as a user mention.
- Fix bug causing `@whatever` inside an inline code snippet (backtick-style) to be picked up as a user mention. - Fix bug causing `@whatever` inside an inline code snippet (backtick-style) to be picked up as a user mention.
- Added GitLab Event header for project hooks
- -
- Show Atom feed buttons everywhere where applicable. - Show Atom feed buttons everywhere where applicable.
- Add project activity atom feed. - Add project activity atom feed.
......
...@@ -33,7 +33,7 @@ class Admin::HooksController < Admin::ApplicationController ...@@ -33,7 +33,7 @@ class Admin::HooksController < Admin::ApplicationController
owner_name: "Someone", owner_name: "Someone",
owner_email: "example@gitlabhq.com" owner_email: "example@gitlabhq.com"
} }
@hook.execute(data, 'system_hooks') @hook.execute(data)
redirect_to :back redirect_to :back
end end
......
...@@ -30,15 +30,12 @@ class WebHook < ActiveRecord::Base ...@@ -30,15 +30,12 @@ class WebHook < ActiveRecord::Base
validates :url, presence: true, validates :url, presence: true,
format: { with: /\A#{URI.regexp(%w(http https))}\z/, message: "should be a valid url" } format: { with: /\A#{URI.regexp(%w(http https))}\z/, message: "should be a valid url" }
def execute(data, hook_name) def execute(data)
parsed_url = URI.parse(url) parsed_url = URI.parse(url)
if parsed_url.userinfo.blank? if parsed_url.userinfo.blank?
WebHook.post(url, WebHook.post(url,
body: data.to_json, body: data.to_json,
headers: { headers: { "Content-Type" => "application/json" },
"Content-Type" => "application/json",
"X-Gitlab-Event" => hook_name.singularize.titleize
},
verify: false) verify: false)
else else
post_url = url.gsub("#{parsed_url.userinfo}@", "") post_url = url.gsub("#{parsed_url.userinfo}@", "")
...@@ -48,10 +45,7 @@ class WebHook < ActiveRecord::Base ...@@ -48,10 +45,7 @@ class WebHook < ActiveRecord::Base
} }
WebHook.post(post_url, WebHook.post(post_url,
body: data.to_json, body: data.to_json,
headers: { headers: { "Content-Type" => "application/json" },
"Content-Type" => "application/json",
"X-Gitlab-Event" => hook_name.singularize.titleize
},
verify: false, verify: false,
basic_auth: auth) basic_auth: auth)
end end
...@@ -60,7 +54,7 @@ class WebHook < ActiveRecord::Base ...@@ -60,7 +54,7 @@ class WebHook < ActiveRecord::Base
false false
end end
def async_execute(data, hook_name) def async_execute(data)
Sidekiq::Client.enqueue(ProjectWebHookWorker, id, data, hook_name) Sidekiq::Client.enqueue(ProjectWebHookWorker, id, data)
end end
end end
...@@ -483,7 +483,7 @@ class Project < ActiveRecord::Base ...@@ -483,7 +483,7 @@ class Project < ActiveRecord::Base
def execute_hooks(data, hooks_scope = :push_hooks) def execute_hooks(data, hooks_scope = :push_hooks)
hooks.send(hooks_scope).each do |hook| hooks.send(hooks_scope).each do |hook|
hook.async_execute(data, hooks_scope.to_s) hook.async_execute(data)
end end
end end
......
...@@ -7,12 +7,12 @@ class SystemHooksService ...@@ -7,12 +7,12 @@ class SystemHooksService
def execute_hooks(data) def execute_hooks(data)
SystemHook.all.each do |sh| SystemHook.all.each do |sh|
async_execute_hook(sh, data, 'system_hooks') async_execute_hook sh, data
end end
end end
def async_execute_hook(hook, data, hook_name) def async_execute_hook(hook, data)
Sidekiq::Client.enqueue(SystemHookWorker, hook.id, data, hook_name) Sidekiq::Client.enqueue(SystemHookWorker, hook.id, data)
end end
def build_event_data(model, event) def build_event_data(model, event)
......
class TestHookService class TestHookService
def execute(hook, current_user) def execute(hook, current_user)
data = Gitlab::PushDataBuilder.build_sample(hook.project, current_user) data = Gitlab::PushDataBuilder.build_sample(hook.project, current_user)
hook.execute(data, 'push_hooks') hook.execute(data)
end end
end end
...@@ -3,8 +3,8 @@ class ProjectWebHookWorker ...@@ -3,8 +3,8 @@ class ProjectWebHookWorker
sidekiq_options queue: :project_web_hook sidekiq_options queue: :project_web_hook
def perform(hook_id, data, hook_name) def perform(hook_id, data)
data = data.with_indifferent_access data = data.with_indifferent_access
WebHook.find(hook_id).execute(data, hook_name) WebHook.find(hook_id).execute(data)
end end
end end
...@@ -3,7 +3,7 @@ class SystemHookWorker ...@@ -3,7 +3,7 @@ class SystemHookWorker
sidekiq_options queue: :system_hook sidekiq_options queue: :system_hook
def perform(hook_id, data, hook_name) def perform(hook_id, data)
SystemHook.find(hook_id).execute(data, hook_name) SystemHook.find(hook_id).execute data
end end
end end
...@@ -47,7 +47,7 @@ module API ...@@ -47,7 +47,7 @@ module API
owner_name: "Someone", owner_name: "Someone",
owner_email: "example@gitlabhq.com" owner_email: "example@gitlabhq.com"
} }
@hook.execute(data, 'system_hooks') @hook.execute(data)
data data
end end
......
...@@ -52,26 +52,22 @@ describe ProjectHook do ...@@ -52,26 +52,22 @@ describe ProjectHook do
end end
it "POSTs to the web hook URL" do it "POSTs to the web hook URL" do
@project_hook.execute(@data, 'push_hooks') @project_hook.execute(@data)
expect(WebMock).to have_requested(:post, @project_hook.url). expect(WebMock).to have_requested(:post, @project_hook.url).once
with(headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'Push Hook'}).
once
end end
it "POSTs the data as JSON" do it "POSTs the data as JSON" do
json = @data.to_json json = @data.to_json
@project_hook.execute(@data, 'push_hooks') @project_hook.execute(@data)
expect(WebMock).to have_requested(:post, @project_hook.url). expect(WebMock).to have_requested(:post, @project_hook.url).with(body: json).once
with(headers: {'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'Push Hook'}).
once
end end
it "catches exceptions" do it "catches exceptions" do
expect(WebHook).to receive(:post).and_raise("Some HTTP Post error") expect(WebHook).to receive(:post).and_raise("Some HTTP Post error")
expect { expect {
@project_hook.execute(@data, 'push_hooks') @project_hook.execute(@data)
}.to raise_error }.to raise_error
end end
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