Commit f6e6b920 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'sh-fix-failing-gpg-signature-ce' into 'master'

Make CreateGpgSignatureWorker backwards compatible with original method signature (CE port)

See merge request gitlab-org/gitlab-ce!20998
parents 7da6ac06 3fda119e
...@@ -4,6 +4,10 @@ class CreateGpgSignatureWorker ...@@ -4,6 +4,10 @@ class CreateGpgSignatureWorker
include ApplicationWorker include ApplicationWorker
def perform(commit_shas, project_id) 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? return if commit_shas.empty?
project = Project.find_by(id: project_id) project = Project.find_by(id: project_id)
......
...@@ -4,10 +4,9 @@ describe CreateGpgSignatureWorker do ...@@ -4,10 +4,9 @@ describe CreateGpgSignatureWorker do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:commits) { project.repository.commits('HEAD', limit: 3).commits } let(:commits) { project.repository.commits('HEAD', limit: 3).commits }
let(:commit_shas) { commits.map(&:id) } let(:commit_shas) { commits.map(&:id) }
context 'when GpgKey is found' do
let(:gpg_commit) { instance_double(Gitlab::Gpg::Commit) } let(:gpg_commit) { instance_double(Gitlab::Gpg::Commit) }
context 'when GpgKey is found' do
before do before do
allow(Project).to receive(:find_by).with(id: project.id).and_return(project) allow(Project).to receive(:find_by).with(id: project.id).and_return(project)
allow(project).to receive(:commits_by).with(oids: commit_shas).and_return(commits) allow(project).to receive(:commits_by).with(oids: commit_shas).and_return(commits)
...@@ -36,6 +35,16 @@ describe CreateGpgSignatureWorker do ...@@ -36,6 +35,16 @@ describe CreateGpgSignatureWorker do
end end
end end
context 'handles when a string is passed in for the commit SHA' do
it 'creates a signature once' do
allow(Gitlab::Gpg::Commit).to receive(:new).with(commits.first).and_return(gpg_commit)
expect(gpg_commit).to receive(:signature).once
described_class.new.perform(commit_shas.first, project.id)
end
end
context 'when Commit is not found' do context 'when Commit is not found' do
let(:nonexisting_commit_sha) { '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a34' } let(:nonexisting_commit_sha) { '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a34' }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment