Commit a7d2ebe5 authored by Alexis Reigel's avatar Alexis Reigel

simplify fetching of commit

parent 4f7ba8f2
......@@ -5,4 +5,8 @@ class GpgSignature < ActiveRecord::Base
validates :commit_sha, presence: true
validates :project, presence: true
validates :gpg_key_primary_keyid, presence: true
def commit
project.commit(commit_sha)
end
end
......@@ -10,9 +10,7 @@ module Gitlab
.where(valid_signature: false)
.where(gpg_key_primary_keyid: @gpg_key.primary_keyid)
.find_each do |gpg_signature|
raw_commit = Gitlab::Git::Commit.find(gpg_signature.project.repository, gpg_signature.commit_sha)
commit = ::Commit.new(raw_commit, gpg_signature.project)
Gitlab::Gpg::Commit.new(commit).update_signature!(gpg_signature)
Gitlab::Gpg::Commit.new(gpg_signature.commit).update_signature!(gpg_signature)
end
end
end
......
......@@ -29,7 +29,7 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do
end
before do
allow(Gitlab::Git::Commit).to receive(:find).with(kind_of(Repository), commit_sha).and_return(raw_commit)
allow_any_instance_of(GpgSignature).to receive(:commit).and_return(commit)
end
context 'gpg signature did not have an associated gpg key' do
......
......@@ -12,4 +12,17 @@ RSpec.describe GpgSignature do
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:gpg_key_primary_keyid) }
end
describe '#commit' do
it 'fetches the commit through the project' do
commit_sha = '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33'
project = create :project
commit = create :commit, project: project
gpg_signature = create :gpg_signature, commit_sha: commit_sha
expect_any_instance_of(Project).to receive(:commit).with(commit_sha).and_return(commit)
gpg_signature.commit
end
end
end
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