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-08-10 12:39:26 -04:00
# rubocop:disable GitlabSecurity/PublicSend
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
2017-03-02 19:11:23 -05:00
error_msg = " Sorry, we cannot #{ action . to_s . dasherize } this #{ @commit . change_type_title ( current_user ) } automatically.
2017-04-19 20:37:44 -04:00
This #{@commit.change_type_title(current_user)} may already have been #{action.to_s.dasherize}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