Commit b841f858 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch...

Merge branch '10361-disable-pull-mirroring-for-private-projects-without-a-premium-silver-subscription-on-march-22' into 'master'

Disable free CI/CD for GitHub for private projects without a paid subscription on March 22

See merge request gitlab-org/gitlab!26170
parents e0d5a134 295381c5
...@@ -199,7 +199,7 @@ module EE ...@@ -199,7 +199,7 @@ module EE
end end
def feature_available_in_plan?(feature) 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 available_features = strong_memoize(:features_available_in_plan) do
Hash.new do |h, f| Hash.new do |h, f|
......
...@@ -318,6 +318,12 @@ module EE ...@@ -318,6 +318,12 @@ module EE
feature_available?(:code_owner_approval_required) feature_available?(:code_owner_approval_required)
end 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? def scoped_approval_rules_enabled?
::Feature.enabled?(:scoped_approval_rules, self, default_enabled: true) ::Feature.enabled?(:scoped_approval_rules, self, default_enabled: true)
end end
......
...@@ -284,6 +284,12 @@ class License < ApplicationRecord ...@@ -284,6 +284,12 @@ class License < ApplicationRecord
def trial_ends_on def trial_ends_on
Gitlab::CurrentSettings.license_trial_ends_on Gitlab::CurrentSettings.license_trial_ends_on
end 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 end
def data_filename def data_filename
......
...@@ -11,7 +11,7 @@ class ProcessGithubPullRequestEventService < ::BaseService ...@@ -11,7 +11,7 @@ class ProcessGithubPullRequestEventService < ::BaseService
}.freeze }.freeze
def execute(webhook_params) def execute(webhook_params)
return unless project.mirror? return unless project.github_external_pull_request_pipelines_available?
params = params_from_webhook(webhook_params) params = params_from_webhook(webhook_params)
return unless params[:status] return unless params[:status]
......
...@@ -711,6 +711,32 @@ describe License do ...@@ -711,6 +711,32 @@ describe License do
end end
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) def set_restrictions(opts)
gl_license.restrictions = { gl_license.restrictions = {
active_user_count: opts[:restricted_user_count], active_user_count: opts[:restricted_user_count],
......
...@@ -76,6 +76,10 @@ describe API::ProjectMirror do ...@@ -76,6 +76,10 @@ describe API::ProjectMirror do
} }
end end
before do
stub_licensed_features(ci_cd_projects: true, github_project_service_integration: true)
end
it 'triggers a pipeline for pull request' do it 'triggers a pipeline for pull request' do
expect(Ci::CreatePipelineService) expect(Ci::CreatePipelineService)
.to receive(:new) .to receive(:new)
...@@ -133,6 +137,30 @@ describe API::ProjectMirror do ...@@ -133,6 +137,30 @@ describe API::ProjectMirror do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
end end
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 end
context 'when "push" event is received' do context 'when "push" event is received' do
...@@ -263,6 +291,24 @@ describe API::ProjectMirror do ...@@ -263,6 +291,24 @@ describe API::ProjectMirror do
end end
end 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 end
def project_member(role, user) def project_member(role, user)
......
...@@ -28,6 +28,10 @@ describe ProcessGithubPullRequestEventService do ...@@ -28,6 +28,10 @@ describe ProcessGithubPullRequestEventService do
subject { described_class.new(project, user) } subject { described_class.new(project, user) }
describe '#execute' do 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 context 'when project is not a mirror' do
let(:source_branch) { double } let(:source_branch) { double }
let(:source_sha) { double } let(:source_sha) { double }
...@@ -155,5 +159,20 @@ describe ProcessGithubPullRequestEventService do ...@@ -155,5 +159,20 @@ describe ProcessGithubPullRequestEventService do
end end
end 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
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