2018-11-08 19:23:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
class CreateGpgSignatureWorker
|
2018-03-17 18:26:18 +05:30
|
|
|
include ApplicationWorker
|
2017-09-10 17:25:29 +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)
|
|
|
|
# Older versions of GitPushService may push a single commit ID on the stack.
|
|
|
|
# We need this to be backwards compatible.
|
|
|
|
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|
|
|
|
|
begin
|
|
|
|
Gitlab::Gpg::Commit.new(commit).signature
|
|
|
|
rescue => e
|
|
|
|
Rails.logger.error("Failed to create signature for commit #{commit.id}. Error: #{e.message}")
|
|
|
|
end
|
|
|
|
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
|