gitlab-org--gitlab-foss/app/workers/create_commit_signature_worker.rb

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

47 lines
1.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
class CreateCommitSignatureWorker
include ApplicationWorker
2017-07-10 07:19:50 -04:00
data_consistency :always
sidekiq_options retry: 3
feature_category :source_code_management
weight 2
idempotent!
loggable_arguments 0
2018-07-30 12:55:28 -04:00
def perform(commit_shas, project_id)
# Older versions of Git::BranchPushService may push a single commit ID on
# the stack. We need this to be backwards compatible.
commit_shas = Array(commit_shas)
2018-07-30 12:55:28 -04:00
return if commit_shas.empty?
project = Project.find_by_id(project_id)
2017-07-26 10:01:24 -04:00
return unless project
2017-07-10 07:19:50 -04:00
2018-07-30 12:55:28 -04:00
commits = project.commits_by(oids: commit_shas)
2018-07-30 12:55:28 -04:00
return if commits.empty?
# Instantiate commits first to lazily load the signatures
commits.map! do |commit|
case commit.signature_type
when :PGP
Gitlab::Gpg::Commit.new(commit)
when :X509
Gitlab::X509::Commit.new(commit)
end
end
# This calculates and caches the signature in the database
commits.each do |commit|
commit&.signature
rescue StandardError => e
Gitlab::AppLogger.error("Failed to create signature for commit #{commit.id}. Error: #{e.message}")
2018-07-30 12:55:28 -04:00
end
2017-07-10 07:19:50 -04:00
end
end