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
5c1aa5fb
Commit
5c1aa5fb
authored
Mar 02, 2017
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some fixes and refactoring after review
parent
1bbf2c2c
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
292 additions
and
115 deletions
+292
-115
app/models/ci/build.rb
app/models/ci/build.rb
+4
-10
lib/api/runner.rb
lib/api/runner.rb
+2
-1
lib/gitlab/ci/build/image.rb
lib/gitlab/ci/build/image.rb
+34
-0
lib/gitlab/ci/build/response/image.rb
lib/gitlab/ci/build/response/image.rb
+0
-20
lib/gitlab/ci/build/response/step.rb
lib/gitlab/ci/build/response/step.rb
+0
-44
lib/gitlab/ci/build/step.rb
lib/gitlab/ci/build/step.rb
+56
-0
spec/factories/ci/builds.rb
spec/factories/ci/builds.rb
+4
-0
spec/lib/gitlab/ci/build/image_spec.rb
spec/lib/gitlab/ci/build/image_spec.rb
+52
-0
spec/lib/gitlab/ci/build/step_spec.rb
spec/lib/gitlab/ci/build/step_spec.rb
+33
-0
spec/requests/api/runner_spec.rb
spec/requests/api/runner_spec.rb
+107
-40
No files found.
app/models/ci/build.rb
View file @
5c1aa5fb
...
...
@@ -510,23 +510,17 @@ module Ci
def
steps
[
Gitlab
::
Ci
::
Build
::
Response
::
Step
.
from_commands
(
self
),
Gitlab
::
Ci
::
Build
::
Response
::
Step
.
from_after_script
(
self
)
Gitlab
::
Ci
::
Build
::
Step
.
from_commands
(
self
),
Gitlab
::
Ci
::
Build
::
Step
.
from_after_script
(
self
)
].
compact
end
def
image
image
=
Gitlab
::
Ci
::
Build
::
Response
::
Image
.
new
(
options
[
:image
])
return
unless
image
.
valid?
image
Gitlab
::
Ci
::
Build
::
Image
.
from_image
(
self
)
end
def
services
services
=
options
[
:services
].
map
do
|
service
|
Gitlab
::
Ci
::
Build
::
Response
::
Image
.
new
(
service
)
end
services
.
select
(
&
:valid?
).
compact
Gitlab
::
Ci
::
Build
::
Image
.
from_services
(
self
)
end
def
artifacts
...
...
lib/api/runner.rb
View file @
5c1aa5fb
...
...
@@ -176,6 +176,7 @@ module API
end
desc
'Upload artifacts for job'
do
success
Entities
::
JobRequest
::
Response
http_codes
[[
201
,
'Artifact uploaded'
],
[
400
,
'Bad request'
],
[
403
,
'Forbidden'
],
...
...
@@ -186,7 +187,7 @@ module API
requires
:id
,
type:
Integer
,
desc:
%q(Job's ID)
optional
:token
,
type:
String
,
desc:
%q(Job's authentication token)
optional
:expire_in
,
type:
String
,
desc:
%q(Specify when artifacts should expire)
optional
'file'
,
type:
File
,
desc:
%q(Artifact's file)
optional
:file
,
type:
File
,
desc:
%q(Artifact's file)
optional
'file.path'
,
type:
String
,
desc:
%q(path to locally stored body (generated by Workhorse))
optional
'file.name'
,
type:
String
,
desc:
%q(real filename as send in Content-Disposition (generated by Workhorse))
optional
'file.type'
,
type:
String
,
desc:
%q(real content type as send in Content-Type (generated by Workhorse))
...
...
lib/gitlab/ci/build/image.rb
0 → 100644
View file @
5c1aa5fb
module
Gitlab
module
Ci
module
Build
class
Image
attr_reader
:name
class
<<
self
def
from_image
(
job
)
image
=
Gitlab
::
Ci
::
Build
::
Image
.
new
(
job
.
options
[
:image
])
return
unless
image
.
valid?
image
end
def
from_services
(
job
)
services
=
job
.
options
[
:services
].
to_a
.
map
do
|
service
|
Gitlab
::
Ci
::
Build
::
Image
.
new
(
service
)
end
services
.
select
(
&
:valid?
).
compact
end
end
def
initialize
(
image
)
type
=
image
.
class
@name
=
image
if
type
==
String
end
def
valid?
@name
.
present?
end
end
end
end
end
lib/gitlab/ci/build/response/image.rb
deleted
100644 → 0
View file @
1bbf2c2c
module
Gitlab
module
Ci
module
Build
module
Response
class
Image
attr_reader
:name
def
initialize
(
image
)
type
=
image
.
class
@name
=
image
if
type
==
String
end
def
valid?
@name
!=
nil
end
end
end
end
end
end
lib/gitlab/ci/build/response/step.rb
deleted
100644 → 0
View file @
1bbf2c2c
module
Gitlab
module
Ci
module
Build
module
Response
class
Step
CONDITION_ON_FAILURE
=
'on_failure'
.
freeze
CONDITION_ON_SUCCESS
=
'on_success'
.
freeze
CONDITION_ALWAYS
=
'always'
.
freeze
attr_reader
:name
,
:script
,
:when
,
:allow_failure
,
:timeout
class
<<
self
def
from_commands
(
build
)
self
.
new
(
:script
,
build
.
commands
,
build
.
timeout
,
CONDITION_ON_SUCCESS
,
false
)
end
def
from_after_script
(
build
)
after_script
=
build
.
options
[
:after_script
]
return
unless
after_script
self
.
new
(
:after_script
,
after_script
,
build
.
timeout
,
CONDITION_ALWAYS
,
true
)
end
end
def
initialize
(
name
,
script
,
timeout
,
when_condition
=
CONDITION_ON_SUCCESS
,
allow_failure
=
true
)
@name
=
name
@script
=
script
.
split
(
"
\n
"
)
@timeout
=
timeout
@when
=
when_condition
@allow_failure
=
allow_failure
end
end
end
end
end
end
lib/gitlab/ci/build/step.rb
0 → 100644
View file @
5c1aa5fb
module
Gitlab
module
Ci
module
Build
class
Step
WHEN_ON_FAILURE
=
'on_failure'
.
freeze
WHEN_ON_SUCCESS
=
'on_success'
.
freeze
WHEN_ALWAYS
=
'always'
.
freeze
attr_reader
:name
,
:script
,
:timeout
,
:when
,
:allow_failure
class
<<
self
def
from_commands
(
job
)
self
.
new
(
:script
).
tap
do
|
step
|
step
.
script
=
job
.
commands
step
.
timeout
=
job
.
timeout
step
.
when
=
WHEN_ON_SUCCESS
end
end
def
from_after_script
(
job
)
after_script
=
job
.
options
[
:after_script
]
return
unless
after_script
self
.
new
(
:after_script
).
tap
do
|
step
|
step
.
script
=
after_script
step
.
timeout
=
job
.
timeout
step
.
when
=
WHEN_ALWAYS
step
.
allow_failure_on
end
end
end
def
initialize
(
name
)
@name
=
name
@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
end
end
end
end
end
spec/factories/ci/builds.rb
View file @
5c1aa5fb
...
...
@@ -173,5 +173,9 @@ FactoryGirl.define do
}
end
end
trait
:no_options
do
options
{
{}
}
end
end
end
spec/lib/gitlab/ci/build/image_spec.rb
0 → 100644
View file @
5c1aa5fb
require
'spec_helper'
describe
Gitlab
::
Ci
::
Build
::
Image
do
let
(
:job
)
{
create
(
:ci_build
,
:no_options
)
}
describe
'#from_image'
do
subject
{
described_class
.
from_image
(
job
)
}
context
'when image is defined in job'
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
)
}
context
'when image name is empty'
do
let
(
:image_name
)
{
''
}
it
{
is_expected
.
to
eq
(
nil
)
}
end
end
context
'when image is not defined in job'
do
it
{
is_expected
.
to
eq
(
nil
)
}
end
end
describe
'#from_services'
do
subject
{
described_class
.
from_services
(
job
)
}
context
'when services are defined in job'
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
)
}
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
}
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
}
end
end
end
\ No newline at end of file
spec/lib/gitlab/ci/build/step_spec.rb
0 → 100644
View file @
5c1aa5fb
require
'spec_helper'
describe
Gitlab
::
Ci
::
Build
::
Step
do
let
(
:job
)
{
create
(
:ci_build
,
:no_options
,
commands:
"ls -la
\n
date"
)
}
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
}
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
)
}
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
}
end
end
end
\ No newline at end of file
spec/requests/api/runner_spec.rb
View file @
5c1aa5fb
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