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

38 lines
1.1 KiB
Ruby
Raw Normal View History

2018-11-08 19:23:39 +05:30
# frozen_string_literal: true
2020-04-08 14:13:33 +05:30
class CreateCommitSignatureWorker # rubocop:disable Scalability/IdempotentWorker
2018-03-17 18:26:18 +05:30
include ApplicationWorker
2017-09-10 17:25:29 +05:30
2019-12-21 20:55:43 +05:30
feature_category :source_code_management
2020-03-09 13:42:32 +05:30
weight 2
2019-12-21 20:55:43 +05:30
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
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?
2017-09-10 17:25:29 +05:30
project = Project.find_by(id: project_id)
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
2017-09-10 17:25:29 +05:30
# This calculates and caches the signature in the database
2018-11-18 11:00:15 +05:30
commits.each do |commit|
2020-03-09 13:42:32 +05:30
case commit.signature_type
when :PGP
Gitlab::Gpg::Commit.new(commit).signature
when :X509
Gitlab::X509::Commit.new(commit).signature
end
2019-07-07 11:18:12 +05:30
rescue => e
2019-09-30 21:07:59 +05:30
Rails.logger.error("Failed to create signature for commit #{commit.id}. Error: #{e.message}") # rubocop:disable Gitlab/RailsLogger
2018-11-18 11:00:15 +05:30
end
2017-09-10 17:25:29 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2017-09-10 17:25:29 +05:30
end