summaryrefslogtreecommitdiff
path: root/app/models/gpg_signature.rb
blob: 454c90d5fc4fe6512e53731d4a735fc76986f95a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class GpgSignature < ActiveRecord::Base
  include ShaAttribute
  include IgnorableColumn

  ignore_column :valid_signature

  sha_attribute :commit_sha
  sha_attribute :gpg_key_primary_keyid

  enum verification_status: {
    unverified: 0,
    verified: 1,
    same_user_different_email: 2,
    other_user: 3,
    unverified_key: 4,
    unknown_key: 5
  }

  belongs_to :project
  belongs_to :gpg_key

  validates :commit_sha, presence: true
  validates :project_id, presence: true
  validates :gpg_key_primary_keyid, presence: true

  def gpg_key_primary_keyid
    super&.upcase
  end

  def commit
    project.commit(commit_sha)
  end

  def gpg_commit
    Gitlab::Gpg::Commit.new(commit)
  end
end