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

36 lines
1 KiB
Ruby
Raw 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?
@author_email = params[:author_email] || git_user&.email
@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'
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
2014-09-02 18:07:02 +05:30
end
end