Skip to content
Snippets Groups Projects
Commit fa0b4321 authored by Etienne Baqué's avatar Etienne Baqué Committed by Shinya Maeda
Browse files

Added validation to AfterCreateService

Removed previous solution for this MR.
Set up call to Sentry when validation fails in service.
parent b7fa9dc4
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -135,7 +135,7 @@ def last?
end
 
def create_ref
project.repository.create_ref(ref, ref_path)
project.repository.create_ref(sha, ref_path)
end
 
def invalidate_cache
Loading
Loading
@@ -280,12 +280,12 @@ def valid_ref
errors.add(:ref, _('The branch or tag does not exist'))
end
 
private
def ref_path
File.join(environment.ref_path, 'deployments', iid.to_s)
end
 
private
def legacy_finished_at
self.created_at if success? && !read_attribute(:finished_at)
end
Loading
Loading
Loading
Loading
@@ -193,15 +193,6 @@ def update_merge_request_metrics?
folder_name == "production"
end
 
def first_deployment_for(commit_sha)
ref = project.repository.ref_name_for_sha(ref_path, commit_sha)
return unless ref
deployment_iid = ref.split('/').last
deployments.find_by(iid: deployment_iid)
end
def ref_path
"refs/#{Repository::REF_ENVIRONMENTS}/#{slug}"
end
Loading
Loading
---
title: Use of sha instead of ref when creating a new ref on deployment creation.
merge_request: 23170
author:
type: fixed
Loading
Loading
@@ -520,6 +520,21 @@
end
end
 
describe '#create_ref' do
let(:deployment) { build(:deployment) }
subject { deployment.create_ref }
it 'creates a ref using the sha' do
expect(deployment.project.repository).to receive(:create_ref).with(
deployment.sha,
"refs/environments/#{deployment.environment.name}/deployments/#{deployment.iid}"
)
subject
end
end
describe '#playable_build' do
subject { deployment.playable_build }
 
Loading
Loading
Loading
Loading
@@ -325,26 +325,6 @@
end
end
 
describe '#first_deployment_for' do
let(:project) { create(:project, :repository) }
let!(:deployment) { create(:deployment, :succeed, environment: environment, ref: commit.parent.id) }
let!(:deployment1) { create(:deployment, :succeed, environment: environment, ref: commit.id) }
let(:head_commit) { project.commit }
let(:commit) { project.commit.parent }
it 'returns deployment id for the environment', :sidekiq_might_not_need_inline do
expect(environment.first_deployment_for(commit.id)).to eq deployment1
end
it 'return nil when no deployment is found' do
expect(environment.first_deployment_for(head_commit.id)).to eq nil
end
it 'returns a UTF-8 ref', :sidekiq_might_not_need_inline do
expect(environment.first_deployment_for(commit.id).ref).to be_utf8
end
end
describe '#environment_type' do
subject { environment.environment_type }
 
Loading
Loading
Loading
Loading
@@ -49,7 +49,7 @@
it 'creates ref' do
expect_any_instance_of(Repository)
.to receive(:create_ref)
.with(deployment.ref, deployment.send(:ref_path))
.with(deployment.sha, deployment.send(:ref_path))
 
service.execute
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment