Commit 318cbb34 authored by Stan Hu's avatar Stan Hu Committed by Fabio Pitino

Fix new users receiving a failed pipeline warning without CI YAML

parent 49e51d0c
...@@ -13,6 +13,7 @@ module Ci ...@@ -13,6 +13,7 @@ module Ci
Gitlab::Ci::Pipeline::Chain::Validate::SecurityOrchestrationPolicy, Gitlab::Ci::Pipeline::Chain::Validate::SecurityOrchestrationPolicy,
Gitlab::Ci::Pipeline::Chain::Config::Content, Gitlab::Ci::Pipeline::Chain::Config::Content,
Gitlab::Ci::Pipeline::Chain::Config::Process, Gitlab::Ci::Pipeline::Chain::Config::Process,
Gitlab::Ci::Pipeline::Chain::Validate::AfterConfig,
Gitlab::Ci::Pipeline::Chain::RemoveUnwantedChatJobs, Gitlab::Ci::Pipeline::Chain::RemoveUnwantedChatJobs,
Gitlab::Ci::Pipeline::Chain::Skip, Gitlab::Ci::Pipeline::Chain::Skip,
Gitlab::Ci::Pipeline::Chain::SeedBlock, Gitlab::Ci::Pipeline::Chain::SeedBlock,
......
...@@ -18,17 +18,6 @@ module EE ...@@ -18,17 +18,6 @@ module EE
return error('Pipeline is disabled for mirror updates') return error('Pipeline is disabled for mirror updates')
end end
if current_user && !current_user.has_required_credit_card_to_run_pipelines?(project)
::Gitlab::AppLogger.info(
message: 'Credit card required to be on file in order to create a pipeline',
project_path: project.full_path,
user_id: current_user.id,
plan: project.root_namespace.actual_plan_name
)
return error('Credit card required to be on file in order to create a pipeline', drop_reason: :user_not_verified)
end
super super
end end
end end
......
# frozen_string_literal: true
module EE
module Gitlab
module Ci
module Pipeline
module Chain
module Validate
module AfterConfig
extend ::Gitlab::Utils::Override
override :perform!
def perform!
if current_user && !current_user.has_required_credit_card_to_run_pipelines?(project)
::Gitlab::AppLogger.info(
message: 'Credit card required to be on file in order to create a pipeline',
project_path: project.full_path,
user_id: current_user.id,
plan: project.root_namespace.actual_plan_name
)
return error('Credit card required to be on file in order to create a pipeline', drop_reason: :user_not_verified)
end
super
end
end
end
end
end
end
end
end
...@@ -39,52 +39,5 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::Abilities do ...@@ -39,52 +39,5 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::Abilities do
.to include('Pipeline is disabled for mirror updates') .to include('Pipeline is disabled for mirror updates')
end end
end end
describe 'credit card requirement' do
context 'when user does not have credit card for pipelines in project' do
before do
allow(user)
.to receive(:has_required_credit_card_to_run_pipelines?)
.with(project)
.and_return(false)
end
it 'breaks the chain with an error' do
step.perform!
expect(step.break?).to be_truthy
expect(pipeline.errors.to_a)
.to include('Credit card required to be on file in order to create a pipeline')
end
it 'logs the event' do
allow(Gitlab).to receive(:com?).and_return(true).at_least(:once)
expect(Gitlab::AppLogger).to receive(:info).with(
message: 'Credit card required to be on file in order to create a pipeline',
project_path: project.full_path,
user_id: user.id,
plan: 'free')
step.perform!
end
end
context 'when user has credit card for pipelines in project' do
before do
allow(user)
.to receive(:has_required_credit_card_to_run_pipelines?)
.with(project)
.and_return(true)
end
it 'succeeds the step' do
step.perform!
expect(step.break?).to be_falsey
expect(pipeline.errors).to be_empty
end
end
end
end end
end end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::AfterConfig do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
let(:pipeline) do
build(:ci_pipeline, project: project)
end
let(:command) do
Gitlab::Ci::Pipeline::Chain::Command
.new(project: project, current_user: user, origin_ref: ref, save_incompleted: true)
end
let(:step) { described_class.new(pipeline, command) }
let(:ref) { 'master' }
describe '#perform!' do
before do
project.add_developer(user)
end
describe 'credit card requirement' do
context 'when user does not have credit card for pipelines in project' do
before do
allow(user)
.to receive(:has_required_credit_card_to_run_pipelines?)
.with(project)
.and_return(false)
end
it 'breaks the chain with an error' do
step.perform!
expect(step.break?).to be_truthy
expect(pipeline.errors.to_a)
.to include('Credit card required to be on file in order to create a pipeline')
expect(pipeline.failure_reason).to eq('user_not_verified')
expect(pipeline).to be_persisted # when passing a failure reason the pipeline is persisted
end
it 'logs the event' do
allow(Gitlab).to receive(:com?).and_return(true).at_least(:once)
expect(Gitlab::AppLogger).to receive(:info).with(
message: 'Credit card required to be on file in order to create a pipeline',
project_path: project.full_path,
user_id: user.id,
plan: 'free')
step.perform!
end
end
context 'when user has credit card for pipelines in project' do
before do
allow(user)
.to receive(:has_required_credit_card_to_run_pipelines?)
.with(project)
.and_return(true)
end
it 'succeeds the step' do
step.perform!
expect(step.break?).to be_falsey
expect(pipeline.errors).to be_empty
end
end
end
end
end
...@@ -206,6 +206,18 @@ RSpec.describe Ci::CreatePipelineService, '#execute' do ...@@ -206,6 +206,18 @@ RSpec.describe Ci::CreatePipelineService, '#execute' do
expect(pipeline.failure_reason).to eq('user_not_verified') expect(pipeline.failure_reason).to eq('user_not_verified')
end end
context 'when config is blank' do
before do
stub_ci_pipeline_yaml_file(nil)
end
it 'does not create a pipeline', :aggregate_failures do
pipeline = create_pipeline!
expect(pipeline).not_to be_persisted
end
end
context 'when feature flag is disabled' do context 'when feature flag is disabled' do
before do before do
stub_feature_flags(ci_require_credit_card_on_free_plan: false) stub_feature_flags(ci_require_credit_card_on_free_plan: false)
......
# frozen_string_literal: true
module Gitlab
module Ci
module Pipeline
module Chain
module Validate
class AfterConfig < Chain::Base
include Chain::Helpers
def perform!
end
def break?
@pipeline.errors.any?
end
end
end
end
end
end
end
Gitlab::Ci::Pipeline::Chain::Validate::AfterConfig.prepend_mod_with('Gitlab::Ci::Pipeline::Chain::Validate::AfterConfig')
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