generate gpg signature on push
This commit is contained in:
parent
4c5d4a69f0
commit
e63b693f28
5 changed files with 108 additions and 0 deletions
|
@ -56,6 +56,8 @@ class GitPushService < BaseService
|
|||
perform_housekeeping
|
||||
|
||||
update_caches
|
||||
|
||||
update_signatures
|
||||
end
|
||||
|
||||
def update_gitattributes
|
||||
|
@ -80,6 +82,12 @@ class GitPushService < BaseService
|
|||
ProjectCacheWorker.perform_async(@project.id, types, [:commit_count, :repository_size])
|
||||
end
|
||||
|
||||
def update_signatures
|
||||
@push_commits.each do |commit|
|
||||
CreateGpgSignatureWorker.perform_async(commit.sha, @project.id)
|
||||
end
|
||||
end
|
||||
|
||||
# Schedules processing of commit messages.
|
||||
def process_commit_messages
|
||||
default = is_default_branch?
|
||||
|
|
20
app/workers/create_gpg_signature_worker.rb
Normal file
20
app/workers/create_gpg_signature_worker.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
class CreateGpgSignatureWorker
|
||||
include Sidekiq::Worker
|
||||
include DedicatedSidekiqQueue
|
||||
|
||||
def perform(commit_sha, project_id)
|
||||
project = Project.find_by(id: project_id)
|
||||
|
||||
unless project
|
||||
return Rails.logger.error("CreateGpgSignatureWorker: couldn't find project with ID=#{project_id}, skipping job")
|
||||
end
|
||||
|
||||
commit = project.commit(commit_sha)
|
||||
|
||||
unless commit
|
||||
return Rails.logger.error("CreateGpgSignatureWorker: couldn't find commit with commit_sha=#{commit_sha}, skipping job")
|
||||
end
|
||||
|
||||
commit.signature
|
||||
end
|
||||
end
|
|
@ -30,6 +30,7 @@
|
|||
- [emails_on_push, 2]
|
||||
- [mailers, 2]
|
||||
- [invalid_gpg_signature_update, 2]
|
||||
- [create_gpg_signature, 2]
|
||||
- [upload_checksum, 1]
|
||||
- [use_key, 1]
|
||||
- [repository_fork, 1]
|
||||
|
|
|
@ -681,6 +681,24 @@ describe GitPushService, services: true do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#update_signatures' do
|
||||
let(:service) do
|
||||
described_class.new(
|
||||
project,
|
||||
user,
|
||||
oldrev: sample_commit.parent_id,
|
||||
newrev: sample_commit.id,
|
||||
ref: 'refs/heads/master'
|
||||
)
|
||||
end
|
||||
|
||||
it 'calls CreateGpgSignatureWorker.perform_async for each commit' do
|
||||
expect(CreateGpgSignatureWorker).to receive(:perform_async).with(sample_commit.id, project.id)
|
||||
|
||||
execute_service(project, user, @oldrev, @newrev, @ref)
|
||||
end
|
||||
end
|
||||
|
||||
def execute_service(project, user, oldrev, newrev, ref)
|
||||
service = described_class.new(project, user, oldrev: oldrev, newrev: newrev, ref: ref )
|
||||
service.execute
|
||||
|
|
61
spec/workers/create_gpg_signature_worker_spec.rb
Normal file
61
spec/workers/create_gpg_signature_worker_spec.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe CreateGpgSignatureWorker do
|
||||
context 'when GpgKey is found' do
|
||||
it 'calls Commit#signature' do
|
||||
commit_sha = '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33'
|
||||
project = create :project
|
||||
commit = instance_double(Commit)
|
||||
|
||||
allow(Project).to receive(:find_by).with(id: project.id).and_return(project)
|
||||
allow(project).to receive(:commit).with(commit_sha).and_return(commit)
|
||||
|
||||
expect(commit).to receive(:signature)
|
||||
|
||||
described_class.new.perform(commit_sha, project.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when Commit is not found' do
|
||||
let(:nonexisting_commit_sha) { 'bogus' }
|
||||
let(:project) { create :project }
|
||||
|
||||
it 'logs CreateGpgSignatureWorker process skipping' do
|
||||
expect(Rails.logger).to receive(:error)
|
||||
.with("CreateGpgSignatureWorker: couldn't find commit with commit_sha=bogus, skipping job")
|
||||
|
||||
described_class.new.perform(nonexisting_commit_sha, project.id)
|
||||
end
|
||||
|
||||
it 'does not raise errors' do
|
||||
expect { described_class.new.perform(nonexisting_commit_sha, project.id) }.not_to raise_error
|
||||
end
|
||||
|
||||
it 'does not call Commit#signature' do
|
||||
expect_any_instance_of(Commit).not_to receive(:signature)
|
||||
|
||||
described_class.new.perform(nonexisting_commit_sha, project.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when Project is not found' do
|
||||
let(:nonexisting_project_id) { -1 }
|
||||
|
||||
it 'logs CreateGpgSignatureWorker process skipping' do
|
||||
expect(Rails.logger).to receive(:error)
|
||||
.with("CreateGpgSignatureWorker: couldn't find project with ID=-1, skipping job")
|
||||
|
||||
described_class.new.perform(anything, nonexisting_project_id)
|
||||
end
|
||||
|
||||
it 'does not raise errors' do
|
||||
expect { described_class.new.perform(anything, nonexisting_project_id) }.not_to raise_error
|
||||
end
|
||||
|
||||
it 'does not call Commit#signature' do
|
||||
expect_any_instance_of(Commit).not_to receive(:signature)
|
||||
|
||||
described_class.new.perform(anything, nonexisting_project_id)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue