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
Jérome Perrin
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
Show 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
raise
ValidationError
,
e
.
message
end
# REFACTORING STUB, remove this method, used only in tests.
#
def
builds_for_stage_and_ref
(
stage
,
ref
,
tag
=
false
,
source
=
nil
)
jobs_for_stage_and_ref
(
stage
,
ref
,
tag
,
source
).
map
do
|
name
,
_
|
build_attributes
(
name
)
end
pipeline_stage_builds
(
stage
,
::
Ci
::
Pipeline
.
new
(
ref:
ref
,
source:
source
,
tag:
tag
))
end
def
builds
...
...
@@ -84,32 +85,19 @@ module Gitlab
private
def
pipeline_stage_builds
(
stage
,
pipeline
)
builds
=
builds_for_stage_and_ref
(
stage
,
pipeline
.
ref
,
pipeline
.
tag?
,
pipeline
.
source
)
builds
.
select
do
|
build
|
job
=
@jobs
[
build
.
fetch
(
:name
).
to_sym
]
stage_jobs
=
@jobs
.
select
do
|
_
,
job
|
next
unless
job
[
:stage
]
==
stage
only_specs
=
Gitlab
::
Ci
::
Build
::
Policy
.
fabricate
(
job
.
fetch
(
:only
,
{}))
except_specs
=
Gitlab
::
Ci
::
Build
::
Policy
.
fabricate
(
job
.
fetch
(
:except
,
{}))
only_specs
.
all?
{
|
spec
|
spec
.
satisfied_by?
(
pipeline
)
}
&&
except_specs
.
none?
{
|
spec
|
spec
.
satisfied_by?
(
pipeline
)
}
end
only_specs
.
all?
{
|
spec
|
spec
.
satisfied_by?
(
pipeline
,
path:
@path
)
}
&&
except_specs
.
none?
{
|
spec
|
spec
.
satisfied_by?
(
pipeline
,
path:
@path
)
}
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
def
jobs_for_stage_and_ref
(
stage
,
ref
,
tag
=
false
,
source
=
nil
)
jobs_for_ref
(
ref
,
tag
,
source
).
select
do
|
_
,
job
|
job
[
:stage
]
==
stage
end
stage_jobs
.
map
{
|
_
,
job
|
build_attributes
(
job
[
:name
])
}
end
def
initial_parsing
...
...
@@ -204,51 +192,6 @@ module Gitlab
raise
ValidationError
,
"
#{
name
}
job: on_stop job
#{
on_stop
}
needs to have action stop defined"
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
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