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
b40d5d0f
Commit
b40d5d0f
authored
6 years ago
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix static analysis and tests related to YAML processing
parent
b9e32976
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
103 additions
and
67 deletions
+103
-67
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+1
-1
lib/gitlab/ci/yaml_processor.rb
lib/gitlab/ci/yaml_processor.rb
+14
-30
spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
+14
-14
spec/lib/gitlab/ci/yaml_processor_spec.rb
spec/lib/gitlab/ci/yaml_processor_spec.rb
+73
-22
spec/views/ci/lints/show.html.haml_spec.rb
spec/views/ci/lints/show.html.haml_spec.rb
+1
-0
No files found.
app/models/ci/pipeline.rb
View file @
b40d5d0f
...
@@ -363,7 +363,7 @@ module Ci
...
@@ -363,7 +363,7 @@ module Ci
return
[]
unless
config_processor
return
[]
unless
config_processor
strong_memoize
(
:stage_seeds
)
do
strong_memoize
(
:stage_seeds
)
do
seeds
=
config_processor
.
stages
.
map
do
|
attributes
|
seeds
=
config_processor
.
stages
_attributes
.
map
do
|
attributes
|
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Stage
.
new
(
self
,
attributes
)
Gitlab
::
Ci
::
Pipeline
::
Seed
::
Stage
.
new
(
self
,
attributes
)
end
end
...
...
This diff is collapsed.
Click to expand it.
lib/gitlab/ci/yaml_processor.rb
View file @
b40d5d0f
...
@@ -27,7 +27,7 @@ module Gitlab
...
@@ -27,7 +27,7 @@ module Gitlab
end
end
def
build_attributes
(
name
)
def
build_attributes
(
name
)
job
=
@jobs
[
name
.
to_sym
]
||
{}
job
=
@jobs
.
fetch
(
name
.
to_sym
,
{})
{
stage_idx:
@stages
.
index
(
job
[
:stage
]),
{
stage_idx:
@stages
.
index
(
job
[
:stage
]),
stage:
job
[
:stage
],
stage:
job
[
:stage
],
...
@@ -53,39 +53,23 @@ module Gitlab
...
@@ -53,39 +53,23 @@ module Gitlab
}.
compact
}
}.
compact
}
end
end
# REFACTORING, this needs improvement, and specs
def
stage_builds_attributes
(
stage
)
#
@jobs
.
values
def
stage_attributes
(
stage
)
.
select
{
|
job
|
job
[
:stage
]
==
stage
}
selected
=
@jobs
.
values
.
select
do
|
job
|
.
map
{
|
job
|
build_attributes
(
job
[
:name
])
}
job
[
:stage
]
==
stage
end
selected
.
map
do
|
job
|
build_attributes
(
job
[
:name
])
end
end
end
# REFACTORING, needs specs
def
stages_attributes
#
@stages
.
uniq
.
map
do
|
stage
|
def
seed_attributes
(
stage
)
seeds
=
stage_builds_attributes
(
stage
).
map
do
|
attributes
|
seeds
=
stage_attributes
(
stage
).
map
do
|
attributes
|
job
=
@jobs
.
fetch
(
attributes
[
:name
].
to_sym
)
job
=
@jobs
.
fetch
(
attributes
[
:name
].
to_sym
)
attributes
.
merge
(
only:
job
.
fetch
(
:only
,
{}))
.
merge
(
except:
job
.
fetch
(
:except
,
{}))
end
{
name:
stage
,
attributes
index:
@stages
.
index
(
stage
),
.
merge
(
only:
job
.
fetch
(
:only
,
{}))
builds:
seeds
}
.
merge
(
except:
job
.
fetch
(
:except
,
{}))
end
end
# REFACTORING, needs specs
{
name:
stage
,
index:
@stages
.
index
(
stage
),
builds:
seeds
}
#
def
stages
@stages
.
uniq
.
map
do
|
stage
|
seed_attributes
(
stage
)
end
end
end
end
...
...
This diff is collapsed.
Click to expand it.
spec/lib/gitlab/ci/pipeline/seed/build_spec.rb
View file @
b40d5d0f
...
@@ -89,13 +89,13 @@ describe Gitlab::Ci::Pipeline::Seed::Build do
...
@@ -89,13 +89,13 @@ describe Gitlab::Ci::Pipeline::Seed::Build do
context
'when branch policy matches'
do
context
'when branch policy matches'
do
context
'when using only'
do
context
'when using only'
do
let
(
:attributes
)
{
{
name:
'rspec'
,
only:
{
refs:
[
'deploy'
,
'master'
]
}
}
}
let
(
:attributes
)
{
{
name:
'rspec'
,
only:
{
refs:
%w[deploy master
]
}
}
}
it
{
is_expected
.
to
be_included
}
it
{
is_expected
.
to
be_included
}
end
end
context
'when using except'
do
context
'when using except'
do
let
(
:attributes
)
{
{
name:
'rspec'
,
except:
{
refs:
[
'deploy'
,
'master'
]
}
}
}
let
(
:attributes
)
{
{
name:
'rspec'
,
except:
{
refs:
%w[deploy master
]
}
}
}
it
{
is_expected
.
not_to
be_included
}
it
{
is_expected
.
not_to
be_included
}
end
end
...
@@ -130,12 +130,12 @@ describe Gitlab::Ci::Pipeline::Seed::Build do
...
@@ -130,12 +130,12 @@ describe Gitlab::Ci::Pipeline::Seed::Build do
end
end
context
'when keywords and pipeline source policy matches'
do
context
'when keywords and pipeline source policy matches'
do
possibilities
=
[
[
'pushes'
,
'push'
],
possibilities
=
[
%w[pushes push
]
,
[
'web'
,
'web'
],
%w[web web
]
,
[
'triggers'
,
'trigger'
],
%w[triggers trigger
]
,
[
'schedules'
,
'schedule'
],
%w[schedules schedule
]
,
[
'api'
,
'api'
],
%w[api api
]
,
[
'external'
,
'external'
]]
%w[external external
]
]
context
'when using only'
do
context
'when using only'
do
possibilities
.
each
do
|
keyword
,
source
|
possibilities
.
each
do
|
keyword
,
source
|
...
@@ -167,12 +167,12 @@ describe Gitlab::Ci::Pipeline::Seed::Build do
...
@@ -167,12 +167,12 @@ describe Gitlab::Ci::Pipeline::Seed::Build do
end
end
context
'when keywords and pipeline source does not match'
do
context
'when keywords and pipeline source does not match'
do
possibilities
=
[
[
'pushes'
,
'web'
],
possibilities
=
[
%w[pushes web
]
,
[
'web'
,
'push'
],
%w[web push
]
,
[
'triggers'
,
'schedule'
],
%w[triggers schedule
]
,
[
'schedules'
,
'external'
],
%w[schedules external
]
,
[
'api'
,
'trigger'
],
%w[api trigger
]
,
[
'external'
,
'api'
]]
%w[external api
]
]
context
'when using only'
do
context
'when using only'
do
possibilities
.
each
do
|
keyword
,
source
|
possibilities
.
each
do
|
keyword
,
source
|
...
...
This diff is collapsed.
Click to expand it.
spec/lib/gitlab/ci/yaml_processor_spec.rb
View file @
b40d5d0f
...
@@ -133,6 +133,57 @@ module Gitlab
...
@@ -133,6 +133,57 @@ module Gitlab
end
end
end
end
describe
'#stages_attributes'
do
let
(
:config
)
do
YAML
.
dump
(
rspec:
{
script:
'rspec'
,
stage:
'test'
,
only:
[
'branches'
]
},
prod:
{
script:
'cap prod'
,
stage:
'deploy'
,
only:
[
'tags'
]
}
)
end
let
(
:attributes
)
do
[{
name:
"build"
,
index:
0
,
builds:
[]
},
{
name:
"test"
,
index:
1
,
builds:
[{
stage_idx:
1
,
stage:
"test"
,
commands:
"rspec"
,
tag_list:
[],
name:
"rspec"
,
allow_failure:
false
,
when:
"on_success"
,
environment:
nil
,
coverage_regex:
nil
,
yaml_variables:
[],
options:
{
script:
[
"rspec"
]
},
only:
{
refs:
[
"branches"
]
},
except:
{}
}]
},
{
name:
"deploy"
,
index:
2
,
builds:
[{
stage_idx:
2
,
stage:
"deploy"
,
commands:
"cap prod"
,
tag_list:
[],
name:
"prod"
,
allow_failure:
false
,
when:
"on_success"
,
environment:
nil
,
coverage_regex:
nil
,
yaml_variables:
[],
options:
{
script:
[
"cap prod"
]
},
only:
{
refs:
[
"tags"
]
},
except:
{}
}]
}]
end
it
'returns stages seed attributes'
do
expect
(
subject
.
stages_attributes
).
to
eq
attributes
end
end
describe
'only / except policies validations'
do
describe
'only / except policies validations'
do
context
'when `only` has an invalid value'
do
context
'when `only` has an invalid value'
do
let
(
:config
)
{
{
rspec:
{
script:
"rspec"
,
type:
"test"
,
only:
only
}
}
}
let
(
:config
)
{
{
rspec:
{
script:
"rspec"
,
type:
"test"
,
only:
only
}
}
}
...
@@ -203,7 +254,7 @@ module Gitlab
...
@@ -203,7 +254,7 @@ module Gitlab
let
(
:config_data
)
{
YAML
.
dump
(
config
)
}
let
(
:config_data
)
{
YAML
.
dump
(
config
)
}
let
(
:config_processor
)
{
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config_data
)
}
let
(
:config_processor
)
{
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config_data
)
}
subject
{
config_processor
.
stage_attributes
(
'test'
).
first
}
subject
{
config_processor
.
stage_
builds_
attributes
(
'test'
).
first
}
describe
"before_script"
do
describe
"before_script"
do
context
"in global context"
do
context
"in global context"
do
...
@@ -286,8 +337,8 @@ module Gitlab
...
@@ -286,8 +337,8 @@ module Gitlab
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_
builds_
attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
first
).
to
eq
({
expect
(
config_processor
.
stage_
builds_
attributes
(
"test"
).
first
).
to
eq
({
stage:
"test"
,
stage:
"test"
,
stage_idx:
1
,
stage_idx:
1
,
name:
"rspec"
,
name:
"rspec"
,
...
@@ -321,8 +372,8 @@ module Gitlab
...
@@ -321,8 +372,8 @@ module Gitlab
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_
builds_
attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
first
).
to
eq
({
expect
(
config_processor
.
stage_
builds_
attributes
(
"test"
).
first
).
to
eq
({
stage:
"test"
,
stage:
"test"
,
stage_idx:
1
,
stage_idx:
1
,
name:
"rspec"
,
name:
"rspec"
,
...
@@ -354,8 +405,8 @@ module Gitlab
...
@@ -354,8 +405,8 @@ module Gitlab
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_
builds_
attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
first
).
to
eq
({
expect
(
config_processor
.
stage_
builds_
attributes
(
"test"
).
first
).
to
eq
({
stage:
"test"
,
stage:
"test"
,
stage_idx:
1
,
stage_idx:
1
,
name:
"rspec"
,
name:
"rspec"
,
...
@@ -383,8 +434,8 @@ module Gitlab
...
@@ -383,8 +434,8 @@ module Gitlab
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_
builds_
attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
first
).
to
eq
({
expect
(
config_processor
.
stage_
builds_
attributes
(
"test"
).
first
).
to
eq
({
stage:
"test"
,
stage:
"test"
,
stage_idx:
1
,
stage_idx:
1
,
name:
"rspec"
,
name:
"rspec"
,
...
@@ -529,7 +580,7 @@ module Gitlab
...
@@ -529,7 +580,7 @@ module Gitlab
})
})
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
builds
=
config_processor
.
stage_attributes
(
"test"
)
builds
=
config_processor
.
stage_
builds_
attributes
(
"test"
)
expect
(
builds
.
size
).
to
eq
(
1
)
expect
(
builds
.
size
).
to
eq
(
1
)
expect
(
builds
.
first
[
:when
]).
to
eq
(
when_state
)
expect
(
builds
.
first
[
:when
]).
to
eq
(
when_state
)
...
@@ -561,8 +612,8 @@ module Gitlab
...
@@ -561,8 +612,8 @@ module Gitlab
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_
builds_
attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
first
[
:options
][
:cache
]).
to
eq
(
expect
(
config_processor
.
stage_
builds_
attributes
(
"test"
).
first
[
:options
][
:cache
]).
to
eq
(
paths:
[
"logs/"
,
"binaries/"
],
paths:
[
"logs/"
,
"binaries/"
],
untracked:
true
,
untracked:
true
,
key:
'key'
,
key:
'key'
,
...
@@ -580,8 +631,8 @@ module Gitlab
...
@@ -580,8 +631,8 @@ module Gitlab
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_
builds_
attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
first
[
:options
][
:cache
]).
to
eq
(
expect
(
config_processor
.
stage_
builds_
attributes
(
"test"
).
first
[
:options
][
:cache
]).
to
eq
(
paths:
[
"logs/"
,
"binaries/"
],
paths:
[
"logs/"
,
"binaries/"
],
untracked:
true
,
untracked:
true
,
key:
'key'
,
key:
'key'
,
...
@@ -600,8 +651,8 @@ module Gitlab
...
@@ -600,8 +651,8 @@ module Gitlab
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_
builds_
attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
first
[
:options
][
:cache
]).
to
eq
(
expect
(
config_processor
.
stage_
builds_
attributes
(
"test"
).
first
[
:options
][
:cache
]).
to
eq
(
paths:
[
"test/"
],
paths:
[
"test/"
],
untracked:
false
,
untracked:
false
,
key:
'local'
,
key:
'local'
,
...
@@ -629,8 +680,8 @@ module Gitlab
...
@@ -629,8 +680,8 @@ module Gitlab
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_
builds_
attributes
(
"test"
).
size
).
to
eq
(
1
)
expect
(
config_processor
.
stage_attributes
(
"test"
).
first
).
to
eq
({
expect
(
config_processor
.
stage_
builds_
attributes
(
"test"
).
first
).
to
eq
({
stage:
"test"
,
stage:
"test"
,
stage_idx:
1
,
stage_idx:
1
,
name:
"rspec"
,
name:
"rspec"
,
...
@@ -666,7 +717,7 @@ module Gitlab
...
@@ -666,7 +717,7 @@ module Gitlab
})
})
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
config_processor
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
builds
=
config_processor
.
stage_attributes
(
"test"
)
builds
=
config_processor
.
stage_
builds_
attributes
(
"test"
)
expect
(
builds
.
size
).
to
eq
(
1
)
expect
(
builds
.
size
).
to
eq
(
1
)
expect
(
builds
.
first
[
:options
][
:artifacts
][
:when
]).
to
eq
(
when_state
)
expect
(
builds
.
first
[
:options
][
:artifacts
][
:when
]).
to
eq
(
when_state
)
...
@@ -682,7 +733,7 @@ module Gitlab
...
@@ -682,7 +733,7 @@ module Gitlab
end
end
let
(
:processor
)
{
Gitlab
::
Ci
::
YamlProcessor
.
new
(
YAML
.
dump
(
config
))
}
let
(
:processor
)
{
Gitlab
::
Ci
::
YamlProcessor
.
new
(
YAML
.
dump
(
config
))
}
let
(
:builds
)
{
processor
.
stage_attributes
(
'deploy'
)
}
let
(
:builds
)
{
processor
.
stage_
builds_
attributes
(
'deploy'
)
}
context
'when a production environment is specified'
do
context
'when a production environment is specified'
do
let
(
:environment
)
{
'production'
}
let
(
:environment
)
{
'production'
}
...
@@ -839,7 +890,7 @@ module Gitlab
...
@@ -839,7 +890,7 @@ module Gitlab
describe
"Hidden jobs"
do
describe
"Hidden jobs"
do
let
(
:config_processor
)
{
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
}
let
(
:config_processor
)
{
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
}
subject
{
config_processor
.
stage_attributes
(
"test"
)
}
subject
{
config_processor
.
stage_
builds_
attributes
(
"test"
)
}
shared_examples
'hidden_job_handling'
do
shared_examples
'hidden_job_handling'
do
it
"doesn't create jobs that start with dot"
do
it
"doesn't create jobs that start with dot"
do
...
@@ -887,7 +938,7 @@ module Gitlab
...
@@ -887,7 +938,7 @@ module Gitlab
describe
"YAML Alias/Anchor"
do
describe
"YAML Alias/Anchor"
do
let
(
:config_processor
)
{
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
}
let
(
:config_processor
)
{
Gitlab
::
Ci
::
YamlProcessor
.
new
(
config
)
}
subject
{
config_processor
.
stage_attributes
(
"build"
)
}
subject
{
config_processor
.
stage_
builds_
attributes
(
"build"
)
}
shared_examples
'job_templates_handling'
do
shared_examples
'job_templates_handling'
do
it
"is correctly supported for jobs"
do
it
"is correctly supported for jobs"
do
...
...
This diff is collapsed.
Click to expand it.
spec/views/ci/lints/show.html.haml_spec.rb
View file @
b40d5d0f
...
@@ -5,6 +5,7 @@ describe 'ci/lints/show' do
...
@@ -5,6 +5,7 @@ describe 'ci/lints/show' do
describe
'XSS protection'
do
describe
'XSS protection'
do
let
(
:config_processor
)
{
Gitlab
::
Ci
::
YamlProcessor
.
new
(
YAML
.
dump
(
content
))
}
let
(
:config_processor
)
{
Gitlab
::
Ci
::
YamlProcessor
.
new
(
YAML
.
dump
(
content
))
}
before
do
before
do
assign
(
:status
,
true
)
assign
(
:status
,
true
)
assign
(
:builds
,
config_processor
.
builds
)
assign
(
:builds
,
config_processor
.
builds
)
...
...
This diff is collapsed.
Click to expand it.
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