Skip to content
代码片段 群组 项目
提交 926a8ab4 编辑于 作者: Valery Sizov's avatar Valery Sizov
浏览文件

Handle custom Git hook result in GitLab UI

上级 f60b48bd
No related branches found
No related tags found
无相关合并请求
...@@ -33,6 +33,7 @@ v 8.10.0 (unreleased) ...@@ -33,6 +33,7 @@ v 8.10.0 (unreleased)
- Add basic system information like memory and disk usage to the admin panel - Add basic system information like memory and disk usage to the admin panel
- Don't garbage collect commits that have related DB records like comments - Don't garbage collect commits that have related DB records like comments
- More descriptive message for git hooks and file locks - More descriptive message for git hooks and file locks
- Handle custom Git hook result in GitLab UI
v 8.9.5 (unreleased) v 8.9.5 (unreleased)
- Improve the request / withdraw access button. !4860 - Improve the request / withdraw access button. !4860
......
...@@ -36,10 +36,13 @@ def commit ...@@ -36,10 +36,13 @@ def commit
commit_id = repository.merge(current_user, merge_request.source_sha, merge_request.target_branch, options) commit_id = repository.merge(current_user, merge_request.source_sha, merge_request.target_branch, options)
merge_request.update(merge_commit_sha: commit_id) merge_request.update(merge_commit_sha: commit_id)
rescue GitHooksService::PreReceiveError => e
merge_request.update(merge_error: e.message)
false
rescue StandardError => e rescue StandardError => e
merge_request.update(merge_error: "Something went wrong during merge") merge_request.update(merge_error: "Something went wrong during merge")
Rails.logger.error(e.message) Rails.logger.error(e.message)
return false false
end end
def after_merge def after_merge
......
...@@ -41,7 +41,7 @@ def call_receive_hook(gl_id, oldrev, newrev, ref) ...@@ -41,7 +41,7 @@ def call_receive_hook(gl_id, oldrev, newrev, ref)
chdir: repo_path chdir: repo_path
} }
Open3.popen3(vars, path, options) do |stdin, _, stderr, wait_thr| Open3.popen3(vars, path, options) do |stdin, stdout, stderr, wait_thr|
exit_status = true exit_status = true
stdin.sync = true stdin.sync = true
...@@ -60,7 +60,7 @@ def call_receive_hook(gl_id, oldrev, newrev, ref) ...@@ -60,7 +60,7 @@ def call_receive_hook(gl_id, oldrev, newrev, ref)
unless wait_thr.value == 0 unless wait_thr.value == 0
exit_status = false exit_status = false
exit_message = stderr.gets exit_message = retrieve_error_message(stderr, stdout)
end end
end end
...@@ -76,6 +76,11 @@ def call_update_hook(gl_id, oldrev, newrev, ref) ...@@ -76,6 +76,11 @@ def call_update_hook(gl_id, oldrev, newrev, ref)
[status, nil] [status, nil]
end end
def retrieve_error_message(stderr, stdout)
err_message = stderr.gets
err_message.blank? ? stdout.gets : err_message
end
end end
end end
end end
...@@ -65,6 +65,16 @@ ...@@ -65,6 +65,16 @@
expect(merge_request.merge_error).to eq("Something went wrong during merge") expect(merge_request.merge_error).to eq("Something went wrong during merge")
end end
it 'saves error if there is an PreReceiveError exception' do
allow(service).to receive(:repository).and_raise(GitHooksService::PreReceiveError, "error")
allow(service).to receive(:execute_hooks)
service.execute(merge_request)
expect(merge_request.merge_error).to eq("error")
end
end end
end end
end end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册