Commit bed2cfac authored by Avielle Wolfe's avatar Avielle Wolfe Committed by Fabio Pitino

Add #force_cost_factor? method to Project

parent c117b51b
......@@ -13,6 +13,7 @@ module EE
include IgnorableColumns
GIT_LFS_DOWNLOAD_OPERATION = 'download'
PUBLIC_COST_FACTOR_RELEASE_DAY = Date.new(2021, 7, 17).freeze
prepended do
include Elastic::ProjectsSearch
......@@ -827,6 +828,12 @@ module EE
ci_cd_settings.auto_rollback_enabled?
end
def force_cost_factor?
::Gitlab.com? && public? &&
::Feature.enabled?(:ci_minutes_public_project_cost_factor, self, default_enabled: :yaml) &&
namespace.created_at >= PUBLIC_COST_FACTOR_RELEASE_DAY
end
private
def github_integration_enabled?
......
---
name: ci_minutes_public_project_cost_factor
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/65155
rollout_issue_url:
milestone: '14.1'
type: development
group: group::pipeline execution
default_enabled: true
......@@ -2947,4 +2947,67 @@ RSpec.describe Project do
end
end
end
describe '#force_cost_factor?' do
context 'on gitlab.com' do
context 'when public' do
context 'when ci_minutes_public_project_cost_factor is enabled' do
context 'when in a namespace created after 17 July, 2021' do
it 'returns true' do
stub_feature_flags(ci_minutes_public_project_cost_factor: true)
allow(::Gitlab).to receive(:com?).and_return(true)
namespace = build(:group, created_at: Date.new(2021, 7, 17))
project = build(:project, :public, namespace: namespace)
expect(project.force_cost_factor?).to be_truthy
end
end
context 'when in a namespace created before 17 July, 2021' do
it 'returns false' do
stub_feature_flags(ci_minutes_public_project_cost_factor: true)
allow(::Gitlab).to receive(:com?).and_return(true)
namespace = build(:group, created_at: Date.new(2021, 7, 16))
project = build(:project, :public, namespace: namespace)
expect(project.force_cost_factor?).to be_falsy
end
end
end
context 'when ci_minutes_public_project_cost_factor is disabled' do
it 'returns false' do
stub_feature_flags(ci_minutes_public_project_cost_factor: false)
allow(::Gitlab).to receive(:com?).and_return(true)
namespace = build(:group, created_at: Date.new(2021, 7, 16))
project = build(:project, :public, namespace: namespace)
expect(project.force_cost_factor?).to be_falsy
end
end
end
context 'when not public' do
it 'returns false' do
stub_feature_flags(ci_minutes_public_project_cost_factor: true)
allow(::Gitlab).to receive(:com?).and_return(true)
namespace = build(:group, created_at: Date.new(2021, 7, 17))
project = build(:project, :private, namespace: namespace)
expect(project.force_cost_factor?).to be_falsy
end
end
end
context 'when not on gitlab.com' do
it 'returns false' do
stub_feature_flags(ci_minutes_public_project_cost_factor: true)
allow(::Gitlab).to receive(:com?).and_return(false)
namespace = build(:group, created_at: Date.new(2021, 7, 17))
project = build(:project, :public, namespace: namespace)
expect(project.force_cost_factor?).to be_falsy
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment