diff --git a/app/serializers/build_details_entity.rb b/app/serializers/build_details_entity.rb index 30c3246b05b..f391b6f8a1b 100644 --- a/app/serializers/build_details_entity.rb +++ b/app/serializers/build_details_entity.rb @@ -13,7 +13,11 @@ class BuildDetailsEntity < JobEntity expose :deployment_status, if: -> (*) { build.starts_environment? } do expose :deployment_status, as: :status - expose :persisted_environment, as: :environment, with: EnvironmentEntity + expose :persisted_environment, as: :environment do |build, options| + options.merge(except: [{ last_deployment: [:commit] }]).yield_self do |opts| + EnvironmentEntity.represent(build.persisted_environment, opts) + end + end end expose :artifact, if: -> (*) { can?(current_user, :read_build, build) } do diff --git a/spec/controllers/projects/jobs_controller_spec.rb b/spec/controllers/projects/jobs_controller_spec.rb index f467d13cfd5..b5d85ad1bcf 100644 --- a/spec/controllers/projects/jobs_controller_spec.rb +++ b/spec/controllers/projects/jobs_controller_spec.rb @@ -269,6 +269,8 @@ def get_index(**extra_params) expect(json_response.dig('deployment_status', 'status')).to eq 'creating' expect(json_response.dig('deployment_status', 'environment')).not_to be_nil expect(json_response.dig('deployment_status', 'environment', 'last_deployment')).not_to be_nil + expect(json_response.dig('deployment_status', 'environment', 'last_deployment')) + .not_to include('commit') end end diff --git a/spec/serializers/build_details_entity_spec.rb b/spec/serializers/build_details_entity_spec.rb index 1edf69dc290..aa0db7bc326 100644 --- a/spec/serializers/build_details_entity_spec.rb +++ b/spec/serializers/build_details_entity_spec.rb @@ -122,5 +122,29 @@ it { is_expected.to include(failure_reason: 'unmet_prerequisites') } end + + context 'when a build has environment with latest deployment' do + let(:build) do + create(:ci_build, :running, environment: environment.name, pipeline: pipeline) + end + + let(:environment) do + create(:environment, project: project, name: 'staging', state: :available) + end + + before do + create(:deployment, :success, environment: environment, project: project) + + allow(request).to receive(:project).and_return(project) + end + + it 'does not serialize latest deployment commit' do + response = subject.with_indifferent_access + + response.dig(:deployment_status, :environment, :last_deployment).tap do |deployment| + expect(deployment).not_to include(:commit) + end + end + end end end