Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-12-13 15:12:59 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-12-13 15:12:59 +0300
commitb0891151f160d287e48a5317d3152b195ef950ae (patch)
tree88070363b2f28de0dfb3b0bdf77d71e9fa228e54 /app/models/commit_signatures/gpg_signature.rb
parent9bc96aa4f94943af9972ca7058ed31771bbcaa53 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/commit_signatures/gpg_signature.rb')
-rw-r--r--app/models/commit_signatures/gpg_signature.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/app/models/commit_signatures/gpg_signature.rb b/app/models/commit_signatures/gpg_signature.rb
new file mode 100644
index 00000000000..1ce76b53da4
--- /dev/null
+++ b/app/models/commit_signatures/gpg_signature.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+module CommitSignatures
+ class GpgSignature < ApplicationRecord
+ include CommitSignature
+
+ sha_attribute :gpg_key_primary_keyid
+
+ belongs_to :gpg_key
+ belongs_to :gpg_key_subkey
+
+ validates :gpg_key_primary_keyid, presence: true
+
+ def self.with_key_and_subkeys(gpg_key)
+ subkey_ids = gpg_key.subkeys.pluck(:id)
+
+ where(
+ arel_table[:gpg_key_id].eq(gpg_key.id).or(
+ arel_table[:gpg_key_subkey_id].in(subkey_ids)
+ )
+ )
+ end
+
+ def gpg_key=(model)
+ case model
+ when GpgKey
+ super
+ when GpgKeySubkey
+ self.gpg_key_subkey = model
+ when NilClass
+ super
+ self.gpg_key_subkey = nil
+ end
+ end
+
+ def gpg_key
+ if gpg_key_id
+ super
+ elsif gpg_key_subkey_id
+ gpg_key_subkey
+ end
+ end
+
+ def gpg_key_primary_keyid
+ super&.upcase
+ end
+
+ def gpg_commit
+ return unless commit
+
+ Gitlab::Gpg::Commit.new(commit)
+ end
+ end
+end