Class: Gitlab::Git::Tag

Inherits:
Ref
  • Object
show all
Extended by:
EncodingHelper
Defined in:
lib/gitlab/git/tag.rb

Constant Summary collapse

MAX_TAG_MESSAGE_DISPLAY_SIZE =
10.megabytes
SERIALIZE_KEYS =
%i[name target target_commit message].freeze

Constants included from EncodingHelper

EncodingHelper::ENCODING_CONFIDENCE_THRESHOLD

Instance Attribute Summary collapse

Attributes inherited from Ref

#dereferenced_target, #name, #target

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EncodingHelper

binary_io, detect_binary?, detect_libgit2_binary?, encode!, encode_binary, encode_utf8

Methods inherited from Ref

extract_branch_name

Methods included from RuggedImpl::Ref

dereference_object

Constructor Details

#initialize(repository, raw_tag) ⇒ Tag

Returns a new instance of Tag.


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gitlab/git/tag.rb', line 29

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

  super(repository, name, target, target_commit)
end

Instance Attribute Details

#object_shaObject (readonly)

Returns the value of attribute object_sha


8
9
10
# File 'lib/gitlab/git/tag.rb', line 8

def object_sha
  @object_sha
end

#repositoryObject (readonly)

Returns the value of attribute repository


8
9
10
# File 'lib/gitlab/git/tag.rb', line 8

def repository
  @repository
end

Class Method Details

.get_message(repository, tag_id) ⇒ Object


16
17
18
19
20
21
22
# File 'lib/gitlab/git/tag.rb', line 16

def get_message(repository, tag_id)
  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)
    end
  end
end

.get_messages(repository, tag_ids) ⇒ Object


24
25
26
# File 'lib/gitlab/git/tag.rb', line 24

def get_messages(repository, tag_ids)
  repository.gitaly_ref_client.get_tag_messages(tag_ids)
end

Instance Method Details

#has_signature?Boolean

Returns:

  • (Boolean)

69
70
71
# File 'lib/gitlab/git/tag.rb', line 69

def has_signature?
  signature_type != :NONE
end

#init_from_gitalyObject


51
52
53
54
55
56
57
58
59
# File 'lib/gitlab/git/tag.rb', line 51

def init_from_gitaly
  @name = encode!(@raw_tag.name.dup)
  @target = @raw_tag.id
  @message = message_from_gitaly_tag

  if @raw_tag.target_commit.present?
    @target_commit = Gitlab::Git::Commit.decorate(repository, @raw_tag.target_commit)
  end
end

#init_from_hashObject


43
44
45
46
47
48
49
# File 'lib/gitlab/git/tag.rb', line 43

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

#messageObject


61
62
63
# File 'lib/gitlab/git/tag.rb', line 61

def message
  encode! @message
end

#signatureObject


77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/gitlab/git/tag.rb', line 77

def signature
  return unless has_signature?

  case signature_type
  when :PGP
    nil # not implemented, see https://gitlab.com/gitlab-org/gitlab/issues/19260
  when :X509
    X509::Tag.new(@raw_tag).signature
  else
    nil
  end
end

#signature_typeObject


73
74
75
# File 'lib/gitlab/git/tag.rb', line 73

def signature_type
  @raw_tag.signature_type || :NONE
end

#taggerObject


65
66
67
# File 'lib/gitlab/git/tag.rb', line 65

def tagger
  @raw_tag.tagger
end