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
d79ad28f
Commit
d79ad28f
authored
Sep 18, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not pass project path from YAML processor
Use project full path that can be received from a pipeline object
parent
6681ea9c
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
40 additions
and
23 deletions
+40
-23
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+1
-0
lib/gitlab/ci/build/policy/kubernetes.rb
lib/gitlab/ci/build/policy/kubernetes.rb
+1
-1
lib/gitlab/ci/build/policy/refs.rb
lib/gitlab/ci/build/policy/refs.rb
+6
-6
lib/gitlab/ci/build/policy/specification.rb
lib/gitlab/ci/build/policy/specification.rb
+2
-2
lib/gitlab/ci/yaml_processor.rb
lib/gitlab/ci/yaml_processor.rb
+2
-2
spec/lib/gitlab/ci/build/policy/refs_spec.rb
spec/lib/gitlab/ci/build/policy/refs_spec.rb
+3
-3
spec/lib/gitlab/ci/yaml_processor_spec.rb
spec/lib/gitlab/ci/yaml_processor_spec.rb
+24
-9
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+1
-0
No files found.
app/models/ci/pipeline.rb
View file @
d79ad28f
...
@@ -31,6 +31,7 @@ module Ci
...
@@ -31,6 +31,7 @@ module Ci
has_many
:auto_canceled_jobs
,
class_name:
'CommitStatus'
,
foreign_key:
'auto_canceled_by_id'
has_many
:auto_canceled_jobs
,
class_name:
'CommitStatus'
,
foreign_key:
'auto_canceled_by_id'
delegate
:id
,
to: :project
,
prefix:
true
delegate
:id
,
to: :project
,
prefix:
true
delegate
:full_path
,
to: :project
,
prefix:
true
validates
:source
,
exclusion:
{
in:
%w(unknown)
,
unless: :importing?
},
on: :create
validates
:source
,
exclusion:
{
in:
%w(unknown)
,
unless: :importing?
},
on: :create
validates
:sha
,
presence:
{
unless: :importing?
}
validates
:sha
,
presence:
{
unless: :importing?
}
...
...
lib/gitlab/ci/build/policy/kubernetes.rb
View file @
d79ad28f
...
@@ -9,7 +9,7 @@ module Gitlab
...
@@ -9,7 +9,7 @@ module Gitlab
end
end
end
end
def
satisfied_by?
(
pipeline
,
**
_
)
def
satisfied_by?
(
pipeline
)
pipeline
.
has_kubernetes_active?
pipeline
.
has_kubernetes_active?
end
end
end
end
...
...
lib/gitlab/ci/build/policy/refs.rb
View file @
d79ad28f
...
@@ -7,21 +7,21 @@ module Gitlab
...
@@ -7,21 +7,21 @@ module Gitlab
@patterns
=
Array
(
refs
)
@patterns
=
Array
(
refs
)
end
end
def
satisfied_by?
(
pipeline
,
path:
nil
)
def
satisfied_by?
(
pipeline
)
@patterns
.
any?
do
|
pattern
|
@patterns
.
any?
do
|
pattern
|
pattern
,
ref_
path
=
pattern
.
split
(
'@'
,
2
)
pattern
,
path
=
pattern
.
split
(
'@'
,
2
)
matches_path?
(
ref_path
,
path
)
&&
matches_path?
(
path
,
pipeline
)
&&
matches_pattern?
(
pattern
,
pipeline
)
matches_pattern?
(
pattern
,
pipeline
)
end
end
end
end
private
private
def
matches_path?
(
ref_path
,
expected_path
)
def
matches_path?
(
path
,
pipeline
)
return
true
unless
ref_
path
return
true
unless
path
expected_path
==
ref_
path
pipeline
.
project_full_path
==
path
end
end
def
matches_pattern?
(
pattern
,
pipeline
)
def
matches_pattern?
(
pattern
,
pipeline
)
...
...
lib/gitlab/ci/build/policy/specification.rb
View file @
d79ad28f
...
@@ -3,7 +3,7 @@ module Gitlab
...
@@ -3,7 +3,7 @@ module Gitlab
module
Build
module
Build
module
Policy
module
Policy
##
##
# Abstract class that defines an inter
e
face of job policy
# Abstract class that defines an interface of job policy
# specification.
# specification.
#
#
# Used for job's only/except policy configuration.
# Used for job's only/except policy configuration.
...
@@ -15,7 +15,7 @@ module Gitlab
...
@@ -15,7 +15,7 @@ module Gitlab
@spec
=
spec
@spec
=
spec
end
end
def
satisfied_by?
(
pipeline
,
**
metadata
)
def
satisfied_by?
(
pipeline
)
raise
NotImplementedError
raise
NotImplementedError
end
end
end
end
...
...
lib/gitlab/ci/yaml_processor.rb
View file @
d79ad28f
...
@@ -63,8 +63,8 @@ module Gitlab
...
@@ -63,8 +63,8 @@ module Gitlab
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
,
path:
@path
)
}
&&
only_specs
.
all?
{
|
spec
|
spec
.
satisfied_by?
(
pipeline
)
}
&&
except_specs
.
none?
{
|
spec
|
spec
.
satisfied_by?
(
pipeline
,
path:
@path
)
}
except_specs
.
none?
{
|
spec
|
spec
.
satisfied_by?
(
pipeline
)
}
end
end
selected_jobs
.
map
{
|
_
,
job
|
build_attributes
(
job
[
:name
])
}
selected_jobs
.
map
{
|
_
,
job
|
build_attributes
(
job
[
:name
])
}
...
...
spec/lib/gitlab/ci/build/policy/refs_spec.rb
View file @
d79ad28f
...
@@ -46,13 +46,13 @@ describe Gitlab::Ci::Build::Policy::Refs do
...
@@ -46,13 +46,13 @@ describe Gitlab::Ci::Build::Policy::Refs do
end
end
it
'is satisfied when provided patch matches specified one'
do
it
'is satisfied when provided patch matches specified one'
do
expect
(
described_class
.
new
(
%
w[master@some/repository
]
))
expect
(
described_class
.
new
(
%
W[master@
#{
pipeline
.
project_full_path
}
]
))
.
to
be_satisfied_by
(
pipeline
,
path:
'some/repository'
)
.
to
be_satisfied_by
(
pipeline
)
end
end
it
'is not satisfied when path differs'
do
it
'is not satisfied when path differs'
do
expect
(
described_class
.
new
(
%w[master@some/fork/repository]
))
expect
(
described_class
.
new
(
%w[master@some/fork/repository]
))
.
not_to
be_satisfied_by
(
pipeline
,
path:
'some/repository'
)
.
not_to
be_satisfied_by
(
pipeline
)
end
end
end
end
...
...
spec/lib/gitlab/ci/yaml_processor_spec.rb
View file @
d79ad28f
...
@@ -340,14 +340,20 @@ module Gitlab
...
@@ -340,14 +340,20 @@ module Gitlab
end
end
it
"returns builds if only has current repository path"
do
it
"returns builds if only has current repository path"
do
seed_pipeline
=
pipeline
(
ref:
'deploy'
)
config
=
YAML
.
dump
({
config
=
YAML
.
dump
({
before_script:
[
"pwd"
],
before_script:
[
"pwd"
],
rspec:
{
script:
"rspec"
,
type:
type
,
only:
[
"branches@path"
]
}
rspec:
{
script:
"rspec"
,
type:
type
,
only:
[
"branches@
#{
seed_pipeline
.
project_full_path
}
"
]
}
})
})
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
,
path
)
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
,
path
)
expect
(
config_processor
.
pipeline_stage_builds
(
type
,
pipeline
(
ref:
"deploy"
)
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
pipeline_stage_builds
(
type
,
seed_pipeline
).
size
).
to
eq
(
1
)
end
end
it
"does not return builds if only has different repository path"
do
it
"does not return builds if only has different repository path"
do
...
@@ -517,14 +523,19 @@ module Gitlab
...
@@ -517,14 +523,19 @@ module Gitlab
end
end
it
"does not return builds if except has current repository path"
do
it
"does not return builds if except has current repository path"
do
seed_pipeline
=
pipeline
(
ref:
'deploy'
)
config
=
YAML
.
dump
({
config
=
YAML
.
dump
({
before_script:
[
"pwd"
],
before_script:
[
"pwd"
],
rspec:
{
script:
"rspec"
,
type:
type
,
except:
[
"branches@path"
]
}
rspec:
{
script:
"rspec"
,
type:
type
,
except:
[
"branches@
#{
seed_pipeline
.
project_full_path
}
"
]
}
})
})
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
,
path
)
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
,
path
)
expect
(
config_processor
.
pipeline_stage_builds
(
type
,
pipeline
(
ref:
"deploy"
)
).
size
).
to
eq
(
0
)
expect
(
config_processor
.
pipeline_stage_builds
(
type
,
seed_pipeline
).
size
).
to
eq
(
0
)
end
end
it
"returns builds if except has different repository path"
do
it
"returns builds if except has different repository path"
do
...
@@ -539,18 +550,22 @@ module Gitlab
...
@@ -539,18 +550,22 @@ module Gitlab
end
end
it
"returns build except specified type"
do
it
"returns build except specified type"
do
master_pipeline
=
pipeline
(
ref:
'master'
)
test_pipeline
=
pipeline
(
ref:
'test'
)
deploy_pipeline
=
pipeline
(
ref:
'deploy'
)
config
=
YAML
.
dump
({
config
=
YAML
.
dump
({
before_script:
[
"pwd"
],
before_script:
[
"pwd"
],
rspec:
{
script:
"rspec"
,
type:
"test"
,
except:
[
"master"
,
"deploy"
,
"test@
fork
"
]
},
rspec:
{
script:
"rspec"
,
type:
"test"
,
except:
[
"master"
,
"deploy"
,
"test@
#{
test_pipeline
.
project_full_path
}
"
]
},
staging:
{
script:
"deploy"
,
type:
"deploy"
,
except:
[
"master"
]
},
staging:
{
script:
"deploy"
,
type:
"deploy"
,
except:
[
"master"
]
},
production:
{
script:
"deploy"
,
type:
"deploy"
,
except:
[
"master@
fork
"
]
}
production:
{
script:
"deploy"
,
type:
"deploy"
,
except:
[
"master@
#{
master_pipeline
.
project_full_path
}
"
]
}
})
})
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
,
'fork'
)
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
,
'fork'
)
expect
(
config_processor
.
pipeline_stage_builds
(
"deploy"
,
pipeline
(
ref:
"deploy"
)
).
size
).
to
eq
(
2
)
expect
(
config_processor
.
pipeline_stage_builds
(
"deploy"
,
deploy_pipeline
).
size
).
to
eq
(
2
)
expect
(
config_processor
.
pipeline_stage_builds
(
"test"
,
pipeline
(
ref:
"test"
)
).
size
).
to
eq
(
0
)
expect
(
config_processor
.
pipeline_stage_builds
(
"test"
,
test_pipeline
).
size
).
to
eq
(
0
)
expect
(
config_processor
.
pipeline_stage_builds
(
"deploy"
,
pipeline
(
ref:
"master"
)
).
size
).
to
eq
(
0
)
expect
(
config_processor
.
pipeline_stage_builds
(
"deploy"
,
master_pipeline
).
size
).
to
eq
(
0
)
end
end
context
'for invalid value'
do
context
'for invalid value'
do
...
...
spec/models/ci/pipeline_spec.rb
View file @
d79ad28f
...
@@ -26,6 +26,7 @@ describe Ci::Pipeline, :mailer do
...
@@ -26,6 +26,7 @@ describe Ci::Pipeline, :mailer do
it
{
is_expected
.
to
respond_to
:git_author_name
}
it
{
is_expected
.
to
respond_to
:git_author_name
}
it
{
is_expected
.
to
respond_to
:git_author_email
}
it
{
is_expected
.
to
respond_to
:git_author_email
}
it
{
is_expected
.
to
respond_to
:short_sha
}
it
{
is_expected
.
to
respond_to
:short_sha
}
it
{
is_expected
.
to
delegate_method
(
:full_path
).
to
(
:project
).
with_prefix
}
describe
'#source'
do
describe
'#source'
do
context
'when creating new pipeline'
do
context
'when creating new pipeline'
do
...
...
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