debian-mirror-gitlab/app/services/commits/change_service.rb

37 lines
1,012 B
Ruby
Raw Normal View History

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]
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
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,
start_branch_name: @start_branch)
2018-03-17 18:26:18 +05:30
rescue Gitlab::Git::Repository::CreateTreeError
2018-12-13 13:39:08 +05:30
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-08-17 22:00:37 +05:30
raise ChangeError, error_msg
2016-06-02 11:05:42 +05:30
end
end
end