cc12b57c3f
Previously the string was spanning multiple lines and included a needless `\n` character in the resulting error message. This change also reduces duplication by assigning two variables.
36 lines
1,012 B
Ruby
36 lines
1,012 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Commits
|
|
class ChangeService < Commits::CreateService
|
|
def initialize(*args)
|
|
super
|
|
|
|
@commit = params[:commit]
|
|
end
|
|
|
|
private
|
|
|
|
def commit_change(action)
|
|
raise NotImplementedError unless repository.respond_to?(action)
|
|
|
|
# rubocop:disable GitlabSecurity/PublicSend
|
|
message = @commit.public_send(:"#{action}_message", current_user)
|
|
repository.public_send(
|
|
action,
|
|
current_user,
|
|
@commit,
|
|
@branch_name,
|
|
message,
|
|
start_project: @start_project,
|
|
start_branch_name: @start_branch)
|
|
rescue Gitlab::Git::Repository::CreateTreeError
|
|
act = action.to_s.dasherize
|
|
type = @commit.change_type_title(current_user)
|
|
|
|
error_msg = "Sorry, we cannot #{act} this #{type} automatically. " \
|
|
"This #{type} may already have been #{act}ed, or a more recent " \
|
|
"commit may have updated some of its content."
|
|
raise ChangeError, error_msg
|
|
end
|
|
end
|
|
end
|