Commit 295381c5 authored by Marius Bobin's avatar Marius Bobin

Add feature flag to disable CI/CD for GitHub

Feature flag name: free_period_for_pull_mirroring

To disable free CI/CD for GitHub for private projects without a
paid subscription we need to turn off the feature flag.

Also adds more checks and specs for licensed features
parent 89cc37a4
......@@ -199,7 +199,7 @@ module EE
end
def feature_available_in_plan?(feature)
return true if ::License::ANY_PLAN_FEATURES.include?(feature)
return true if ::License.promo_feature_available?(feature)
available_features = strong_memoize(:features_available_in_plan) do
Hash.new do |h, f|
......
......@@ -318,6 +318,12 @@ module EE
feature_available?(:code_owner_approval_required)
end
def github_external_pull_request_pipelines_available?
mirror? &&
feature_available?(:ci_cd_projects) &&
feature_available?(:github_project_service_integration)
end
def scoped_approval_rules_enabled?
::Feature.enabled?(:scoped_approval_rules, self, default_enabled: true)
end
......
......@@ -284,6 +284,12 @@ class License < ApplicationRecord
def trial_ends_on
Gitlab::CurrentSettings.license_trial_ends_on
end
def promo_feature_available?(feature)
return false unless ::Feature.enabled?(:free_period_for_pull_mirroring, default_enabled: true)
ANY_PLAN_FEATURES.include?(feature)
end
end
def data_filename
......
......@@ -11,7 +11,7 @@ class ProcessGithubPullRequestEventService < ::BaseService
}.freeze
def execute(webhook_params)
return unless project.mirror?
return unless project.github_external_pull_request_pipelines_available?
params = params_from_webhook(webhook_params)
return unless params[:status]
......
......@@ -711,6 +711,32 @@ describe License do
end
end
describe '#promo_feature_available?' do
subject { described_class.promo_feature_available?(feature) }
shared_examples 'CI CD trial features' do |status|
before do
stub_feature_flags(free_period_for_pull_mirroring: status)
end
License::ANY_PLAN_FEATURES.each do |feature_name|
context "with #{feature_name}" do
let(:feature) { feature_name }
it { is_expected.to eq(status) }
end
end
end
context 'with free_period_for_pull_mirroring enabled' do
it_behaves_like 'CI CD trial features', true
end
context 'with free_period_for_pull_mirroring disabled' do
it_behaves_like 'CI CD trial features', false
end
end
def set_restrictions(opts)
gl_license.restrictions = {
active_user_count: opts[:restricted_user_count],
......
......@@ -76,6 +76,10 @@ describe API::ProjectMirror do
}
end
before do
stub_licensed_features(ci_cd_projects: true, github_project_service_integration: true)
end
it 'triggers a pipeline for pull request' do
expect(Ci::CreatePipelineService)
.to receive(:new)
......@@ -133,6 +137,30 @@ describe API::ProjectMirror do
expect(response).to have_gitlab_http_status(:ok)
end
end
context 'when ci_cd_projects is not available' do
before do
stub_licensed_features(ci_cd_projects: false, github_project_service_integration: true)
end
it 'returns the error message' do
do_post(params: params)
expect(response).to have_gitlab_http_status(:unprocessable_entity)
end
end
context 'when github_project_service_integration is not available' do
before do
stub_licensed_features(github_project_service_integration: false, ci_cd_projects: true)
end
it 'returns the error message' do
do_post(params: params)
expect(response).to have_gitlab_http_status(:unprocessable_entity)
end
end
end
context 'when "push" event is received' do
......@@ -263,6 +291,24 @@ describe API::ProjectMirror do
end
end
end
context 'when repository_mirrors feature is not available' do
before do
stub_licensed_features(repository_mirrors: false)
project_mirrored.clear_memoization(:licensed_feature_available)
end
it_behaves_like 'an API endpoint that does not trigger pull mirroring operation', :bad_request
end
context 'when repository_mirrors feature is available' do
before do
stub_licensed_features(repository_mirrors: true)
project_mirrored.clear_memoization(:licensed_feature_available)
end
it_behaves_like 'an API endpoint that triggers pull mirroring operation'
end
end
def project_member(role, user)
......
......@@ -28,6 +28,10 @@ describe ProcessGithubPullRequestEventService do
subject { described_class.new(project, user) }
describe '#execute' do
before do
stub_licensed_features(ci_cd_projects: true, github_project_service_integration: true)
end
context 'when project is not a mirror' do
let(:source_branch) { double }
let(:source_sha) { double }
......@@ -155,5 +159,20 @@ describe ProcessGithubPullRequestEventService do
end
end
end
context 'without license' do
let(:source_branch) { double }
let(:source_sha) { double }
before do
project.clear_memoization(:licensed_feature_available)
allow(project).to receive(:mirror?).and_return(true)
stub_licensed_features(ci_cd_projects: false, github_project_service_integration: false)
end
it 'does nothing' do
expect(subject.execute(params)).to be_nil
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