Commit 7cefdb49 authored by Robert Schilling's avatar Robert Schilling

Prevent 500 if hook url is down, fixes #7376

parent d30454e1
......@@ -25,8 +25,13 @@ class Projects::HooksController < Projects::ApplicationController
def test
if !@project.empty_repo?
TestHookService.new.execute(hook, current_user)
status = TestHookService.new.execute(hook, current_user)
if status
flash[:notice] = 'Hook successfully executed.'
else
flash[:alert] = 'Hook execution failed. '\
'Ensure hook URL is correct and service is up.'
end
else
flash[:alert] = 'Hook execution failed. Ensure the project has commits.'
end
......
......@@ -2,5 +2,8 @@ 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
......@@ -24,3 +24,9 @@ Feature: Project Hooks
And I visit project hooks page
When I click test hook button
Then I should see hook error message
Scenario: I test a hook on down URL
Given project has hook
And I visit project hooks page
When I click test hook button with invalid URL
Then I should see hook service down error message
......@@ -38,6 +38,11 @@ class ProjectHooks < Spinach::FeatureSteps
click_link 'Test Hook'
end
step 'I click test hook button with invalid URL' do
stub_request(:post, @hook.url).to_raise(SocketError)
click_link 'Test Hook'
end
step 'hook should be triggered' do
page.current_path.should == project_hooks_path(current_project)
page.should have_selector '.flash-notice',
......@@ -49,4 +54,11 @@ class ProjectHooks < Spinach::FeatureSteps
text: 'Hook execution failed. '\
'Ensure the project has commits.'
end
step 'I should see hook service down error message' do
page.should have_selector '.flash-alert',
text: 'Hook execution failed. '\
'Ensure hook URL is correct and '\
'service is up.'
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