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
8fe708f4
Commit
8fe708f4
authored
Dec 13, 2016
by
Leandro Camargo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make more code improvements around the '/' stripping logic
parent
518fd2eb
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
35 additions
and
37 deletions
+35
-37
app/models/ci/build.rb
app/models/ci/build.rb
+13
-22
lib/gitlab/ci/config/entry/coverage.rb
lib/gitlab/ci/config/entry/coverage.rb
+4
-0
lib/gitlab/ci/config/entry/validators.rb
lib/gitlab/ci/config/entry/validators.rb
+4
-8
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+9
-2
spec/lib/gitlab/ci/config/entry/coverage_spec.rb
spec/lib/gitlab/ci/config/entry/coverage_spec.rb
+1
-1
spec/lib/gitlab/ci/config/entry/global_spec.rb
spec/lib/gitlab/ci/config/entry/global_spec.rb
+2
-2
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+2
-2
No files found.
app/models/ci/build.rb
View file @
8fe708f4
...
...
@@ -275,19 +275,13 @@ module Ci
end
def
update_coverage
regex
=
coverage_regex
return
unless
regex
coverage
=
extract_coverage
(
trace
,
regex
[
1
...-
1
])
if
coverage
.
is_a?
Numeric
update_attributes
(
coverage:
coverage
)
end
coverage
=
extract_coverage
(
trace
,
coverage_regex
)
update_attributes
(
coverage:
coverage
)
if
coverage
.
is_a?
(
Numeric
)
end
def
extract_coverage
(
text
,
regex
)
begin
return
unless
regex
matches
=
text
.
scan
(
Regexp
.
new
(
regex
)).
last
matches
=
matches
.
last
if
matches
.
kind_of?
(
Array
)
coverage
=
matches
.
gsub
(
/\d+(\.\d+)?/
).
first
...
...
@@ -299,7 +293,6 @@ module Ci
# if bad regex or something goes wrong we dont want to interrupt transition
# so we just silentrly ignore error for now
end
end
def
has_trace_file?
File
.
exist?
(
path_to_trace
)
||
has_old_trace_file?
...
...
@@ -524,9 +517,7 @@ module Ci
end
def
coverage_regex
super
||
project
.
try
(
:build_coverage_regex
).
presence
&&
"/
#{
project
.
build_coverage_regex
}
/"
super
||
project
.
try
(
:build_coverage_regex
)
end
def
when
...
...
lib/gitlab/ci/config/entry/coverage.rb
View file @
8fe708f4
...
...
@@ -11,6 +11,10 @@ module Gitlab
validations
do
validates
:config
,
regexp:
true
end
def
value
@config
[
1
...-
1
]
end
end
end
end
...
...
lib/gitlab/ci/config/entry/validators.rb
View file @
8fe708f4
...
...
@@ -66,7 +66,7 @@ module Gitlab
private
def
look_like_regexp?
(
value
)
value
=~
%r{
\A
/.*/
\z
}
value
.
start_with?
(
'/'
)
&&
value
.
end_with?
(
'/'
)
end
def
validate_regexp
(
value
)
...
...
@@ -78,7 +78,7 @@ module Gitlab
end
end
class
ArrayOfStringsOrRegexps
<
RegexpValidator
class
ArrayOfStringsOrRegexps
Validator
<
RegexpValidator
def
validate_each
(
record
,
attribute
,
value
)
unless
validate_array_of_strings_or_regexps
(
value
)
record
.
errors
.
add
(
attribute
,
'should be an array of strings or regexps'
)
...
...
@@ -94,14 +94,10 @@ module Gitlab
def
validate_string_or_regexp
(
value
)
return
true
if
value
.
is_a?
(
Symbol
)
return
false
unless
value
.
is_a?
(
String
)
if
look_like_regexp?
(
value
)
validate_regexp
(
value
)
else
return
validate_regexp
(
value
)
if
look_like_regexp?
(
value
)
true
end
end
end
class
TypeValidator
<
ActiveModel
::
EachValidator
def
validate_each
(
record
,
attribute
,
value
)
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
8fe708f4
...
...
@@ -17,7 +17,7 @@ module Ci
end
context
"and 'rspec' job doesn't have coverage set"
do
it
{
is_expected
.
to
include
(
coverage_regex:
'
/\(\d+\.\d+\) covered/
'
)
}
it
{
is_expected
.
to
include
(
coverage_regex:
'
\(\d+\.\d+\) covered
'
)
}
end
context
"but 'rspec' job also has coverage set"
do
...
...
@@ -25,7 +25,7 @@ module Ci
config_base
[
:rspec
][
:coverage
]
=
'/Code coverage: \d+\.\d+/'
end
it
{
is_expected
.
to
include
(
coverage_regex:
'
/Code coverage: \d+\.\d+/
'
)
}
it
{
is_expected
.
to
include
(
coverage_regex:
'
Code coverage: \d+\.\d+
'
)
}
end
end
end
...
...
@@ -48,6 +48,7 @@ module Ci
stage_idx:
1
,
name:
"rspec"
,
commands:
"pwd
\n
rspec"
,
coverage_regex:
nil
,
tag_list:
[],
options:
{},
allow_failure:
false
,
...
...
@@ -462,6 +463,7 @@ module Ci
stage_idx:
1
,
name:
"rspec"
,
commands:
"pwd
\n
rspec"
,
coverage_regex:
nil
,
tag_list:
[],
options:
{
image:
"ruby:2.1"
,
...
...
@@ -490,6 +492,7 @@ module Ci
stage_idx:
1
,
name:
"rspec"
,
commands:
"pwd
\n
rspec"
,
coverage_regex:
nil
,
tag_list:
[],
options:
{
image:
"ruby:2.5"
,
...
...
@@ -729,6 +732,7 @@ module Ci
stage_idx:
1
,
name:
"rspec"
,
commands:
"pwd
\n
rspec"
,
coverage_regex:
nil
,
tag_list:
[],
options:
{
image:
"ruby:2.1"
,
...
...
@@ -940,6 +944,7 @@ module Ci
stage_idx:
1
,
name:
"normal_job"
,
commands:
"test"
,
coverage_regex:
nil
,
tag_list:
[],
options:
{},
when:
"on_success"
,
...
...
@@ -985,6 +990,7 @@ module Ci
stage_idx:
0
,
name:
"job1"
,
commands:
"execute-script-for-job"
,
coverage_regex:
nil
,
tag_list:
[],
options:
{},
when:
"on_success"
,
...
...
@@ -997,6 +1003,7 @@ module Ci
stage_idx:
0
,
name:
"job2"
,
commands:
"execute-script-for-job"
,
coverage_regex:
nil
,
tag_list:
[],
options:
{},
when:
"on_success"
,
...
...
spec/lib/gitlab/ci/config/entry/coverage_spec.rb
View file @
8fe708f4
...
...
@@ -23,7 +23,7 @@ describe Gitlab::Ci::Config::Entry::Coverage do
describe
'#value'
do
subject
{
entry
.
value
}
it
{
is_expected
.
to
eq
(
config
)
}
it
{
is_expected
.
to
eq
(
config
[
1
...-
1
]
)
}
end
describe
'#errors'
do
...
...
spec/lib/gitlab/ci/config/entry/global_spec.rb
View file @
8fe708f4
...
...
@@ -40,7 +40,7 @@ describe Gitlab::Ci::Config::Entry::Global do
end
it
'creates node object for each entry'
do
expect
(
global
.
descendants
.
count
).
to
eq
8
expect
(
global
.
descendants
.
count
).
to
eq
9
end
it
'creates node object using valid class'
do
...
...
@@ -181,7 +181,7 @@ describe Gitlab::Ci::Config::Entry::Global do
describe
'#nodes'
do
it
'instantizes all nodes'
do
expect
(
global
.
descendants
.
count
).
to
eq
8
expect
(
global
.
descendants
.
count
).
to
eq
9
end
it
'contains unspecified nodes'
do
...
...
spec/models/ci/build_spec.rb
View file @
8fe708f4
...
...
@@ -232,11 +232,11 @@ describe Ci::Build, :models do
end
context
'and coverage_regex attribute is not set'
do
it
{
is_expected
.
to
eq
(
"/
#{
project_regex
}
/"
)
}
it
{
is_expected
.
to
eq
(
project_regex
)
}
end
context
'but coverage_regex attribute is also set'
do
let
(
:build_regex
)
{
'
/Code coverage: \d+\.\d+/
'
}
let
(
:build_regex
)
{
'
Code coverage: \d+\.\d+
'
}
before
do
build
.
coverage_regex
=
build_regex
...
...
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