Merge branch 'prevent-500-test-webhook' into 'master'
Prevent 500 test webhook Fixes #1803 See merge request !1299
This commit is contained in:
commit
d7fa9952ef
|
@ -26,6 +26,7 @@ class Projects::HooksController < Projects::ApplicationController
|
|||
def test
|
||||
if !@project.empty_repo?
|
||||
status = TestHookService.new.execute(hook, current_user)
|
||||
|
||||
if status
|
||||
flash[:notice] = 'Hook successfully executed.'
|
||||
else
|
||||
|
|
|
@ -32,7 +32,10 @@ class WebHook < ActiveRecord::Base
|
|||
def execute(data)
|
||||
parsed_url = URI.parse(url)
|
||||
if parsed_url.userinfo.blank?
|
||||
WebHook.post(url, body: data.to_json, headers: { "Content-Type" => "application/json" }, verify: false)
|
||||
WebHook.post(url,
|
||||
body: data.to_json,
|
||||
headers: { "Content-Type" => "application/json" },
|
||||
verify: false)
|
||||
else
|
||||
post_url = url.gsub("#{parsed_url.userinfo}@", "")
|
||||
auth = {
|
||||
|
@ -45,6 +48,9 @@ class WebHook < ActiveRecord::Base
|
|||
verify: false,
|
||||
basic_auth: auth)
|
||||
end
|
||||
rescue SocketError, Errno::ECONNREFUSED => e
|
||||
logger.error("WebHook Error => #{e}")
|
||||
false
|
||||
end
|
||||
|
||||
def async_execute(data)
|
||||
|
|
|
@ -2,8 +2,5 @@ class TestHookService
|
|||
def execute(hook, current_user)
|
||||
data = GitPushService.new.sample_data(hook.project, current_user)
|
||||
hook.execute(data)
|
||||
true
|
||||
rescue SocketError
|
||||
false
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue