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
039a46d5
Commit
039a46d5
authored
Jul 29, 2020
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move Ci::PipelineEnums to Enums::Ci::Pipeline
Move enums related modules to a separate directory
parent
7e027db6
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
136 additions
and
126 deletions
+136
-126
app/graphql/types/ci/pipeline_config_source_enum.rb
app/graphql/types/ci/pipeline_config_source_enum.rb
+1
-1
app/graphql/types/ci/pipeline_type.rb
app/graphql/types/ci/pipeline_type.rb
+1
-1
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+7
-7
app/models/ci/pipeline_enums.rb
app/models/ci/pipeline_enums.rb
+0
-73
app/models/concerns/enums/ci/pipeline.rb
app/models/concerns/enums/ci/pipeline.rb
+75
-0
doc/development/creating_enums.md
doc/development/creating_enums.md
+20
-14
ee/app/models/concerns/ee/enums/ci/pipeline.rb
ee/app/models/concerns/ee/enums/ci/pipeline.rb
+24
-0
ee/app/models/ee/ci/pipeline_enums.rb
ee/app/models/ee/ci/pipeline_enums.rb
+0
-22
spec/graphql/resolvers/project_pipeline_resolver_spec.rb
spec/graphql/resolvers/project_pipeline_resolver_spec.rb
+2
-2
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+1
-1
spec/models/ci/ref_spec.rb
spec/models/ci/ref_spec.rb
+2
-2
spec/presenters/ci/pipeline_presenter_spec.rb
spec/presenters/ci/pipeline_presenter_spec.rb
+1
-1
spec/requests/api/ci/pipelines_spec.rb
spec/requests/api/ci/pipelines_spec.rb
+1
-1
spec/requests/api/jobs_spec.rb
spec/requests/api/jobs_spec.rb
+1
-1
No files found.
app/graphql/types/ci/pipeline_config_source_enum.rb
View file @
039a46d5
...
...
@@ -3,7 +3,7 @@
module
Types
module
Ci
class
PipelineConfigSourceEnum
<
BaseEnum
::
Ci
::
PipelineEnums
.
config_sources
.
keys
.
each
do
|
state_symbol
|
::
Enums
::
Ci
::
Pipeline
.
config_sources
.
keys
.
each
do
|
state_symbol
|
value
state_symbol
.
to_s
.
upcase
,
value:
state_symbol
.
to_s
end
end
...
...
app/graphql/types/ci/pipeline_type.rb
View file @
039a46d5
...
...
@@ -26,7 +26,7 @@ module Types
description:
'Detailed status of the pipeline'
,
resolve:
->
(
obj
,
_args
,
ctx
)
{
obj
.
detailed_status
(
ctx
[
:current_user
])
}
field
:config_source
,
PipelineConfigSourceEnum
,
null:
true
,
description:
"Config source of the pipeline (
#{
::
Ci
::
PipelineEnums
.
config_sources
.
keys
.
join
(
', '
).
upcase
}
)"
description:
"Config source of the pipeline (
#{
::
Enums
::
Ci
::
Pipeline
.
config_sources
.
keys
.
join
(
', '
).
upcase
}
)"
field
:duration
,
GraphQL
::
INT_TYPE
,
null:
true
,
description:
'Duration of the pipeline in seconds'
field
:coverage
,
GraphQL
::
FLOAT_TYPE
,
null:
true
,
...
...
app/models/ci/pipeline.rb
View file @
039a46d5
...
...
@@ -104,15 +104,15 @@ module Ci
after_create
:keep_around_commits
,
unless: :importing?
# We use `
Ci::PipelineEnums
.sources` here so that EE can more easily extend
# We use `
Enums::Ci::Pipeline
.sources` here so that EE can more easily extend
# this `Hash` with new values.
enum_with_nil
source:
::
Ci
::
PipelineEnums
.
sources
enum_with_nil
source:
Enums
::
Ci
::
Pipeline
.
sources
enum_with_nil
config_source:
::
Ci
::
PipelineEnums
.
config_sources
enum_with_nil
config_source:
Enums
::
Ci
::
Pipeline
.
config_sources
# We use `
Ci::PipelineEnums
.failure_reasons` here so that EE can more easily
# We use `
Enums::Ci::Pipeline
.failure_reasons` here so that EE can more easily
# extend this `Hash` with new values.
enum
failure_reason:
::
Ci
::
PipelineEnums
.
failure_reasons
enum
failure_reason:
Enums
::
Ci
::
Pipeline
.
failure_reasons
enum
locked:
{
unlocked:
0
,
artifacts_locked:
1
}
...
...
@@ -260,7 +260,7 @@ module Ci
scope
:internal
,
->
{
where
(
source:
internal_sources
)
}
scope
:no_child
,
->
{
where
.
not
(
source: :parent_pipeline
)
}
scope
:ci_sources
,
->
{
where
(
config_source:
::
Ci
::
PipelineEnums
.
ci_config_sources_values
)
}
scope
:ci_sources
,
->
{
where
(
config_source:
Enums
::
Ci
::
Pipeline
.
ci_config_sources_values
)
}
scope
:for_user
,
->
(
user
)
{
where
(
user:
user
)
}
scope
:for_sha
,
->
(
sha
)
{
where
(
sha:
sha
)
}
scope
:for_source_sha
,
->
(
source_sha
)
{
where
(
source_sha:
source_sha
)
}
...
...
@@ -1012,7 +1012,7 @@ module Ci
end
def
cacheable?
Ci
::
PipelineEnums
.
ci_config_sources
.
key?
(
config_source
.
to_sym
)
Enums
::
Ci
::
Pipeline
.
ci_config_sources
.
key?
(
config_source
.
to_sym
)
end
def
source_ref_path
...
...
app/models/ci/pipeline_enums.rb
deleted
100644 → 0
View file @
7e027db6
# frozen_string_literal: true
module
Ci
module
PipelineEnums
# Returns the `Hash` to use for creating the `failure_reason` enum for
# `Ci::Pipeline`.
def
self
.
failure_reasons
{
unknown_failure:
0
,
config_error:
1
,
external_validation_failure:
2
}
end
# Returns the `Hash` to use for creating the `sources` enum for
# `Ci::Pipeline`.
def
self
.
sources
{
unknown:
nil
,
push:
1
,
web:
2
,
trigger:
3
,
schedule:
4
,
api:
5
,
external:
6
,
# TODO: Rename `pipeline` to `cross_project_pipeline` in 13.0
# https://gitlab.com/gitlab-org/gitlab/issues/195991
pipeline:
7
,
chat:
8
,
webide:
9
,
merge_request_event:
10
,
external_pull_request_event:
11
,
parent_pipeline:
12
,
ondemand_dast_scan:
13
}
end
# Returns the `Hash` to use for creating the `config_sources` enum for
# `Ci::Pipeline`.
def
self
.
config_sources
{
unknown_source:
nil
,
repository_source:
1
,
auto_devops_source:
2
,
webide_source:
3
,
remote_source:
4
,
external_project_source:
5
,
bridge_source:
6
,
parameter_source:
7
}
end
def
self
.
ci_config_sources
config_sources
.
slice
(
:unknown_source
,
:repository_source
,
:auto_devops_source
,
:remote_source
,
:external_project_source
)
end
def
self
.
ci_config_sources_values
ci_config_sources
.
values
end
def
self
.
non_ci_config_source_values
config_sources
.
values
-
ci_config_sources
.
values
end
end
end
Ci
::
PipelineEnums
.
prepend_if_ee
(
'EE::Ci::PipelineEnums'
)
app/models/concerns/enums/ci/pipeline.rb
0 → 100644
View file @
039a46d5
# frozen_string_literal: true
module
Enums
module
Ci
module
Pipeline
# Returns the `Hash` to use for creating the `failure_reason` enum for
# `Ci::Pipeline`.
def
self
.
failure_reasons
{
unknown_failure:
0
,
config_error:
1
,
external_validation_failure:
2
}
end
# Returns the `Hash` to use for creating the `sources` enum for
# `Ci::Pipeline`.
def
self
.
sources
{
unknown:
nil
,
push:
1
,
web:
2
,
trigger:
3
,
schedule:
4
,
api:
5
,
external:
6
,
# TODO: Rename `pipeline` to `cross_project_pipeline` in 13.0
# https://gitlab.com/gitlab-org/gitlab/issues/195991
pipeline:
7
,
chat:
8
,
webide:
9
,
merge_request_event:
10
,
external_pull_request_event:
11
,
parent_pipeline:
12
,
ondemand_dast_scan:
13
}
end
# Returns the `Hash` to use for creating the `config_sources` enum for
# `Ci::Pipeline`.
def
self
.
config_sources
{
unknown_source:
nil
,
repository_source:
1
,
auto_devops_source:
2
,
webide_source:
3
,
remote_source:
4
,
external_project_source:
5
,
bridge_source:
6
,
parameter_source:
7
}
end
def
self
.
ci_config_sources
config_sources
.
slice
(
:unknown_source
,
:repository_source
,
:auto_devops_source
,
:remote_source
,
:external_project_source
)
end
def
self
.
ci_config_sources_values
ci_config_sources
.
values
end
def
self
.
non_ci_config_source_values
config_sources
.
values
-
ci_config_sources
.
values
end
end
end
end
Enums
::
Ci
::
Pipeline
.
prepend_if_ee
(
'EE::Enums::Ci::Pipeline'
)
doc/development/creating_enums.md
View file @
039a46d5
...
...
@@ -33,28 +33,32 @@ tempted to organize the `enum` as the following:
```
ruby
# Define `failure_reason` enum in `Pipeline` model:
class
Pipeline
<
ApplicationRecord
enum
failure_reason:
::
PipelineEnums
.
failure_reasons
enum
failure_reason:
Enums
::
Pipeline
.
failure_reasons
end
```
```
ruby
# Define key/value pairs that used in FOSS and EE:
module
PipelineEnums
def
self
.
failure_reasons
{
unknown_failure:
0
,
config_error:
1
}
module
Enums
module
Pipeline
def
self
.
failure_reasons
{
unknown_failure:
0
,
config_error:
1
}
end
end
end
PipelineEnums
.
prepend_if_ee
(
'EE::PipelineEnums
'
)
Enums
::
Pipeline
.
prepend_if_ee
(
'EE::Enums::Pipeline
'
)
```
```
ruby
# Define key/value pairs that used in EE only:
module
EE
module
PipelineEnums
override
:failure_reasons
def
failure_reasons
super
.
merge
(
activity_limit_exceeded:
2
)
module
Enums
module
Pipeline
override
:failure_reasons
def
failure_reasons
super
.
merge
(
activity_limit_exceeded:
2
)
end
end
end
end
...
...
@@ -63,7 +67,7 @@ end
This works as-is, however, it has a couple of downside that:
-
Someone could define a key/value pair in EE that is
**conflicted**
with a value defined in FOSS.
e.g. Define
`activity_limit_exceeded: 1`
in
`EE::
PipelineEnums
`
.
e.g. Define
`activity_limit_exceeded: 1`
in
`EE::
Enums::Pipeline
`
.
-
When it happens, the feature works totally different.
e.g. We cannot figure out
`failure_reason`
is either
`config_error`
or
`activity_limit_exceeded`
.
-
When it happens, we have to ship a database migration to fix the data integrity,
...
...
@@ -74,10 +78,12 @@ For example, this example sets `1000` as the offset:
```
ruby
module
EE
module
PipelineEnums
override
:failure_reasons
def
failure_reasons
super
.
merge
(
activity_limit_exceeded:
1_000
,
size_limit_exceeded:
1_001
)
module
Enums
module
Pipeline
override
:failure_reasons
def
failure_reasons
super
.
merge
(
activity_limit_exceeded:
1_000
,
size_limit_exceeded:
1_001
)
end
end
end
end
...
...
ee/app/models/concerns/ee/enums/ci/pipeline.rb
0 → 100644
View file @
039a46d5
# frozen_string_literal: true
module
EE
module
Enums
module
Ci
module
Pipeline
extend
ActiveSupport
::
Concern
class_methods
do
extend
::
Gitlab
::
Utils
::
Override
override
:failure_reasons
def
failure_reasons
super
.
merge
(
activity_limit_exceeded:
20
,
size_limit_exceeded:
21
,
job_activity_limit_exceeded:
22
)
end
end
end
end
end
end
ee/app/models/ee/ci/pipeline_enums.rb
deleted
100644 → 0
View file @
7e027db6
# frozen_string_literal: true
module
EE
module
Ci
module
PipelineEnums
extend
ActiveSupport
::
Concern
class_methods
do
extend
::
Gitlab
::
Utils
::
Override
override
:failure_reasons
def
failure_reasons
super
.
merge
(
activity_limit_exceeded:
20
,
size_limit_exceeded:
21
,
job_activity_limit_exceeded:
22
)
end
end
end
end
end
spec/graphql/resolvers/project_pipeline_resolver_spec.rb
View file @
039a46d5
...
...
@@ -36,8 +36,8 @@ RSpec.describe Resolvers::ProjectPipelineResolver do
context
'when the pipeline is not a ci_config_source'
do
let
(
:pipeline
)
do
config_source_value
=
Ci
::
PipelineEnums
.
non_ci_config_source_values
.
first
config_source
=
Ci
::
PipelineEnums
.
config_sources
.
key
(
config_source_value
)
config_source_value
=
::
Enums
::
Ci
::
Pipeline
.
non_ci_config_source_values
.
first
config_source
=
::
Enums
::
Ci
::
Pipeline
.
config_sources
.
key
(
config_source_value
)
create
(
:ci_pipeline
,
config_source:
config_source
,
project:
project
)
end
...
...
spec/models/ci/pipeline_spec.rb
View file @
039a46d5
...
...
@@ -1965,7 +1965,7 @@ RSpec.describe Ci::Pipeline, :mailer do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:branch
)
{
project
.
default_branch
}
let
(
:ref
)
{
project
.
ci_refs
.
take
}
let
(
:config_source
)
{
Ci
::
PipelineEnums
.
config_sources
[
:parameter_source
]
}
let
(
:config_source
)
{
Enums
::
Ci
::
Pipeline
.
config_sources
[
:parameter_source
]
}
let!
(
:pipeline1
)
{
create
(
:ci_pipeline
,
:success
,
project:
project
,
ref:
branch
)
}
let!
(
:pipeline2
)
{
create
(
:ci_pipeline
,
:success
,
project:
project
,
ref:
branch
)
}
let!
(
:pipeline3
)
{
create
(
:ci_pipeline
,
:failed
,
project:
project
,
ref:
branch
)
}
...
...
spec/models/ci/ref_spec.rb
View file @
039a46d5
...
...
@@ -125,7 +125,7 @@ RSpec.describe Ci::Ref do
describe
'#last_finished_pipeline_id'
do
let
(
:pipeline_status
)
{
:running
}
let
(
:config_source
)
{
Ci
::
PipelineEnums
.
config_sources
[
:repository_source
]
}
let
(
:config_source
)
{
Enums
::
Ci
::
Pipeline
.
config_sources
[
:repository_source
]
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
pipeline_status
,
config_source:
config_source
)
}
let
(
:ci_ref
)
{
pipeline
.
ci_ref
}
...
...
@@ -143,7 +143,7 @@ RSpec.describe Ci::Ref do
end
context
'when the pipeline is not a ci_source'
do
let
(
:config_source
)
{
Ci
::
PipelineEnums
.
config_sources
[
:parameter_source
]
}
let
(
:config_source
)
{
Enums
::
Ci
::
Pipeline
.
config_sources
[
:parameter_source
]
}
it
'returns nil'
do
expect
(
ci_ref
.
last_finished_pipeline_id
).
to
be_nil
...
...
spec/presenters/ci/pipeline_presenter_spec.rb
View file @
039a46d5
...
...
@@ -65,7 +65,7 @@ RSpec.describe Ci::PipelinePresenter do
describe
'#failure_reason'
do
context
'when pipeline has a failure reason'
do
::
Ci
::
PipelineEnums
.
failure_reasons
.
keys
.
each
do
|
failure_reason
|
Enums
::
Ci
::
Pipeline
.
failure_reasons
.
keys
.
each
do
|
failure_reason
|
context
"when failure reason is
#{
failure_reason
}
"
do
before
do
pipeline
.
failure_reason
=
failure_reason
...
...
spec/requests/api/ci/pipelines_spec.rb
View file @
039a46d5
...
...
@@ -477,7 +477,7 @@ RSpec.describe API::Ci::Pipelines do
end
context
'when config source is not ci'
do
let
(
:non_ci_config_source
)
{
::
Ci
::
PipelineEnums
.
non_ci_config_source_values
.
first
}
let
(
:non_ci_config_source
)
{
Enums
::
Ci
::
Pipeline
.
non_ci_config_source_values
.
first
}
let
(
:pipeline_not_ci
)
do
create
(
:ci_pipeline
,
config_source:
non_ci_config_source
,
project:
project
)
end
...
...
spec/requests/api/jobs_spec.rb
View file @
039a46d5
...
...
@@ -240,7 +240,7 @@ RSpec.describe API::Jobs do
end
context
'when config source not ci'
do
let
(
:non_ci_config_source
)
{
::
Ci
::
PipelineEnums
.
non_ci_config_source_values
.
first
}
let
(
:non_ci_config_source
)
{
Enums
::
Ci
::
Pipeline
.
non_ci_config_source_values
.
first
}
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
config_source:
non_ci_config_source
,
project:
project
)
end
...
...
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