Commit b4e3dc95 authored by Rajendra Kadam's avatar Rajendra Kadam Committed by Peter Leitzen

Use applogger in merge_service.rb

parent 11271ac4
...@@ -121,12 +121,12 @@ module MergeRequests ...@@ -121,12 +121,12 @@ module MergeRequests
end end
def handle_merge_error(log_message:, save_message_on_model: false) def handle_merge_error(log_message:, save_message_on_model: false)
Rails.logger.error("MergeService ERROR: #{merge_request_info} - #{log_message}") # rubocop:disable Gitlab/RailsLogger Gitlab::AppLogger.error("MergeService ERROR: #{merge_request_info} - #{log_message}")
@merge_request.update(merge_error: log_message) if save_message_on_model @merge_request.update(merge_error: log_message) if save_message_on_model
end end
def log_info(message) def log_info(message)
@logger ||= Rails.logger # rubocop:disable Gitlab/RailsLogger @logger ||= Gitlab::AppLogger
@logger.info("#{merge_request_info} - #{message}") @logger.info("#{merge_request_info} - #{message}")
end end
......
---
title: Use applogger in merge_service.rb
merge_request: 32196
author: Rajendra Kadam
type: fixed
...@@ -87,7 +87,7 @@ describe MergeRequests::FfMergeService do ...@@ -87,7 +87,7 @@ describe MergeRequests::FfMergeService do
let(:service) { described_class.new(project, user, valid_merge_params.merge(commit_message: 'Awesome message')) } let(:service) { described_class.new(project, user, valid_merge_params.merge(commit_message: 'Awesome message')) }
before do before do
allow(Rails.logger).to receive(:error) allow(Gitlab::AppLogger).to receive(:error)
end end
it 'logs and saves error if there is an exception' do it 'logs and saves error if there is an exception' do
...@@ -99,7 +99,7 @@ describe MergeRequests::FfMergeService do ...@@ -99,7 +99,7 @@ describe MergeRequests::FfMergeService do
service.execute(merge_request) service.execute(merge_request)
expect(merge_request.merge_error).to include(error_message) expect(merge_request.merge_error).to include(error_message)
expect(Rails.logger).to have_received(:error).with(a_string_matching(error_message)) expect(Gitlab::AppLogger).to have_received(:error).with(a_string_matching(error_message))
end end
it 'logs and saves error if there is an PreReceiveError exception' do it 'logs and saves error if there is an PreReceiveError exception' do
...@@ -111,7 +111,7 @@ describe MergeRequests::FfMergeService do ...@@ -111,7 +111,7 @@ describe MergeRequests::FfMergeService do
service.execute(merge_request) service.execute(merge_request)
expect(merge_request.merge_error).to include(error_message) expect(merge_request.merge_error).to include(error_message)
expect(Rails.logger).to have_received(:error).with(a_string_matching(error_message)) expect(Gitlab::AppLogger).to have_received(:error).with(a_string_matching(error_message))
end end
it 'does not update squash_commit_sha if squash merge is not successful' do it 'does not update squash_commit_sha if squash merge is not successful' do
......
...@@ -277,7 +277,7 @@ describe MergeRequests::MergeService do ...@@ -277,7 +277,7 @@ describe MergeRequests::MergeService do
context 'error handling' do context 'error handling' do
before do before do
allow(Rails.logger).to receive(:error) allow(Gitlab::AppLogger).to receive(:error)
end end
context 'when source is missing' do context 'when source is missing' do
...@@ -289,7 +289,7 @@ describe MergeRequests::MergeService do ...@@ -289,7 +289,7 @@ describe MergeRequests::MergeService do
service.execute(merge_request) service.execute(merge_request)
expect(merge_request.merge_error).to eq(error_message) expect(merge_request.merge_error).to eq(error_message)
expect(Rails.logger).to have_received(:error).with(a_string_matching(error_message)) expect(Gitlab::AppLogger).to have_received(:error).with(a_string_matching(error_message))
end end
end end
...@@ -302,7 +302,7 @@ describe MergeRequests::MergeService do ...@@ -302,7 +302,7 @@ describe MergeRequests::MergeService do
service.execute(merge_request) service.execute(merge_request)
expect(merge_request.merge_error).to include('Something went wrong during merge') expect(merge_request.merge_error).to include('Something went wrong during merge')
expect(Rails.logger).to have_received(:error).with(a_string_matching(error_message)) expect(Gitlab::AppLogger).to have_received(:error).with(a_string_matching(error_message))
end end
it 'logs and saves error if user is not authorized' do it 'logs and saves error if user is not authorized' do
...@@ -326,7 +326,7 @@ describe MergeRequests::MergeService do ...@@ -326,7 +326,7 @@ describe MergeRequests::MergeService do
service.execute(merge_request) service.execute(merge_request)
expect(merge_request.merge_error).to include('Something went wrong during merge pre-receive hook') expect(merge_request.merge_error).to include('Something went wrong during merge pre-receive hook')
expect(Rails.logger).to have_received(:error).with(a_string_matching(error_message)) expect(Gitlab::AppLogger).to have_received(:error).with(a_string_matching(error_message))
end end
it 'logs and saves error if there is a merge conflict' do it 'logs and saves error if there is a merge conflict' do
...@@ -340,7 +340,7 @@ describe MergeRequests::MergeService do ...@@ -340,7 +340,7 @@ describe MergeRequests::MergeService do
expect(merge_request).to be_open expect(merge_request).to be_open
expect(merge_request.merge_commit_sha).to be_nil expect(merge_request.merge_commit_sha).to be_nil
expect(merge_request.merge_error).to include(error_message) expect(merge_request.merge_error).to include(error_message)
expect(Rails.logger).to have_received(:error).with(a_string_matching(error_message)) expect(Gitlab::AppLogger).to have_received(:error).with(a_string_matching(error_message))
end end
context 'when squashing' do context 'when squashing' do
...@@ -359,7 +359,7 @@ describe MergeRequests::MergeService do ...@@ -359,7 +359,7 @@ describe MergeRequests::MergeService do
expect(merge_request).to be_open expect(merge_request).to be_open
expect(merge_request.merge_commit_sha).to be_nil expect(merge_request.merge_commit_sha).to be_nil
expect(merge_request.merge_error).to include(error_message) expect(merge_request.merge_error).to include(error_message)
expect(Rails.logger).to have_received(:error).with(a_string_matching(error_message)) expect(Gitlab::AppLogger).to have_received(:error).with(a_string_matching(error_message))
end end
it 'logs and saves error if there is a squash in progress' do it 'logs and saves error if there is a squash in progress' do
...@@ -373,7 +373,7 @@ describe MergeRequests::MergeService do ...@@ -373,7 +373,7 @@ describe MergeRequests::MergeService do
expect(merge_request).to be_open expect(merge_request).to be_open
expect(merge_request.merge_commit_sha).to be_nil expect(merge_request.merge_commit_sha).to be_nil
expect(merge_request.merge_error).to include(error_message) expect(merge_request.merge_error).to include(error_message)
expect(Rails.logger).to have_received(:error).with(a_string_matching(error_message)) expect(Gitlab::AppLogger).to have_received(:error).with(a_string_matching(error_message))
end end
context 'when fast-forward merge is not allowed' do context 'when fast-forward merge is not allowed' do
...@@ -393,7 +393,7 @@ describe MergeRequests::MergeService do ...@@ -393,7 +393,7 @@ describe MergeRequests::MergeService do
expect(merge_request).to be_open expect(merge_request).to be_open
expect(merge_request.merge_commit_sha).to be_nil expect(merge_request.merge_commit_sha).to be_nil
expect(merge_request.merge_error).to include(error_message) expect(merge_request.merge_error).to include(error_message)
expect(Rails.logger).to have_received(:error).with(a_string_matching(error_message)) expect(Gitlab::AppLogger).to have_received(:error).with(a_string_matching(error_message))
end end
end end
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