2018-06-27 03:23:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-10 07:19:50 -04:00
|
|
|
class CreateGpgSignatureWorker
|
2017-11-28 11:08:30 -05:00
|
|
|
include ApplicationWorker
|
2017-07-10 07:19:50 -04:00
|
|
|
|
2018-07-30 12:55:28 -04:00
|
|
|
def perform(commit_shas, project_id)
|
2018-08-02 17:22:18 -04:00
|
|
|
# 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)
|
|
|
|
|
2018-07-30 12:55:28 -04:00
|
|
|
return if commit_shas.empty?
|
|
|
|
|
2017-07-10 07:19:50 -04: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
|
|
|
|
2017-08-15 07:22:55 -04:00
|
|
|
# This calculates and caches the signature in the database
|
2018-07-30 12:55:28 -04:00
|
|
|
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-07-10 07:19:50 -04:00
|
|
|
end
|
|
|
|
end
|