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
Tatuya Kamada
gitlab-ce
Commits
32b09b88
Commit
32b09b88
authored
Mar 07, 2017
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add minor refactoring
parent
0905fe4d
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
63 additions
and
47 deletions
+63
-47
app/models/ci/build.rb
app/models/ci/build.rb
+2
-4
lib/api/runner.rb
lib/api/runner.rb
+1
-1
lib/gitlab/ci/build/image.rb
lib/gitlab/ci/build/image.rb
+1
-2
lib/gitlab/ci/build/step.rb
lib/gitlab/ci/build/step.rb
+6
-16
spec/lib/gitlab/ci/build/image_spec.rb
spec/lib/gitlab/ci/build/image_spec.rb
+26
-11
spec/lib/gitlab/ci/build/step_spec.rb
spec/lib/gitlab/ci/build/step_spec.rb
+17
-11
spec/requests/api/runner_spec.rb
spec/requests/api/runner_spec.rb
+10
-2
No files found.
app/models/ci/build.rb
View file @
32b09b88
...
...
@@ -509,10 +509,8 @@ module Ci
end
def
steps
[
Gitlab
::
Ci
::
Build
::
Step
.
from_commands
(
self
),
Gitlab
::
Ci
::
Build
::
Step
.
from_after_script
(
self
)
].
compact
[
Gitlab
::
Ci
::
Build
::
Step
.
from_commands
(
self
),
Gitlab
::
Ci
::
Build
::
Step
.
from_after_script
(
self
)].
compact
end
def
image
...
...
lib/api/runner.rb
View file @
32b09b88
...
...
@@ -115,7 +115,7 @@ module API
end
end
desc
'Appends a patch to the job
.
trace'
do
desc
'Appends a patch to the job
trace'
do
http_codes
[[
202
,
'Trace was patched'
],
[
400
,
'Missing Content-Range header'
],
[
403
,
'Forbidden'
],
...
...
lib/gitlab/ci/build/image.rb
View file @
32b09b88
...
...
@@ -21,8 +21,7 @@ module Gitlab
end
def
initialize
(
image
)
type
=
image
.
class
@name
=
image
if
type
==
String
@name
=
image
end
def
valid?
...
...
lib/gitlab/ci/build/step.rb
View file @
32b09b88
...
...
@@ -6,7 +6,9 @@ module Gitlab
WHEN_ON_SUCCESS
=
'on_success'
.
freeze
WHEN_ALWAYS
=
'always'
.
freeze
attr_reader
:name
,
:script
,
:timeout
,
:when
,
:allow_failure
attr_reader
:name
attr_writer
:script
attr_accessor
:timeout
,
:when
,
:allow_failure
class
<<
self
def
from_commands
(
job
)
...
...
@@ -25,7 +27,7 @@ module Gitlab
step
.
script
=
after_script
step
.
timeout
=
job
.
timeout
step
.
when
=
WHEN_ALWAYS
step
.
allow_failure
_on
step
.
allow_failure
=
true
end
end
end
...
...
@@ -35,20 +37,8 @@ module Gitlab
@allow_failure
=
false
end
def
script
=
(
script
)
@script
=
script
.
split
(
"
\n
"
)
end
def
timeout
=
(
timeout
)
@timeout
=
timeout
end
def
when
=
(
when_condition
)
@when
=
when_condition
end
def
allow_failure_on
@allow_failure
=
true
def
script
@script
.
split
(
"
\n
"
)
end
end
end
...
...
spec/lib/gitlab/ci/build/image_spec.rb
View file @
32b09b88
...
...
@@ -10,18 +10,27 @@ describe Gitlab::Ci::Build::Image do
let
(
:image_name
)
{
'ruby:2.1'
}
let
(
:job
)
{
create
(
:ci_build
,
options:
{
image:
image_name
}
)
}
it
{
is_expected
.
to
be_kind_of
(
described_class
)
}
it
{
expect
(
subject
.
name
).
to
eq
(
image_name
)
}
it
'fabricates an object of the proper class'
do
is_expected
.
to
be_kind_of
(
described_class
)
end
it
'populates fabricated object with the proper name attribute'
do
expect
(
subject
.
name
).
to
eq
(
image_name
)
end
context
'when image name is empty'
do
let
(
:image_name
)
{
''
}
it
{
is_expected
.
to
eq
(
nil
)
}
it
'does not fabricate an object'
do
is_expected
.
to
be_nil
end
end
end
context
'when image is not defined in job'
do
it
{
is_expected
.
to
eq
(
nil
)
}
it
'does not fabricate an object'
do
is_expected
.
to
be_nil
end
end
end
...
...
@@ -32,21 +41,27 @@ describe Gitlab::Ci::Build::Image do
let
(
:service_image_name
)
{
'postgres'
}
let
(
:job
)
{
create
(
:ci_build
,
options:
{
services:
[
service_image_name
]
})
}
it
{
is_expected
.
to
be_kind_of
(
Array
)
}
it
{
is_expected
.
not_to
be_empty
}
it
{
expect
(
subject
[
0
].
name
).
to
eq
(
service_image_name
)
}
it
'fabricates an non-empty array of objects'
do
is_expected
.
to
be_kind_of
(
Array
)
is_expected
.
not_to
be_empty
expect
(
subject
.
first
.
name
).
to
eq
(
service_image_name
)
end
context
'when service image name is empty'
do
let
(
:service_image_name
)
{
''
}
it
{
is_expected
.
to
be_kind_of
(
Array
)
}
it
{
is_expected
.
to
be_empty
}
it
'fabricates an empty array'
do
is_expected
.
to
be_kind_of
(
Array
)
is_expected
.
to
be_empty
end
end
end
context
'when services are not defined in job'
do
it
{
is_expected
.
to
be_kind_of
(
Array
)
}
it
{
is_expected
.
to
be_empty
}
it
'fabricates an empty array'
do
is_expected
.
to
be_kind_of
(
Array
)
is_expected
.
to
be_empty
end
end
end
end
spec/lib/gitlab/ci/build/step_spec.rb
View file @
32b09b88
...
...
@@ -6,28 +6,34 @@ describe Gitlab::Ci::Build::Step do
describe
'#from_commands'
do
subject
{
described_class
.
from_commands
(
job
)
}
it
{
expect
(
subject
.
name
).
to
eq
(
:script
)
}
it
{
expect
(
subject
.
script
).
to
eq
([
'ls -la'
,
'date'
])
}
it
{
expect
(
subject
.
timeout
).
to
eq
(
job
.
timeout
)
}
it
{
expect
(
subject
.
when
).
to
eq
(
'on_success'
)
}
it
{
expect
(
subject
.
allow_failure
).
to
be_falsey
}
it
'fabricates an object'
do
expect
(
subject
.
name
).
to
eq
(
:script
)
expect
(
subject
.
script
).
to
eq
([
'ls -la'
,
'date'
])
expect
(
subject
.
timeout
).
to
eq
(
job
.
timeout
)
expect
(
subject
.
when
).
to
eq
(
'on_success'
)
expect
(
subject
.
allow_failure
).
to
be_falsey
end
end
describe
'#from_after_script'
do
subject
{
described_class
.
from_after_script
(
job
)
}
context
'when after_script is empty'
do
it
{
is_expected
.
to
be
(
nil
)
}
it
'doesn not fabricate an object'
do
is_expected
.
to
be_nil
end
end
context
'when after_script is not empty'
do
let
(
:job
)
{
create
(
:ci_build
,
options:
{
after_script:
"ls -la
\n
date"
})
}
it
{
expect
(
subject
.
name
).
to
eq
(
:after_script
)
}
it
{
expect
(
subject
.
script
).
to
eq
([
'ls -la'
,
'date'
])
}
it
{
expect
(
subject
.
timeout
).
to
eq
(
job
.
timeout
)
}
it
{
expect
(
subject
.
when
).
to
eq
(
'always'
)
}
it
{
expect
(
subject
.
allow_failure
).
to
be_truthy
}
it
'fabricates an object'
do
expect
(
subject
.
name
).
to
eq
(
:after_script
)
expect
(
subject
.
script
).
to
eq
([
'ls -la'
,
'date'
])
expect
(
subject
.
timeout
).
to
eq
(
job
.
timeout
)
expect
(
subject
.
when
).
to
eq
(
'always'
)
expect
(
subject
.
allow_failure
).
to
be_truthy
end
end
end
end
spec/requests/api/runner_spec.rb
View file @
32b09b88
...
...
@@ -155,7 +155,10 @@ describe API::Runner do
let
(
:project
)
{
create
(
:empty_project
,
shared_runners_enabled:
false
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline_without_jobs
,
project:
project
,
ref:
'master'
)
}
let
(
:runner
)
{
create
(
:ci_runner
)
}
let!
(
:job
)
{
create
(
:ci_build
,
:artifacts
,
:extended_options
,
pipeline:
pipeline
,
name:
'spinach'
,
stage:
'test'
,
stage_idx:
0
,
commands:
"ls
\n
date"
)
}
let!
(
:job
)
do
create
(
:ci_build
,
:artifacts
,
:extended_options
,
pipeline:
pipeline
,
name:
'spinach'
,
stage:
'test'
,
stage_idx:
0
,
commands:
"ls
\n
date"
)
end
before
{
project
.
runners
<<
runner
}
...
...
@@ -283,6 +286,7 @@ describe API::Runner do
'project_id'
=>
job
.
project
.
id
,
'project_name'
=>
job
.
project
.
name
}
end
let
(
:expected_git_info
)
do
{
'repo_url'
=>
job
.
repo_url
,
'ref'
=>
job
.
ref
,
...
...
@@ -290,6 +294,7 @@ describe API::Runner do
'before_sha'
=>
job
.
before_sha
,
'ref_type'
=>
'branch'
}
end
let
(
:expected_steps
)
do
[{
'name'
=>
'script'
,
'script'
=>
%w(ls date)
,
...
...
@@ -302,11 +307,13 @@ describe API::Runner do
'when'
=>
'always'
,
'allow_failure'
=>
true
}]
end
let
(
:expected_variables
)
do
[{
'key'
=>
'CI_BUILD_NAME'
,
'value'
=>
'spinach'
,
'public'
=>
true
},
{
'key'
=>
'CI_BUILD_STAGE'
,
'value'
=>
'test'
,
'public'
=>
true
},
{
'key'
=>
'DB_NAME'
,
'value'
=>
'postgres'
,
'public'
=>
true
}]
end
let
(
:expected_artifacts
)
do
[{
'name'
=>
'artifacts_file'
,
'untracked'
=>
false
,
...
...
@@ -314,13 +321,14 @@ describe API::Runner do
'when'
=>
'always'
,
'expire_in'
=>
'7d'
}]
end
let
(
:expected_cache
)
do
[{
'key'
=>
'cache_key'
,
'untracked'
=>
false
,
'paths'
=>
[
'vendor/*'
]
}]
end
it
'
start
s a job'
do
it
'
pick
s a job'
do
request_job
info:
{
platform: :darwin
}
expect
(
response
).
to
have_http_status
(
201
)
...
...
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