debian-mirror-gitlab/app/workers/create_commit_signature_worker.rb

47 lines
1.1 KiB
Ruby
Raw Normal View History

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