Merge branch 'fix-multi-line-hook-output' into 'master'

Display full pre-receive and post-receive hook output in GitLab UI

Closes #25214

See merge request gitlab-org/gitlab-ce!14222
This commit is contained in:
Rémy Coutable 2017-09-22 06:12:58 +00:00
commit d2d5549d2a
3 changed files with 11 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
title: Display full pre-receive and post-receive hook output in GitLab UI
merge_request: 14222
author: Robin Bobbitt
type: fixed

View file

@ -83,13 +83,14 @@ module Gitlab
def call_update_hook(gl_id, oldrev, newrev, ref)
Dir.chdir(repo_path) do
stdout, stderr, status = Open3.capture3({ 'GL_ID' => gl_id }, path, ref, oldrev, newrev)
[status.success?, stderr.presence || stdout]
[status.success?, (stderr.presence || stdout).gsub(/\R/, "<br>").html_safe]
end
end
def retrieve_error_message(stderr, stdout)
err_message = stderr.gets
err_message.blank? ? stdout.gets : err_message
err_message = stderr.read
err_message = err_message.blank? ? stdout.read : err_message
err_message.gsub(/\R/, "<br>").html_safe
end
end
end

View file

@ -28,6 +28,7 @@ describe Gitlab::Git::Hook do
f.write(<<-HOOK)
echo 'regular message from the hook'
echo 'error message from the hook' 1>&2
echo 'error message from the hook line 2' 1>&2
exit 1
HOOK
end
@ -73,7 +74,7 @@ describe Gitlab::Git::Hook do
status, errors = hook.trigger(gl_id, blank, blank, ref)
expect(status).to be false
expect(errors).to eq("error message from the hook\n")
expect(errors).to eq("error message from the hook<br>error message from the hook line 2<br>")
end
end
end