Add latest changes from gitlab-org/gitlab@master
This commit is contained in:
parent
57b0826587
commit
e3a138e3b9
|
@ -3,17 +3,6 @@
|
|||
module Gitlab
|
||||
module Gpg
|
||||
class Commit < Gitlab::SignedCommit
|
||||
def signature
|
||||
super
|
||||
|
||||
return @signature if @signature
|
||||
|
||||
cached_signature = lazy_signature&.itself
|
||||
return @signature = cached_signature if cached_signature.present?
|
||||
|
||||
@signature = create_cached_signature!
|
||||
end
|
||||
|
||||
def update_signature!(cached_signature)
|
||||
using_keychain do |gpg_key|
|
||||
cached_signature.update!(attributes(gpg_key))
|
||||
|
@ -23,12 +12,8 @@ module Gitlab
|
|||
|
||||
private
|
||||
|
||||
def lazy_signature
|
||||
BatchLoader.for(@commit.sha).batch do |shas, loader|
|
||||
CommitSignatures::GpgSignature.by_commit_sha(shas).each do |signature|
|
||||
loader.call(signature.commit_sha, signature)
|
||||
end
|
||||
end
|
||||
def signature_class
|
||||
CommitSignatures::GpgSignature
|
||||
end
|
||||
|
||||
def using_keychain
|
||||
|
|
|
@ -18,7 +18,18 @@ module Gitlab
|
|||
end
|
||||
|
||||
def signature
|
||||
return unless @commit.has_signature?
|
||||
return @signature if @signature
|
||||
|
||||
cached_signature = lazy_signature&.itself
|
||||
|
||||
return @signature = cached_signature if cached_signature.present?
|
||||
|
||||
@signature = create_cached_signature!
|
||||
end
|
||||
|
||||
def update_signature!(cached_signature)
|
||||
cached_signature.update!(attributes)
|
||||
@signature = cached_signature
|
||||
end
|
||||
|
||||
def signature_text
|
||||
|
@ -32,5 +43,27 @@ module Gitlab
|
|||
@signature_data.itself ? @signature_data[1] : nil
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def signature_class
|
||||
raise NotImplementedError, '`signature_class` must be implmented by subclass`'
|
||||
end
|
||||
|
||||
def lazy_signature
|
||||
BatchLoader.for(@commit.sha).batch do |shas, loader|
|
||||
signature_class.by_commit_sha(shas).each do |signature|
|
||||
loader.call(signature.commit_sha, signature)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def create_cached_signature!
|
||||
return if attributes.nil?
|
||||
|
||||
return signature_class.new(attributes) if Gitlab::Database.read_only?
|
||||
|
||||
signature_class.safe_create!(attributes)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,30 +5,10 @@ require 'digest'
|
|||
module Gitlab
|
||||
module X509
|
||||
class Commit < Gitlab::SignedCommit
|
||||
def signature
|
||||
super
|
||||
|
||||
return @signature if @signature
|
||||
|
||||
cached_signature = lazy_signature&.itself
|
||||
return @signature = cached_signature if cached_signature.present?
|
||||
|
||||
@signature = create_cached_signature!
|
||||
end
|
||||
|
||||
def update_signature!(cached_signature)
|
||||
cached_signature.update!(attributes)
|
||||
@signature = cached_signature
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def lazy_signature
|
||||
BatchLoader.for(@commit.sha).batch do |shas, loader|
|
||||
CommitSignatures::X509CommitSignature.by_commit_sha(shas).each do |signature|
|
||||
loader.call(signature.commit_sha, signature)
|
||||
end
|
||||
end
|
||||
def signature_class
|
||||
CommitSignatures::X509CommitSignature
|
||||
end
|
||||
|
||||
def attributes
|
||||
|
@ -45,14 +25,6 @@ module Gitlab
|
|||
verification_status: signature.verification_status
|
||||
}
|
||||
end
|
||||
|
||||
def create_cached_signature!
|
||||
return if attributes.nil?
|
||||
|
||||
return CommitSignatures::X509CommitSignature.new(attributes) if Gitlab::Database.read_only?
|
||||
|
||||
CommitSignatures::X509CommitSignature.safe_create!(attributes)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue