2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
module Commits
|
2017-08-17 22:00:37 +05:30
|
|
|
class ChangeService < Commits::CreateService
|
|
|
|
def initialize(*args)
|
|
|
|
super
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
@commit = params[:commit]
|
2021-09-04 01:27:46 +05:30
|
|
|
@message = params[:message]
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def commit_change(action)
|
|
|
|
raise NotImplementedError unless repository.respond_to?(action)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
# rubocop:disable GitlabSecurity/PublicSend
|
2021-09-04 01:27:46 +05:30
|
|
|
message =
|
|
|
|
@message || @commit.public_send(:"#{action}_message", current_user)
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
repository.public_send(
|
|
|
|
action,
|
|
|
|
current_user,
|
|
|
|
@commit,
|
|
|
|
@branch_name,
|
2018-03-17 18:26:18 +05:30
|
|
|
message,
|
2017-08-17 22:00:37 +05:30
|
|
|
start_project: @start_project,
|
2020-10-24 23:57:45 +05:30
|
|
|
start_branch_name: @start_branch,
|
|
|
|
dry_run: @dry_run
|
|
|
|
)
|
2019-12-26 22:10:19 +05:30
|
|
|
rescue Gitlab::Git::Repository::CreateTreeError => ex
|
2018-12-13 13:39:08 +05:30
|
|
|
type = @commit.change_type_title(current_user)
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
status = case [type, action]
|
|
|
|
when ['commit', :cherry_pick]
|
|
|
|
s_("MergeRequests|Commit cherry-pick failed")
|
|
|
|
when ['commit', :revert]
|
|
|
|
s_("MergeRequests|Commit revert failed")
|
|
|
|
when ['merge request', :cherry_pick]
|
|
|
|
s_("MergeRequests|Merge request cherry-pick failed")
|
|
|
|
when ['merge request', :revert]
|
|
|
|
s_("MergeRequests|Merge request revert failed")
|
|
|
|
end
|
|
|
|
|
|
|
|
detail = s_("MergeRequests|Can't perform this action automatically. " \
|
|
|
|
"It may have already been done, or a more recent commit may have updated some of this content. " \
|
|
|
|
"Please perform this action locally.")
|
|
|
|
|
|
|
|
error_msg = "#{status}: #{detail}"
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
raise ChangeError.new(error_msg, ex.error_code)
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|