debian-mirror-gitlab/app/services/files/base_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.7 KiB
Ruby
Raw Permalink Normal View History

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
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
2023-05-27 22:25:52 +05:30
last_commit_from_branch = get_last_commit_for_path(ref: @start_branch, path: path)
2018-03-17 18:26:18 +05:30
2023-05-27 22:25:52 +05:30
return false unless last_commit_from_branch
2018-03-17 18:26:18 +05:30
2023-05-27 22:25:52 +05:30
last_commit_from_commit_id = get_last_commit_for_path(ref: commit_id, path: path)
return false unless last_commit_from_commit_id
last_commit_from_branch.sha != last_commit_from_commit_id.sha
2018-03-17 18:26:18 +05:30
end
2023-03-17 16:20:25 +05:30
private
2023-05-27 22:25:52 +05:30
def get_last_commit_for_path(ref:, path:)
Gitlab::Git::Commit.last_for_path(@start_project.repository, ref, path, literal_pathspec: true)
end
2023-03-17 16:20:25 +05:30
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