2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
module Files
|
2017-08-17 22:00:37 +05:30
|
|
|
class BaseService < Commits::CreateService
|
2018-03-17 18:26:18 +05:30
|
|
|
FileChangedError = Class.new(StandardError)
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def initialize(*args)
|
|
|
|
super
|
2016-01-14 18:37:52 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
git_user = Gitlab::Git::User.from_gitlab(current_user) if current_user.present?
|
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
@author_email = commit_email(git_user)
|
2018-12-05 23:21:45 +05:30
|
|
|
@author_name = params[:author_name] || git_user&.name
|
2015-09-25 12:07:36 +05:30
|
|
|
@commit_message = params[:commit_message]
|
2018-03-17 18:26:18 +05:30
|
|
|
@last_commit_sha = params[:last_commit_sha]
|
2015-09-25 12:07:36 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
@file_path = params[:file_path]
|
|
|
|
@previous_path = params[:previous_path]
|
2015-09-25 12:07:36 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
@file_content = params[:file_content]
|
|
|
|
@file_content = Base64.decode64(@file_content) if params[:file_content_encoding] == 'base64'
|
2022-06-21 17:19:12 +05:30
|
|
|
|
|
|
|
@execute_filemode = params[:execute_filemode]
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def file_has_changed?(path, commit_id)
|
|
|
|
return false unless commit_id
|
|
|
|
|
|
|
|
last_commit = Gitlab::Git::Commit
|
2020-07-28 23:09:34 +05:30
|
|
|
.last_for_path(@start_project.repository, @start_branch, path, literal_pathspec: true)
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
return false unless last_commit
|
|
|
|
|
|
|
|
last_commit.sha != commit_id
|
|
|
|
end
|
2023-03-17 16:20:25 +05:30
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def commit_email(git_user)
|
|
|
|
return params[:author_email] if params[:author_email].present?
|
|
|
|
return unless current_user
|
|
|
|
|
|
|
|
namespace_commit_email = current_user.namespace_commit_email_for_project(@start_project)
|
|
|
|
|
|
|
|
return namespace_commit_email.email.email if namespace_commit_email
|
|
|
|
|
|
|
|
git_user.email
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|