debian-mirror-gitlab/app/models/concerns/commit_signature.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.2 KiB
Ruby
Raw Normal View History

2022-01-26 12:08:38 +05:30
# frozen_string_literal: true
module CommitSignature
extend ActiveSupport::Concern
included do
include ShaAttribute
2023-04-23 21:23:45 +05:30
include EachBatch
2022-01-26 12:08:38 +05:30
sha_attribute :commit_sha
enum verification_status: {
unverified: 0,
verified: 1,
same_user_different_email: 2,
other_user: 3,
unverified_key: 4,
unknown_key: 5,
2023-04-23 21:23:45 +05:30
multiple_signatures: 6,
revoked_key: 7
2022-01-26 12:08:38 +05:30
}
belongs_to :project, class_name: 'Project', foreign_key: 'project_id', optional: false
validates :commit_sha, presence: true
validates :project_id, presence: true
scope :by_commit_sha, ->(shas) { where(commit_sha: shas) }
end
class_methods do
def safe_create!(attributes)
create_with(attributes)
.safe_find_or_create_by!(commit_sha: attributes[:commit_sha])
end
# Find commits that are lacking a signature in the database at present
def unsigned_commit_shas(commit_shas)
return [] if commit_shas.empty?
signed = by_commit_sha(commit_shas).pluck(:commit_sha)
commit_shas - signed
end
end
def commit
project.commit(commit_sha)
end
2023-03-04 22:38:38 +05:30
def signed_by_user
raise NoMethodError, 'must implement `signed_by_user` method'
2022-01-26 12:08:38 +05:30
end
end