2018-07-16 12:31:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-04-18 03:39:07 -04:00
|
|
|
module Commits
|
2017-04-19 20:37:44 -04:00
|
|
|
class ChangeService < Commits::CreateService
|
|
|
|
def initialize(*args)
|
|
|
|
super
|
2016-04-18 03:39:07 -04:00
|
|
|
|
|
|
|
@commit = params[:commit]
|
|
|
|
end
|
|
|
|
|
2016-09-15 10:30:27 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def commit_change(action)
|
|
|
|
raise NotImplementedError unless repository.respond_to?(action)
|
|
|
|
|
2017-09-19 13:09:10 -04:00
|
|
|
# rubocop:disable GitlabSecurity/PublicSend
|
|
|
|
message = @commit.public_send(:"#{action}_message", current_user)
|
2017-02-16 19:24:56 -05:00
|
|
|
repository.public_send(
|
|
|
|
action,
|
|
|
|
current_user,
|
|
|
|
@commit,
|
2017-04-19 20:37:44 -04:00
|
|
|
@branch_name,
|
2017-09-19 13:09:10 -04:00
|
|
|
message,
|
2017-02-16 19:24:56 -05:00
|
|
|
start_project: @start_project,
|
|
|
|
start_branch_name: @start_branch)
|
2017-09-19 13:09:10 -04:00
|
|
|
rescue Gitlab::Git::Repository::CreateTreeError
|
2018-11-06 23:18:32 -05:00
|
|
|
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."
|
2017-03-02 19:11:23 -05:00
|
|
|
raise ChangeError, error_msg
|
2016-09-15 10:30:27 -04:00
|
|
|
end
|
2016-04-18 03:39:07 -04:00
|
|
|
end
|
|
|
|
end
|