2018-07-16 12:31:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-11-05 05:06:52 -05:00
|
|
|
module Files
|
2017-04-19 20:37:44 -04:00
|
|
|
class BaseService < Commits::CreateService
|
2017-12-20 10:57:27 -05:00
|
|
|
FileChangedError = Class.new(StandardError)
|
|
|
|
|
2017-04-19 20:37:44 -04:00
|
|
|
def initialize(*args)
|
|
|
|
super
|
2015-12-18 04:03:34 -05:00
|
|
|
|
2018-09-17 09:14:58 -04:00
|
|
|
git_user = Gitlab::Git::User.from_gitlab(current_user) if current_user.present?
|
|
|
|
|
|
|
|
@author_email = params[:author_email] || git_user&.email
|
|
|
|
@author_name = params[:author_name] || git_user&.name
|
2015-08-11 08:33:31 -04:00
|
|
|
@commit_message = params[:commit_message]
|
2017-12-20 10:57:27 -05:00
|
|
|
@last_commit_sha = params[:last_commit_sha]
|
2015-08-11 08:33:31 -04:00
|
|
|
|
2017-04-19 20:37:44 -04:00
|
|
|
@file_path = params[:file_path]
|
|
|
|
@previous_path = params[:previous_path]
|
2015-08-11 08:33:31 -04:00
|
|
|
|
2017-04-19 20:37:44 -04:00
|
|
|
@file_content = params[:file_content]
|
|
|
|
@file_content = Base64.decode64(@file_content) if params[:file_content_encoding] == 'base64'
|
2015-08-11 04:28:42 -04:00
|
|
|
end
|
2017-12-20 10:57:27 -05:00
|
|
|
|
|
|
|
def file_has_changed?(path, commit_id)
|
|
|
|
return false unless commit_id
|
|
|
|
|
|
|
|
last_commit = Gitlab::Git::Commit
|
|
|
|
.last_for_path(@start_project.repository, @start_branch, path)
|
|
|
|
|
|
|
|
return false unless last_commit
|
|
|
|
|
|
|
|
last_commit.sha != commit_id
|
|
|
|
end
|
2013-11-05 05:06:52 -05:00
|
|
|
end
|
|
|
|
end
|