debian-mirror-gitlab/lib/gitlab/git/tag.rb

83 lines
2.1 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Gitlab
module Git
class Tag < Ref
2018-11-08 19:23:39 +05:30
extend Gitlab::EncodingHelper
attr_reader :object_sha, :repository
MAX_TAG_MESSAGE_DISPLAY_SIZE = 10.megabytes
SERIALIZE_KEYS = %i[name target target_commit message].freeze
attr_accessor *SERIALIZE_KEYS # rubocop:disable Lint/AmbiguousOperator
class << self
def get_message(repository, tag_id)
2019-02-15 15:39:39 +05:30
BatchLoader.for(tag_id).batch(key: repository) do |tag_ids, loader, args|
get_messages(args[:key], tag_ids).each do |tag_id, message|
loader.call(tag_id, message)
2018-11-08 19:23:39 +05:30
end
end
end
def get_messages(repository, tag_ids)
repository.gitaly_ref_client.get_tag_messages(tag_ids)
end
end
def initialize(repository, raw_tag)
@repository = repository
@raw_tag = raw_tag
case raw_tag
when Hash
init_from_hash
when Gitaly::Tag
init_from_gitaly
end
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
super(repository, name, target, target_commit)
2018-11-08 19:23:39 +05:30
end
def init_from_hash
raw_tag = @raw_tag.symbolize_keys
SERIALIZE_KEYS.each do |key|
send("#{key}=", raw_tag[key]) # rubocop:disable GitlabSecurity/PublicSend
end
end
def init_from_gitaly
@name = encode!(@raw_tag.name.dup)
@target = @raw_tag.id
@message = message_from_gitaly_tag
2017-08-17 22:00:37 +05:30
2018-11-08 19:23:39 +05:30
if @raw_tag.target_commit.present?
@target_commit = Gitlab::Git::Commit.decorate(repository, @raw_tag.target_commit)
end
2017-08-17 22:00:37 +05:30
end
def message
encode! @message
end
2018-11-08 19:23:39 +05:30
private
def message_from_gitaly_tag
return @raw_tag.message.dup if full_message_fetched_from_gitaly?
if @raw_tag.message_size > MAX_TAG_MESSAGE_DISPLAY_SIZE
'--tag message is too big'
else
self.class.get_message(@repository, target)
end
end
def full_message_fetched_from_gitaly?
@raw_tag.message.bytesize == @raw_tag.message_size
end
2017-08-17 22:00:37 +05:30
end
end
end