2018-06-27 03:23:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-05-11 17:09:40 -04:00
|
|
|
class CreateCommitSignatureWorker
|
2017-11-28 11:08:30 -05:00
|
|
|
include ApplicationWorker
|
2017-07-10 07:19:50 -04:00
|
|
|
|
2021-07-21 08:09:35 -04:00
|
|
|
data_consistency :always
|
|
|
|
|
2021-04-30 14:10:09 -04:00
|
|
|
sidekiq_options retry: 3
|
|
|
|
|
2019-10-18 07:11:44 -04:00
|
|
|
feature_category :source_code_management
|
2020-01-24 13:09:00 -05:00
|
|
|
weight 2
|
2020-05-11 17:09:40 -04:00
|
|
|
idempotent!
|
2020-06-12 08:08:56 -04:00
|
|
|
loggable_arguments 0
|
2020-05-11 17:09:40 -04:00
|
|
|
|
2018-07-30 12:55:28 -04:00
|
|
|
def perform(commit_shas, project_id)
|
2019-03-22 13:01:48 -04:00
|
|
|
# Older versions of Git::BranchPushService may push a single commit ID on
|
|
|
|
# the stack. We need this to be backwards compatible.
|
2018-08-02 17:22:18 -04:00
|
|
|
commit_shas = Array(commit_shas)
|
|
|
|
|
2018-07-30 12:55:28 -04:00
|
|
|
return if commit_shas.empty?
|
|
|
|
|
2021-11-10 10:13:21 -05:00
|
|
|
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)
|
2017-08-24 08:21:26 -04:00
|
|
|
|
2018-07-30 12:55:28 -04:00
|
|
|
return if commits.empty?
|
2017-08-24 08:21:26 -04:00
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
# Instantiate commits first to lazily load the signatures
|
|
|
|
commits.map! do |commit|
|
2020-02-06 19:09:12 -05:00
|
|
|
case commit.signature_type
|
|
|
|
when :PGP
|
2020-04-21 11:21:10 -04:00
|
|
|
Gitlab::Gpg::Commit.new(commit)
|
2020-02-06 19:09:12 -05:00
|
|
|
when :X509
|
2020-04-21 11:21:10 -04:00
|
|
|
Gitlab::X509::Commit.new(commit)
|
2020-02-06 19:09:12 -05:00
|
|
|
end
|
2020-04-21 11:21:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# This calculates and caches the signature in the database
|
|
|
|
commits.each do |commit|
|
|
|
|
commit&.signature
|
2021-04-26 08:09:44 -04:00
|
|
|
rescue StandardError => e
|
2020-05-21 17:08:31 -04:00
|
|
|
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
|