diff --git a/app/services/security/ci_configuration/base_create_service.rb b/app/services/security/ci_configuration/base_create_service.rb index 3e8865d3dfffde768ae14978ffac4de587d3fe3f..c5fbabf487c493db446d9651a81407c3f77a4019 100644 --- a/app/services/security/ci_configuration/base_create_service.rb +++ b/app/services/security/ci_configuration/base_create_service.rb @@ -51,7 +51,7 @@ def attributes end def existing_gitlab_ci_content - root_ref = root_ref_sha(project) + root_ref = root_ref_sha(project.repository) return if root_ref.nil? @gitlab_ci_yml ||= project.ci_config_for(root_ref) @@ -82,13 +82,10 @@ def track_event(attributes_for_commit) ) end - def root_ref_sha(project) - project.repository.root_ref_sha - rescue StandardError => e - # this might fail on the very first commit, - # and unfortunately it raises a StandardError - Gitlab::ErrorTracking.track_exception(e, project_id: project.id) - nil + def root_ref_sha(repository) + commit = repository.commit(repository.root_ref) + + commit&.sha end end end diff --git a/spec/support/shared_examples/services/security/ci_configuration/create_service_shared_examples.rb b/spec/support/shared_examples/services/security/ci_configuration/create_service_shared_examples.rb index 209be09c807fdd73641c2e591418f8c004e01f1c..8bfe57f45496ae7b65aafc36c5da667513bab8e3 100644 --- a/spec/support/shared_examples/services/security/ci_configuration/create_service_shared_examples.rb +++ b/spec/support/shared_examples/services/security/ci_configuration/create_service_shared_examples.rb @@ -145,7 +145,7 @@ let_it_be(:repository) { project.repository } it 'is successful' do - expect(repository).to receive(:root_ref_sha).and_raise(StandardError) + expect(repository).to receive(:commit).and_return(nil) expect(result.status).to eq(:success) end end