Skip to content

Commit

Permalink
Return HTTP 500 if git fails - not that Github cares about this at th…
Browse files Browse the repository at this point in the history
…is point, but it seems more correct
  • Loading branch information
koppen committed Mar 8, 2010
1 parent 139fcf5 commit 5f69896
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
18 changes: 11 additions & 7 deletions app/controllers/github_hook_controller.rb
Expand Up @@ -21,12 +21,13 @@ def index

# Get updates from the Github repository
command = "cd '#{repository.url}' && git fetch origin && git reset --soft refs/remotes/origin/master"
exec(command)

# Fetch the new changesets into Redmine
repository.fetch_changesets

render(:text => 'OK')
if exec(command)
# Fetch the new changesets into Redmine
repository.fetch_changesets
render(:text => 'OK')
else
render(:text => 'Failed', :status => 500)
end
end

private
Expand All @@ -38,12 +39,15 @@ def exec(command)
output = stdout.readlines.collect(&:strip)
errors = stderr.readlines.collect(&:strip)

unless errors.empty?
if errors.empty?
return true
else
error_message = []
error_message << "Error occurred running git"
error_message += errors
error_message += output
logger.error error_message
return false
end
end

Expand Down
13 changes: 13 additions & 0 deletions test/functional/github_hook_controller_test.rb
Expand Up @@ -147,4 +147,17 @@ def test_exec_should_not_log_errors_if_none_occurred
@controller.logger.expects(:error).never
do_post
end

def test_should_return_500_if_git_has_errors
@controller.expects(:exec).returns(false)
do_post
assert_response 500
assert_equal 'Failed', @response.body
end

def test_should_not_import_changeset_if_git_has_errors
@controller.expects(:exec).returns(false)
@repository.expects(:fetch_changesets).never
do_post
end
end

0 comments on commit 5f69896

Please sign in to comment.