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
Léo-Paul Géneau
gitlab-ce
Commits
154b8ceb
Commit
154b8ceb
authored
Jan 13, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor build artifacts upload API endpoint
parent
3f0c18f8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
15 deletions
+15
-15
lib/api/helpers.rb
lib/api/helpers.rb
+3
-1
lib/ci/api/builds.rb
lib/ci/api/builds.rb
+7
-8
spec/requests/ci/api/builds_spec.rb
spec/requests/ci/api/builds_spec.rb
+5
-6
No files found.
lib/api/helpers.rb
View file @
154b8ceb
...
...
@@ -289,12 +289,14 @@ module API
# file helpers
def
uploaded_file
!
(
field
,
uploads_path
)
def
uploaded_file
(
field
,
uploads_path
)
if
params
[
field
]
bad_request!
(
"
#{
field
}
is not a file"
)
unless
params
[
field
].
respond_to?
(
:filename
)
return
params
[
field
]
end
return
nil
unless
params
[
"
#{
field
}
.path"
]
&&
params
[
"
#{
field
}
.name"
]
# sanitize file paths
# this requires all paths to exist
required_attributes!
%W(
#{
field
}
.path)
...
...
lib/ci/api/builds.rb
View file @
154b8ceb
...
...
@@ -85,7 +85,6 @@ module Ci
# file.type - real content type as send in Content-Type
# metadata.path - path to locally stored body (generated by Workhorse)
# metadata.name - filename (generated by Workhorse)
# metadata.type - content type (returned by Workhorse)
# Headers:
# BUILD-TOKEN (required) - The build authorization token, the same as token
# Body:
...
...
@@ -99,17 +98,17 @@ module Ci
build
=
Ci
::
Build
.
find_by_id
(
params
[
:id
])
not_found!
unless
build
authenticate_build_token!
(
build
)
forbidden!
(
'build is not running'
)
unless
build
.
running?
forbidden!
(
'metadata reserved for workhorse'
)
if
params
[
:metadata
]
forbidden!
(
'Build is not running!'
)
unless
build
.
running?
artifacts_upload_path
=
ArtifactUploader
.
artifacts_upload_path
artifacts
=
uploaded_file!
(
:file
,
artifacts_upload_path
)
artifacts
=
uploaded_file
(
:file
,
artifacts_upload_path
)
metadata
=
uploaded_file
(
:metadata
,
artifacts_upload_path
)
bad_request!
(
'Missing artifacts file!'
)
unless
artifacts
file_to_large!
unless
artifacts
.
size
<
max_artifacts_size
build
.
artifacts_file
=
artifacts
if
params
[
:'metadata.path'
]
&&
params
[
:'metadata.name'
]
build
.
artifacts_metadata
=
uploaded_file!
(
:metadata
,
artifacts_upload_path
)
end
build
.
artifacts_file
=
artifacts
build
.
artifacts_metadata
=
metadata
if
build
.
save
present
(
build
,
with:
Entities
::
Build
)
...
...
spec/requests/ci/api/builds_spec.rb
View file @
154b8ceb
...
...
@@ -240,17 +240,16 @@ describe Ci::API::API do
end
end
context
'
runner sends metadata file
'
do
context
'
no artifacts file in post data
'
do
let
(
:post_data
)
do
{
'
file'
=>
artifacts
,
'
metadata'
=>
metadata
}
{
'metadata'
=>
metadata
}
end
it
'is expected to respond with
forbbiden
'
do
expect
(
response
.
status
).
to
eq
(
40
3
)
it
'is expected to respond with
bad request
'
do
expect
(
response
.
status
).
to
eq
(
40
0
)
end
it
'does not store artifacts or metadata'
do
expect
(
stored_artifacts_file
).
to
be_nil
it
'does not store metadata'
do
expect
(
stored_metadata_file
).
to
be_nil
end
end
...
...
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