diff --git a/app/models/project_ci_cd_setting.rb b/app/models/project_ci_cd_setting.rb index 492d50766ea..821e022f51b 100644 --- a/app/models/project_ci_cd_setting.rb +++ b/app/models/project_ci_cd_setting.rb @@ -31,6 +31,8 @@ class ProjectCiCdSetting < ApplicationRecord private def set_default_git_depth + return unless Feature.enabled?(:ci_set_project_default_git_depth, default_enabled: true) + self.default_git_depth ||= DEFAULT_GIT_DEPTH end end diff --git a/app/presenters/ci/build_runner_presenter.rb b/app/presenters/ci/build_runner_presenter.rb index 471b6d3b726..c75f62149f8 100644 --- a/app/presenters/ci/build_runner_presenter.rb +++ b/app/presenters/ci/build_runner_presenter.rb @@ -27,7 +27,7 @@ module Ci def git_depth if git_depth_variable git_depth_variable[:value] - else + elsif Feature.enabled?(:ci_project_git_depth, default_enabled: true) project.default_git_depth end.to_i end diff --git a/spec/models/project_ci_cd_setting_spec.rb b/spec/models/project_ci_cd_setting_spec.rb index f596cee81dc..eb3a7e527c9 100644 --- a/spec/models/project_ci_cd_setting_spec.rb +++ b/spec/models/project_ci_cd_setting_spec.rb @@ -48,5 +48,17 @@ describe ProjectCiCdSetting do expect(project.reload.ci_cd_settings.default_git_depth).to eq(0) end + + context 'when feature flag :ci_set_project_default_git_depth is disabled' do + let(:project) { create(:project) } + + before do + stub_feature_flags(ci_set_project_default_git_depth: { enabled: false } ) + end + + it 'does not set default value for new records' do + expect(project.ci_cd_settings.default_git_depth).to eq(nil) + end + end end end diff --git a/spec/presenters/ci/build_runner_presenter_spec.rb b/spec/presenters/ci/build_runner_presenter_spec.rb index 9ed8e3a4e0a..620f34bac79 100644 --- a/spec/presenters/ci/build_runner_presenter_spec.rb +++ b/spec/presenters/ci/build_runner_presenter_spec.rb @@ -136,6 +136,16 @@ describe Ci::BuildRunnerPresenter do it 'defaults to git depth setting for the project' do expect(git_depth).to eq(build.project.default_git_depth) end + + context 'when feature flag :ci_project_git_depth is disabled' do + before do + stub_feature_flags(ci_project_git_depth: { enabled: false }) + end + + it 'defaults to 0' do + expect(git_depth).to eq(0) + end + end end describe '#refspecs' do