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

30 lines
855 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2017-07-10 11:19:50 +00:00
class CreateGpgSignatureWorker
include ApplicationWorker
2017-07-10 11:19:50 +00:00
# rubocop: disable CodeReuse/ActiveRecord
2018-07-30 16:55:28 +00: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 16:55:28 +00:00
return if commit_shas.empty?
2017-07-10 11:19:50 +00:00
project = Project.find_by(id: project_id)
2017-07-26 14:01:24 +00:00
return unless project
2017-07-10 11:19:50 +00:00
2018-07-30 16:55:28 +00:00
commits = project.commits_by(oids: commit_shas)
2018-07-30 16:55:28 +00:00
return if commits.empty?
# This calculates and caches the signature in the database
2018-07-30 16:55:28 +00:00
commits.each do |commit|
2019-03-13 13:42:43 +00:00
Gitlab::Gpg::Commit.new(commit).signature
rescue => e
Rails.logger.error("Failed to create signature for commit #{commit.id}. Error: #{e.message}")
2018-07-30 16:55:28 +00:00
end
2017-07-10 11:19:50 +00:00
end
# rubocop: enable CodeReuse/ActiveRecord
2017-07-10 11:19:50 +00:00
end