Commit 039a46d5 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Move Ci::PipelineEnums to Enums::Ci::Pipeline

Move enums related modules to a separate directory
parent 7e027db6
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Types module Types
module Ci module Ci
class PipelineConfigSourceEnum < BaseEnum 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 value state_symbol.to_s.upcase, value: state_symbol.to_s
end end
end end
......
...@@ -26,7 +26,7 @@ module Types ...@@ -26,7 +26,7 @@ module Types
description: 'Detailed status of the pipeline', description: 'Detailed status of the pipeline',
resolve: -> (obj, _args, ctx) { obj.detailed_status(ctx[:current_user]) } resolve: -> (obj, _args, ctx) { obj.detailed_status(ctx[:current_user]) }
field :config_source, PipelineConfigSourceEnum, null: true, 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, field :duration, GraphQL::INT_TYPE, null: true,
description: 'Duration of the pipeline in seconds' description: 'Duration of the pipeline in seconds'
field :coverage, GraphQL::FLOAT_TYPE, null: true, field :coverage, GraphQL::FLOAT_TYPE, null: true,
......
...@@ -104,15 +104,15 @@ module Ci ...@@ -104,15 +104,15 @@ module Ci
after_create :keep_around_commits, unless: :importing? 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. # 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. # 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 } enum locked: { unlocked: 0, artifacts_locked: 1 }
...@@ -260,7 +260,7 @@ module Ci ...@@ -260,7 +260,7 @@ module Ci
scope :internal, -> { where(source: internal_sources) } scope :internal, -> { where(source: internal_sources) }
scope :no_child, -> { where.not(source: :parent_pipeline) } 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_user, -> (user) { where(user: user) }
scope :for_sha, -> (sha) { where(sha: sha) } scope :for_sha, -> (sha) { where(sha: sha) }
scope :for_source_sha, -> (source_sha) { where(source_sha: source_sha) } scope :for_source_sha, -> (source_sha) { where(source_sha: source_sha) }
...@@ -1012,7 +1012,7 @@ module Ci ...@@ -1012,7 +1012,7 @@ module Ci
end end
def cacheable? def cacheable?
Ci::PipelineEnums.ci_config_sources.key?(config_source.to_sym) Enums::Ci::Pipeline.ci_config_sources.key?(config_source.to_sym)
end end
def source_ref_path def source_ref_path
......
# 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')
# 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')
...@@ -33,37 +33,41 @@ tempted to organize the `enum` as the following: ...@@ -33,37 +33,41 @@ tempted to organize the `enum` as the following:
```ruby ```ruby
# Define `failure_reason` enum in `Pipeline` model: # Define `failure_reason` enum in `Pipeline` model:
class Pipeline < ApplicationRecord class Pipeline < ApplicationRecord
enum failure_reason: ::PipelineEnums.failure_reasons enum failure_reason: Enums::Pipeline.failure_reasons
end end
``` ```
```ruby ```ruby
# Define key/value pairs that used in FOSS and EE: # Define key/value pairs that used in FOSS and EE:
module PipelineEnums module Enums
module Pipeline
def self.failure_reasons def self.failure_reasons
{ unknown_failure: 0, config_error: 1 } { unknown_failure: 0, config_error: 1 }
end end
end
end end
PipelineEnums.prepend_if_ee('EE::PipelineEnums') Enums::Pipeline.prepend_if_ee('EE::Enums::Pipeline')
``` ```
```ruby ```ruby
# Define key/value pairs that used in EE only: # Define key/value pairs that used in EE only:
module EE module EE
module PipelineEnums module Enums
module Pipeline
override :failure_reasons override :failure_reasons
def failure_reasons def failure_reasons
super.merge(activity_limit_exceeded: 2) super.merge(activity_limit_exceeded: 2)
end end
end end
end
end end
``` ```
This works as-is, however, it has a couple of downside that: 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. - 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. - When it happens, the feature works totally different.
e.g. We cannot figure out `failure_reason` is either `config_error` or `activity_limit_exceeded`. 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, - When it happens, we have to ship a database migration to fix the data integrity,
...@@ -74,12 +78,14 @@ For example, this example sets `1000` as the offset: ...@@ -74,12 +78,14 @@ For example, this example sets `1000` as the offset:
```ruby ```ruby
module EE module EE
module PipelineEnums module Enums
module Pipeline
override :failure_reasons override :failure_reasons
def failure_reasons def failure_reasons
super.merge(activity_limit_exceeded: 1_000, size_limit_exceeded: 1_001) super.merge(activity_limit_exceeded: 1_000, size_limit_exceeded: 1_001)
end end
end end
end
end end
``` ```
......
# 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
# 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
...@@ -36,8 +36,8 @@ RSpec.describe Resolvers::ProjectPipelineResolver do ...@@ -36,8 +36,8 @@ RSpec.describe Resolvers::ProjectPipelineResolver do
context 'when the pipeline is not a ci_config_source' do context 'when the pipeline is not a ci_config_source' do
let(:pipeline) do let(:pipeline) do
config_source_value = Ci::PipelineEnums.non_ci_config_source_values.first config_source_value = ::Enums::Ci::Pipeline.non_ci_config_source_values.first
config_source = Ci::PipelineEnums.config_sources.key(config_source_value) config_source = ::Enums::Ci::Pipeline.config_sources.key(config_source_value)
create(:ci_pipeline, config_source: config_source, project: project) create(:ci_pipeline, config_source: config_source, project: project)
end end
......
...@@ -1965,7 +1965,7 @@ RSpec.describe Ci::Pipeline, :mailer do ...@@ -1965,7 +1965,7 @@ RSpec.describe Ci::Pipeline, :mailer do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:branch) { project.default_branch } let(:branch) { project.default_branch }
let(:ref) { project.ci_refs.take } 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!(:pipeline1) { create(:ci_pipeline, :success, project: project, ref: branch) }
let!(:pipeline2) { 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) } let!(:pipeline3) { create(:ci_pipeline, :failed, project: project, ref: branch) }
......
...@@ -125,7 +125,7 @@ RSpec.describe Ci::Ref do ...@@ -125,7 +125,7 @@ RSpec.describe Ci::Ref do
describe '#last_finished_pipeline_id' do describe '#last_finished_pipeline_id' do
let(:pipeline_status) { :running } 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(:pipeline) { create(:ci_pipeline, pipeline_status, config_source: config_source) }
let(:ci_ref) { pipeline.ci_ref } let(:ci_ref) { pipeline.ci_ref }
...@@ -143,7 +143,7 @@ RSpec.describe Ci::Ref do ...@@ -143,7 +143,7 @@ RSpec.describe Ci::Ref do
end end
context 'when the pipeline is not a ci_source' do 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 it 'returns nil' do
expect(ci_ref.last_finished_pipeline_id).to be_nil expect(ci_ref.last_finished_pipeline_id).to be_nil
......
...@@ -65,7 +65,7 @@ RSpec.describe Ci::PipelinePresenter do ...@@ -65,7 +65,7 @@ RSpec.describe Ci::PipelinePresenter do
describe '#failure_reason' do describe '#failure_reason' do
context 'when pipeline has a 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 context "when failure reason is #{failure_reason}" do
before do before do
pipeline.failure_reason = failure_reason pipeline.failure_reason = failure_reason
......
...@@ -477,7 +477,7 @@ RSpec.describe API::Ci::Pipelines do ...@@ -477,7 +477,7 @@ RSpec.describe API::Ci::Pipelines do
end end
context 'when config source is not ci' do 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 let(:pipeline_not_ci) do
create(:ci_pipeline, config_source: non_ci_config_source, project: project) create(:ci_pipeline, config_source: non_ci_config_source, project: project)
end end
......
...@@ -240,7 +240,7 @@ RSpec.describe API::Jobs do ...@@ -240,7 +240,7 @@ RSpec.describe API::Jobs do
end end
context 'when config source not ci' do 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 let(:pipeline) do
create(:ci_pipeline, config_source: non_ci_config_source, project: project) create(:ci_pipeline, config_source: non_ci_config_source, project: project)
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