Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
318cbb34
Commit
318cbb34
authored
Jun 16, 2021
by
Stan Hu
Committed by
Fabio Pitino
Jun 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix new users receiving a failed pipeline warning without CI YAML
parent
49e51d0c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
145 additions
and
58 deletions
+145
-58
app/services/ci/create_pipeline_service.rb
app/services/ci/create_pipeline_service.rb
+1
-0
ee/lib/ee/gitlab/ci/pipeline/chain/validate/abilities.rb
ee/lib/ee/gitlab/ci/pipeline/chain/validate/abilities.rb
+0
-11
ee/lib/ee/gitlab/ci/pipeline/chain/validate/after_config.rb
ee/lib/ee/gitlab/ci/pipeline/chain/validate/after_config.rb
+33
-0
ee/spec/lib/ee/gitlab/ci/pipeline/chain/validate/abilities_spec.rb
...ib/ee/gitlab/ci/pipeline/chain/validate/abilities_spec.rb
+0
-47
ee/spec/lib/ee/gitlab/ci/pipeline/chain/validate/after_config_spec.rb
...ee/gitlab/ci/pipeline/chain/validate/after_config_spec.rb
+75
-0
ee/spec/services/ci/create_pipeline_service_spec.rb
ee/spec/services/ci/create_pipeline_service_spec.rb
+12
-0
lib/gitlab/ci/pipeline/chain/validate/after_config.rb
lib/gitlab/ci/pipeline/chain/validate/after_config.rb
+24
-0
No files found.
app/services/ci/create_pipeline_service.rb
View file @
318cbb34
...
...
@@ -13,6 +13,7 @@ module Ci
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Validate
::
SecurityOrchestrationPolicy
,
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Config
::
Content
,
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Config
::
Process
,
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Validate
::
AfterConfig
,
Gitlab
::
Ci
::
Pipeline
::
Chain
::
RemoveUnwantedChatJobs
,
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Skip
,
Gitlab
::
Ci
::
Pipeline
::
Chain
::
SeedBlock
,
...
...
ee/lib/ee/gitlab/ci/pipeline/chain/validate/abilities.rb
View file @
318cbb34
...
...
@@ -18,17 +18,6 @@ module EE
return
error
(
'Pipeline is disabled for mirror updates'
)
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
end
end
...
...
ee/lib/ee/gitlab/ci/pipeline/chain/validate/after_config.rb
0 → 100644
View file @
318cbb34
# 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
ee/spec/lib/ee/gitlab/ci/pipeline/chain/validate/abilities_spec.rb
View file @
318cbb34
...
...
@@ -39,52 +39,5 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::Abilities do
.
to
include
(
'Pipeline is disabled for mirror updates'
)
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
ee/spec/lib/ee/gitlab/ci/pipeline/chain/validate/after_config_spec.rb
0 → 100644
View file @
318cbb34
# 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
ee/spec/services/ci/create_pipeline_service_spec.rb
View file @
318cbb34
...
...
@@ -206,6 +206,18 @@ RSpec.describe Ci::CreatePipelineService, '#execute' do
expect
(
pipeline
.
failure_reason
).
to
eq
(
'user_not_verified'
)
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
before
do
stub_feature_flags
(
ci_require_credit_card_on_free_plan:
false
)
...
...
lib/gitlab/ci/pipeline/chain/validate/after_config.rb
0 → 100644
View file @
318cbb34
# 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'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment