2016-08-29 19:58:32 -04:00
|
|
|
module Files
|
|
|
|
class MultiService < Files::BaseService
|
2017-12-20 10:57:27 -05:00
|
|
|
UPDATE_FILE_ACTIONS = %w(update move delete).freeze
|
|
|
|
|
2017-04-19 20:37:44 -04:00
|
|
|
def create_commit!
|
2016-08-29 19:58:32 -04:00
|
|
|
repository.multi_action(
|
2018-01-03 20:47:25 -05:00
|
|
|
current_user,
|
2016-08-29 19:58:32 -04:00
|
|
|
message: @commit_message,
|
2017-04-19 20:37:44 -04:00
|
|
|
branch_name: @branch_name,
|
2016-08-29 19:58:32 -04:00
|
|
|
actions: params[:actions],
|
|
|
|
author_email: @author_email,
|
2016-11-14 15:02:10 -05:00
|
|
|
author_name: @author_name,
|
2017-01-06 10:29:13 -05:00
|
|
|
start_project: @start_project,
|
|
|
|
start_branch_name: @start_branch
|
2016-08-29 19:58:32 -04:00
|
|
|
)
|
2018-01-03 20:47:25 -05:00
|
|
|
rescue ArgumentError => e
|
|
|
|
raise_error(e)
|
2016-08-29 19:58:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-04-19 20:37:44 -04:00
|
|
|
def validate!
|
2016-08-29 19:58:32 -04:00
|
|
|
super
|
2017-02-24 15:11:10 -05:00
|
|
|
|
2018-01-03 20:47:25 -05:00
|
|
|
params[:actions].each { |action| validate_file_status!(action) }
|
2016-08-29 19:58:32 -04:00
|
|
|
end
|
2017-12-15 23:24:12 -05:00
|
|
|
|
2017-12-20 10:57:27 -05:00
|
|
|
def validate_file_status!(action)
|
|
|
|
return unless UPDATE_FILE_ACTIONS.include?(action[:action])
|
2017-12-15 23:24:12 -05:00
|
|
|
|
2017-12-20 10:57:27 -05:00
|
|
|
file_path = action[:previous_path] || action[:file_path]
|
2017-12-15 23:24:12 -05:00
|
|
|
|
2017-12-20 10:57:27 -05:00
|
|
|
if file_has_changed?(file_path, action[:last_commit_id])
|
|
|
|
raise_error("The file has changed since you started editing it: #{file_path}")
|
2017-12-15 23:24:12 -05:00
|
|
|
end
|
|
|
|
end
|
2016-08-29 19:58:32 -04:00
|
|
|
end
|
|
|
|
end
|