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
342de8be
Commit
342de8be
authored
Mar 25, 2020
by
Fabio Pitino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move Dependencies to Ci::BuildDependencies
Dependencies are specific to Ci::Build
parent
f1dd55e8
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
157 additions
and
161 deletions
+157
-161
app/models/ci/build.rb
app/models/ci/build.rb
+1
-1
app/models/ci/build_dependencies.rb
app/models/ci/build_dependencies.rb
+85
-0
app/models/ci/processable/dependencies.rb
app/models/ci/processable/dependencies.rb
+0
-87
ee/app/models/ee/ci/build_dependencies.rb
ee/app/models/ee/ci/build_dependencies.rb
+69
-0
ee/app/models/ee/ci/processable/dependencies.rb
ee/app/models/ee/ci/processable/dependencies.rb
+0
-71
ee/spec/models/ee/ci/build_dependencies_spec.rb
ee/spec/models/ee/ci/build_dependencies_spec.rb
+1
-1
spec/models/ci/build_dependencies_spec.rb
spec/models/ci/build_dependencies_spec.rb
+1
-1
No files found.
app/models/ci/build.rb
View file @
342de8be
...
...
@@ -914,7 +914,7 @@ module Ci
def
dependencies
strong_memoize
(
:dependencies
)
do
Ci
::
Processable
::
Dependencies
.
new
(
self
)
Ci
::
Build
Dependencies
.
new
(
self
)
end
end
...
...
app/models/ci/build_dependencies.rb
0 → 100644
View file @
342de8be
# frozen_string_literal: true
module
Ci
class
BuildDependencies
attr_reader
:processable
def
initialize
(
processable
)
@processable
=
processable
end
def
all
(
local
+
cross_pipeline
).
uniq
end
# Dependencies local to the given pipeline
def
local
return
[]
if
no_local_dependencies_specified?
deps
=
model_class
.
where
(
pipeline_id:
processable
.
pipeline_id
).
latest
deps
=
from_previous_stages
(
deps
)
deps
=
from_needs
(
deps
)
deps
=
from_dependencies
(
deps
)
deps
end
# Dependencies that are defined in other pipelines
def
cross_pipeline
[]
end
def
invalid_local
local
.
reject
(
&
:valid_dependency?
)
end
def
valid?
valid_local?
&&
valid_cross_pipeline?
end
private
# Dependencies can only be of Ci::Build type because only builds
# can create artifacts
def
model_class
::
Ci
::
Build
end
def
valid_local?
return
true
if
Feature
.
enabled?
(
'ci_disable_validates_dependencies'
)
local
.
all?
(
&
:valid_dependency?
)
end
def
valid_cross_pipeline?
true
end
def
project
processable
.
project
end
def
no_local_dependencies_specified?
processable
.
options
[
:dependencies
]
&
.
empty?
end
def
from_previous_stages
(
scope
)
scope
.
before_stage
(
processable
.
stage_idx
)
end
def
from_needs
(
scope
)
return
scope
unless
Feature
.
enabled?
(
:ci_dag_support
,
project
,
default_enabled:
true
)
return
scope
unless
processable
.
scheduling_type_dag?
needs_names
=
processable
.
needs
.
artifacts
.
select
(
:name
)
scope
.
where
(
name:
needs_names
)
end
def
from_dependencies
(
scope
)
return
scope
unless
processable
.
options
[
:dependencies
].
present?
scope
.
where
(
name:
processable
.
options
[
:dependencies
])
end
end
end
Ci
::
BuildDependencies
.
prepend_if_ee
(
'EE::Ci::BuildDependencies'
)
app/models/ci/processable/dependencies.rb
deleted
100644 → 0
View file @
f1dd55e8
# frozen_string_literal: true
module
Ci
class
Processable
class
Dependencies
attr_reader
:processable
def
initialize
(
processable
)
@processable
=
processable
end
def
all
(
local
+
cross_pipeline
).
uniq
end
# Dependencies local to the given pipeline
def
local
return
[]
if
no_local_dependencies_specified?
deps
=
model_class
.
where
(
pipeline_id:
processable
.
pipeline_id
).
latest
deps
=
from_previous_stages
(
deps
)
deps
=
from_needs
(
deps
)
deps
=
from_dependencies
(
deps
)
deps
end
# Dependencies that are defined in other pipelines
def
cross_pipeline
[]
end
def
invalid_local
local
.
reject
(
&
:valid_dependency?
)
end
def
valid?
valid_local?
&&
valid_cross_pipeline?
end
private
# Dependencies can only be of Ci::Build type because only builds
# can create artifacts
def
model_class
::
Ci
::
Build
end
def
valid_local?
return
true
if
Feature
.
enabled?
(
'ci_disable_validates_dependencies'
)
local
.
all?
(
&
:valid_dependency?
)
end
def
valid_cross_pipeline?
true
end
def
project
processable
.
project
end
def
no_local_dependencies_specified?
processable
.
options
[
:dependencies
]
&
.
empty?
end
def
from_previous_stages
(
scope
)
scope
.
before_stage
(
processable
.
stage_idx
)
end
def
from_needs
(
scope
)
return
scope
unless
Feature
.
enabled?
(
:ci_dag_support
,
project
,
default_enabled:
true
)
return
scope
unless
processable
.
scheduling_type_dag?
needs_names
=
processable
.
needs
.
artifacts
.
select
(
:name
)
scope
.
where
(
name:
needs_names
)
end
def
from_dependencies
(
scope
)
return
scope
unless
processable
.
options
[
:dependencies
].
present?
scope
.
where
(
name:
processable
.
options
[
:dependencies
])
end
end
end
end
Ci
::
Processable
::
Dependencies
.
prepend_if_ee
(
'EE::Ci::Processable::Dependencies'
)
ee/app/models/ee/ci/build_dependencies.rb
0 → 100644
View file @
342de8be
# frozen_string_literal: true
module
EE
module
Ci
module
BuildDependencies
extend
ActiveSupport
::
Concern
extend
::
Gitlab
::
Utils
::
Override
include
::
Gitlab
::
Utils
::
StrongMemoize
LIMIT
=
::
Gitlab
::
Ci
::
Config
::
Entry
::
Needs
::
NEEDS_CROSS_DEPENDENCIES_LIMIT
override
:cross_pipeline
def
cross_pipeline
strong_memoize
(
:cross_pipeline
)
do
fetch_cross_pipeline
end
end
private
override
:valid_cross_pipeline?
def
valid_cross_pipeline?
cross_pipeline
.
size
==
specified_cross_pipeline_dependencies
.
size
end
def
fetch_cross_pipeline
return
[]
unless
processable
.
user_id
return
[]
unless
project
.
feature_available?
(
:cross_project_pipelines
)
cross_dependencies_relationship
.
preload
(
project:
[
:project_feature
])
.
select
{
|
job
|
user
.
can?
(
:read_build
,
job
)
}
end
def
cross_dependencies_relationship
deps
=
specified_cross_pipeline_dependencies
return
model_class
.
none
unless
deps
.
any?
relationship_fragments
=
build_cross_dependencies_fragments
(
deps
,
model_class
.
latest
.
success
)
return
model_class
.
none
unless
relationship_fragments
.
any?
model_class
.
from_union
(
relationship_fragments
).
limit
(
LIMIT
)
end
def
build_cross_dependencies_fragments
(
deps
,
search_scope
)
deps
.
inject
([])
do
|
fragments
,
dep
|
next
fragments
unless
dep
[
:artifacts
]
fragments
<<
build_cross_dependency_relationship_fragment
(
dep
,
search_scope
)
end
end
def
build_cross_dependency_relationship_fragment
(
dependency
,
search_scope
)
args
=
dependency
.
values_at
(
:job
,
:ref
,
:project
)
dep_id
=
search_scope
.
max_build_id_by
(
*
args
)
model_class
.
id_in
(
dep_id
)
end
def
user
processable
.
user
end
def
specified_cross_pipeline_dependencies
Array
(
processable
.
options
[
:cross_dependencies
])
end
end
end
end
ee/app/models/ee/ci/processable/dependencies.rb
deleted
100644 → 0
View file @
f1dd55e8
# frozen_string_literal: true
module
EE
module
Ci
module
Processable
module
Dependencies
extend
ActiveSupport
::
Concern
extend
::
Gitlab
::
Utils
::
Override
include
::
Gitlab
::
Utils
::
StrongMemoize
LIMIT
=
::
Gitlab
::
Ci
::
Config
::
Entry
::
Needs
::
NEEDS_CROSS_DEPENDENCIES_LIMIT
override
:cross_pipeline
def
cross_pipeline
strong_memoize
(
:cross_pipeline
)
do
fetch_cross_pipeline
end
end
private
override
:valid_cross_pipeline?
def
valid_cross_pipeline?
cross_pipeline
.
size
==
specified_cross_pipeline_dependencies
.
size
end
def
fetch_cross_pipeline
return
[]
unless
processable
.
user_id
return
[]
unless
project
.
feature_available?
(
:cross_project_pipelines
)
cross_dependencies_relationship
.
preload
(
project:
[
:project_feature
])
.
select
{
|
job
|
user
.
can?
(
:read_build
,
job
)
}
end
def
cross_dependencies_relationship
deps
=
specified_cross_pipeline_dependencies
return
model_class
.
none
unless
deps
.
any?
relationship_fragments
=
build_cross_dependencies_fragments
(
deps
,
model_class
.
latest
.
success
)
return
model_class
.
none
unless
relationship_fragments
.
any?
model_class
.
from_union
(
relationship_fragments
).
limit
(
LIMIT
)
end
def
build_cross_dependencies_fragments
(
deps
,
search_scope
)
deps
.
inject
([])
do
|
fragments
,
dep
|
next
fragments
unless
dep
[
:artifacts
]
fragments
<<
build_cross_dependency_relationship_fragment
(
dep
,
search_scope
)
end
end
def
build_cross_dependency_relationship_fragment
(
dependency
,
search_scope
)
args
=
dependency
.
values_at
(
:job
,
:ref
,
:project
)
dep_id
=
search_scope
.
max_build_id_by
(
*
args
)
model_class
.
id_in
(
dep_id
)
end
def
user
processable
.
user
end
def
specified_cross_pipeline_dependencies
Array
(
processable
.
options
[
:cross_dependencies
])
end
end
end
end
end
ee/spec/models/ee/ci/
processable/
dependencies_spec.rb
→
ee/spec/models/ee/ci/
build_
dependencies_spec.rb
View file @
342de8be
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
describe
Ci
::
Processable
::
Dependencies
do
describe
Ci
::
Build
Dependencies
do
describe
'#cross_pipeline'
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
,
refind:
true
)
{
create
(
:project
,
:repository
)
}
...
...
spec/models/ci/
processable/
dependencies_spec.rb
→
spec/models/ci/
build_
dependencies_spec.rb
View file @
342de8be
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
describe
Ci
::
Processable
::
Dependencies
do
describe
Ci
::
Build
Dependencies
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
,
reload:
true
)
{
create
(
:project
,
:repository
)
}
...
...
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