diff --git a/config/feature_flags/development/ci_cost_factors_narrow_os_contribution_by_plan.yml b/config/feature_flags/development/ci_cost_factors_narrow_os_contribution_by_plan.yml new file mode 100644 index 0000000000000000000000000000000000000000..0d73e8735e9e67f12ef5b1c6ec058a0775289ffa --- /dev/null +++ b/config/feature_flags/development/ci_cost_factors_narrow_os_contribution_by_plan.yml @@ -0,0 +1,8 @@ +--- +name: ci_cost_factors_narrow_os_contribution_by_plan +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/96273 +rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/372263 +milestone: '15.4' +type: development +group: group::pipeline execution +default_enabled: false diff --git a/ee/lib/gitlab/ci/minutes/cost_factor.rb b/ee/lib/gitlab/ci/minutes/cost_factor.rb index 023ca47c497988ccd47fed3b763a1035683f2d61..17a1fc0825844aa6817f5fd3bf871afbf31f96e3 100644 --- a/ee/lib/gitlab/ci/minutes/cost_factor.rb +++ b/ee/lib/gitlab/ci/minutes/cost_factor.rb @@ -50,14 +50,21 @@ def apply_discount(project, runner_cost_factor) if project.public? cost_factors << PUBLIC_OPEN_SOURCE_PLAN if open_source_plan?(project) - cost_factors << OPEN_SOURCE_CONTRIBUTION if public_fork_source?(project) + cost_factors << OPEN_SOURCE_CONTRIBUTION if open_source_project?(project) end cost_factors.min end - def public_fork_source?(project) - project&.fork_source&.public? + def open_source_project?(project) + fork_source = project&.fork_source + public_fork = fork_source&.public? + + if Feature.enabled?(:ci_cost_factors_narrow_os_contribution_by_plan, project) + return public_fork && open_source_plan?(fork_source) + end + + public_fork end def open_source_plan?(project) diff --git a/ee/spec/lib/gitlab/ci/minutes/cost_factor_spec.rb b/ee/spec/lib/gitlab/ci/minutes/cost_factor_spec.rb index f784d2155fa384702cc5dc23565af5f69f0b0779..3878cf7c9cac5de9222eec9bc74e13215bdd1919 100644 --- a/ee/spec/lib/gitlab/ci/minutes/cost_factor_spec.rb +++ b/ee/spec/lib/gitlab/ci/minutes/cost_factor_spec.rb @@ -211,7 +211,25 @@ let(:source_visibility_level) { Gitlab::VisibilityLevel::PUBLIC } context 'when the forked source cost factor is lower' do - specify { expect(subject).to eq(described_class::OPEN_SOURCE_CONTRIBUTION) } + context 'when the forked source plan is open source' do + before do + create(:gitlab_subscription, namespace: project.fork_source.namespace, hosted_plan: create(:opensource_plan)) + end + + specify { expect(subject).to eq(described_class::OPEN_SOURCE_CONTRIBUTION) } + end + + context 'when the plan is not open source' do + specify { expect(subject).to eq(public_cost_factor) } + + context 'when the ci_cost_factors_narrow_os_contribution_by_plan flag is disabled' do + before do + stub_feature_flags(ci_cost_factors_narrow_os_contribution_by_plan: false) + end + + specify { expect(subject).to eq(described_class::OPEN_SOURCE_CONTRIBUTION) } + end + end end context 'when the runner cost factor is lower' do