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
Kazuhiko Shiozaki
gitlab-ce
Commits
e8995f9f
Commit
e8995f9f
authored
Jan 12, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify artifacts upload API endpoint, add artifacts metadata
parent
cf00a808
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
4 deletions
+42
-4
lib/ci/api/builds.rb
lib/ci/api/builds.rb
+16
-4
lib/ci/api/entities.rb
lib/ci/api/entities.rb
+1
-0
spec/requests/ci/api/builds_spec.rb
spec/requests/ci/api/builds_spec.rb
+25
-0
No files found.
lib/ci/api/builds.rb
View file @
e8995f9f
...
@@ -78,11 +78,15 @@ module Ci
...
@@ -78,11 +78,15 @@ module Ci
# Parameters:
# Parameters:
# id (required) - The ID of a build
# id (required) - The ID of a build
# token (required) - The build authorization token
# token (required) - The build authorization token
# file (required) - The uploaded file
# file (required) - Artifacts file
# metadata (optional) - Artifacts metadata file
# Parameters (accelerated by GitLab Workhorse):
# Parameters (accelerated by GitLab Workhorse):
# file.path - path to locally stored body (generated by Workhorse)
# file.path - path to locally stored body (generated by Workhorse)
# file.name - real filename as send in Content-Disposition
# file.name - real filename as send in Content-Disposition
# file.type - real content type as send in Content-Type
# file.type - real content type as send in Content-Type
# metadata.path - path to locally stored body (generated by Workhorse)
# metadata.name - real filename as send in Content-Disposition
# metadata.type - real content type as send in Content-Type
# Headers:
# Headers:
# BUILD-TOKEN (required) - The build authorization token, the same as token
# BUILD-TOKEN (required) - The build authorization token, the same as token
# Body:
# Body:
...
@@ -98,10 +102,17 @@ module Ci
...
@@ -98,10 +102,17 @@ module Ci
authenticate_build_token!
(
build
)
authenticate_build_token!
(
build
)
forbidden!
(
'build is not running'
)
unless
build
.
running?
forbidden!
(
'build is not running'
)
unless
build
.
running?
file
=
uploaded_file!
(
:file
,
ArtifactUploader
.
artifacts_upload_path
)
artifacts_upload_path
=
ArtifactUploader
.
artifacts_upload_path
file_to_large!
unless
file
.
size
<
max_artifacts_size
artifacts
=
uploaded_file!
(
:file
,
artifacts_upload_path
)
file_to_large!
unless
artifacts
.
size
<
max_artifacts_size
artifacts_attributes
=
{
artifacts_file:
artifacts
}
if
build
.
update_attributes
(
artifacts_file:
file
)
if
params
[
:metadata
]
||
params
[
'metadata.path'
.
to_sym
]
metadata
=
uploaded_file!
(
:metadata
,
artifacts_upload_path
)
artifacts_attributes
.
store
(
:artifacts_metadata
,
metadata
)
end
if
build
.
update_attributes
(
artifacts_attributes
)
present
build
,
with:
Entities
::
Build
present
build
,
with:
Entities
::
Build
else
else
render_validation_error!
(
build
)
render_validation_error!
(
build
)
...
@@ -148,6 +159,7 @@ module Ci
...
@@ -148,6 +159,7 @@ module Ci
not_found!
unless
build
not_found!
unless
build
authenticate_build_token!
(
build
)
authenticate_build_token!
(
build
)
build
.
remove_artifacts_file!
build
.
remove_artifacts_file!
build
.
remove_artifacts_metadata!
end
end
end
end
end
end
...
...
lib/ci/api/entities.rb
View file @
e8995f9f
...
@@ -31,6 +31,7 @@ module Ci
...
@@ -31,6 +31,7 @@ module Ci
expose
:variables
expose
:variables
expose
:artifacts_file
,
using:
ArtifactFile
expose
:artifacts_file
,
using:
ArtifactFile
expose
:artifacts_metadata
,
using:
ArtifactFile
end
end
class
Runner
<
Grape
::
Entity
class
Runner
<
Grape
::
Entity
...
...
spec/requests/ci/api/builds_spec.rb
View file @
e8995f9f
...
@@ -210,6 +210,31 @@ describe Ci::API::API do
...
@@ -210,6 +210,31 @@ describe Ci::API::API do
end
end
end
end
context
"should post artifacts metadata"
do
let!
(
:artifacts
)
{
file_upload
}
let!
(
:metadata
)
{
file_upload2
}
before
do
build
.
run!
post_data
=
{
'file.path'
=>
artifacts
.
path
,
'file.name'
=>
artifacts
.
original_filename
,
'metadata.path'
=>
metadata
.
path
,
'metadata.name'
=>
metadata
.
original_filename
}
post
post_url
,
post_data
,
headers_with_token
end
it
'stores artifacts and artifacts metadata'
do
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
json_response
[
'artifacts_file'
][
'filename'
]).
to
eq
(
artifacts
.
original_filename
)
expect
(
json_response
[
'artifacts_metadata'
][
'filename'
]).
to
eq
(
metadata
.
original_filename
)
end
end
context
"should fail to post too large artifact"
do
context
"should fail to post too large artifact"
do
before
do
before
do
build
.
run!
build
.
run!
...
...
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