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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
241197c2
Commit
241197c2
authored
Sep 14, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract job refs policy specs into separate class
parent
dd784b15
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
66 deletions
+59
-66
lib/gitlab/ci/build/policy/refs.rb
lib/gitlab/ci/build/policy/refs.rb
+50
-0
lib/gitlab/ci/yaml_processor.rb
lib/gitlab/ci/yaml_processor.rb
+9
-66
No files found.
lib/gitlab/ci/build/policy/refs.rb
0 → 100644
View file @
241197c2
module
Gitlab
module
Ci
module
Build
module
Policy
class
Refs
<
Policy
::
Specification
def
initialize
(
refs
)
@patterns
=
Array
(
refs
)
end
def
satisfied_by?
(
pipeline
,
path
:)
@patterns
.
any?
do
|
pattern
|
pattern
,
ref_path
=
pattern
.
split
(
'@'
,
2
)
matches_path?
(
ref_path
,
path
)
&&
matches_pattern?
(
pattern
,
pipeline
)
end
end
private
def
matches_path?
(
ref_path
,
expected_path
)
return
true
unless
ref_path
expected_path
==
ref_path
end
def
matches_pattern?
(
pattern
,
pipeline
)
return
true
if
pipeline
.
tag?
&&
pattern
==
'tags'
return
true
if
!
pipeline
.
tag?
&&
pattern
==
'branches'
return
true
if
source_to_pattern
(
pipeline
.
source
)
==
pattern
if
pattern
.
first
==
"/"
&&
pattern
.
last
==
"/"
Regexp
.
new
(
pattern
[
1
...-
1
])
=~
pipeline
.
ref
else
pattern
==
pipeline
.
ref
end
end
def
source_to_pattern
(
source
)
if
%w[api external web]
.
include?
(
source
)
source
else
source
&
.
pluralize
end
end
end
end
end
end
end
lib/gitlab/ci/yaml_processor.rb
View file @
241197c2
...
@@ -21,10 +21,11 @@ module Gitlab
...
@@ -21,10 +21,11 @@ module Gitlab
raise
ValidationError
,
e
.
message
raise
ValidationError
,
e
.
message
end
end
# REFACTORING STUB, remove this method, used only in tests.
#
def
builds_for_stage_and_ref
(
stage
,
ref
,
tag
=
false
,
source
=
nil
)
def
builds_for_stage_and_ref
(
stage
,
ref
,
tag
=
false
,
source
=
nil
)
jobs_for_stage_and_ref
(
stage
,
ref
,
tag
,
source
).
map
do
|
name
,
_
|
pipeline_stage_builds
(
stage
,
::
Ci
::
Pipeline
.
new
(
ref:
ref
,
source:
source
,
tag:
tag
))
build_attributes
(
name
)
end
end
end
def
builds
def
builds
...
@@ -84,32 +85,19 @@ module Gitlab
...
@@ -84,32 +85,19 @@ module Gitlab
private
private
def
pipeline_stage_builds
(
stage
,
pipeline
)
def
pipeline_stage_builds
(
stage
,
pipeline
)
builds
=
builds_for_stage_and_ref
(
stage_jobs
=
@jobs
.
select
do
|
_
,
job
|
stage
,
pipeline
.
ref
,
pipeline
.
tag?
,
pipeline
.
source
)
next
unless
job
[
:stage
]
==
stage
builds
.
select
do
|
build
|
job
=
@jobs
[
build
.
fetch
(
:name
).
to_sym
]
only_specs
=
Gitlab
::
Ci
::
Build
::
Policy
only_specs
=
Gitlab
::
Ci
::
Build
::
Policy
.
fabricate
(
job
.
fetch
(
:only
,
{}))
.
fabricate
(
job
.
fetch
(
:only
,
{}))
except_specs
=
Gitlab
::
Ci
::
Build
::
Policy
except_specs
=
Gitlab
::
Ci
::
Build
::
Policy
.
fabricate
(
job
.
fetch
(
:except
,
{}))
.
fabricate
(
job
.
fetch
(
:except
,
{}))
only_specs
.
all?
{
|
spec
|
spec
.
satisfied_by?
(
pipeline
)
}
&&
only_specs
.
all?
{
|
spec
|
spec
.
satisfied_by?
(
pipeline
,
path:
@path
)
}
&&
except_specs
.
none?
{
|
spec
|
spec
.
satisfied_by?
(
pipeline
)
}
except_specs
.
none?
{
|
spec
|
spec
.
satisfied_by?
(
pipeline
,
path:
@path
)
}
end
end
def
jobs_for_ref
(
ref
,
tag
=
false
,
source
=
nil
)
@jobs
.
select
do
|
_
,
job
|
process?
(
job
.
dig
(
:only
,
:refs
),
job
.
dig
(
:except
,
:refs
),
ref
,
tag
,
source
)
end
end
end
def
jobs_for_stage_and_ref
(
stage
,
ref
,
tag
=
false
,
source
=
nil
)
stage_jobs
.
map
{
|
_
,
job
|
build_attributes
(
job
[
:name
])
}
jobs_for_ref
(
ref
,
tag
,
source
).
select
do
|
_
,
job
|
job
[
:stage
]
==
stage
end
end
end
def
initial_parsing
def
initial_parsing
...
@@ -204,51 +192,6 @@ module Gitlab
...
@@ -204,51 +192,6 @@ module Gitlab
raise
ValidationError
,
"
#{
name
}
job: on_stop job
#{
on_stop
}
needs to have action stop defined"
raise
ValidationError
,
"
#{
name
}
job: on_stop job
#{
on_stop
}
needs to have action stop defined"
end
end
end
end
def
process?
(
only_params
,
except_params
,
ref
,
tag
,
source
)
if
only_params
.
present?
return
false
unless
matching?
(
only_params
,
ref
,
tag
,
source
)
end
if
except_params
.
present?
return
false
if
matching?
(
except_params
,
ref
,
tag
,
source
)
end
true
end
def
matching?
(
patterns
,
ref
,
tag
,
source
)
patterns
.
any?
do
|
pattern
|
pattern
,
path
=
pattern
.
split
(
'@'
,
2
)
matches_path?
(
path
)
&&
matches_pattern?
(
pattern
,
ref
,
tag
,
source
)
end
end
def
matches_path?
(
path
)
return
true
unless
path
path
==
self
.
path
end
def
matches_pattern?
(
pattern
,
ref
,
tag
,
source
)
return
true
if
tag
&&
pattern
==
'tags'
return
true
if
!
tag
&&
pattern
==
'branches'
return
true
if
source_to_pattern
(
source
)
==
pattern
if
pattern
.
first
==
"/"
&&
pattern
.
last
==
"/"
Regexp
.
new
(
pattern
[
1
...-
1
])
=~
ref
else
pattern
==
ref
end
end
def
source_to_pattern
(
source
)
if
%w[api external web]
.
include?
(
source
)
source
else
source
&
.
pluralize
end
end
end
end
end
end
end
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