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
Boxiang Sun
gitlab-ce
Commits
70f508f5
Commit
70f508f5
authored
Jul 14, 2016
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Serve artifacts from Builds
parent
a9a8ceeb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
43 deletions
+35
-43
lib/api/api.rb
lib/api/api.rb
+0
-1
lib/api/artifacts.rb
lib/api/artifacts.rb
+0
-34
lib/api/builds.rb
lib/api/builds.rb
+31
-4
spec/requests/api/artifacts_spec.rb
spec/requests/api/artifacts_spec.rb
+3
-3
spec/requests/api/builds_spec.rb
spec/requests/api/builds_spec.rb
+1
-1
No files found.
lib/api/api.rb
View file @
70f508f5
...
@@ -26,7 +26,6 @@ module API
...
@@ -26,7 +26,6 @@ module API
# Ensure the namespace is right, otherwise we might load Grape::API::Helpers
# Ensure the namespace is right, otherwise we might load Grape::API::Helpers
helpers
::
API
::
Helpers
helpers
::
API
::
Helpers
mount
::
API
::
Artifacts
mount
::
API
::
AwardEmoji
mount
::
API
::
AwardEmoji
mount
::
API
::
Branches
mount
::
API
::
Branches
mount
::
API
::
Builds
mount
::
API
::
Builds
...
...
lib/api/artifacts.rb
deleted
100644 → 0
View file @
a9a8ceeb
module
API
# Projects artifacts API
class
Artifacts
<
Grape
::
API
before
do
authenticate!
authorize!
(
:read_build
,
user_project
)
end
resource
:projects
do
# Download the artifacts file from ref_name and build_name
#
# Parameters:
# id (required) - The ID of a project
# ref_name (required) - The ref from repository
# build_name (required) - The name for the build
# Example Request:
# GET /projects/:id/artifacts/:ref_name/:build_name
get
':id/artifacts/:ref_name/:build_name'
,
requirements:
{
ref_name:
/.+/
}
do
builds
=
user_project
.
builds_for
(
params
[
:build_name
],
params
[
:ref_name
])
latest_build
=
builds
.
success
.
latest
.
first
if
latest_build
redirect
(
"/projects/
#{
user_project
.
id
}
/builds/
#{
latest_build
.
id
}
/artifacts"
)
else
not_found!
end
end
end
end
end
lib/api/builds.rb
View file @
70f508f5
...
@@ -71,12 +71,27 @@ module API
...
@@ -71,12 +71,27 @@ module API
build
=
get_build!
(
params
[
:build_id
])
build
=
get_build!
(
params
[
:build_id
])
artifacts_file
=
build
.
artifacts_file
artifacts_file
=
build
.
artifacts_file
if
!
artifacts_file
.
file_storage?
present_artifact!
(
artifacts_file
)
redirect_to
(
build
.
artifacts_file
.
url
)
end
elsif
artifacts_file
.
exists?
# Download the artifacts file from ref_name and build_name
present_file!
(
artifacts_file
.
path
,
artifacts_file
.
filename
)
#
# Parameters:
# id (required) - The ID of a project
# ref_name (required) - The ref from repository
# job (required) - The name for the build
# Example Request:
# GET /projects/:id/artifacts/:ref_name/:build_name
get
':id/builds/artifacts/:ref_name'
,
requirements:
{
ref_name:
/.+/
}
do
builds
=
user_project
.
builds_for
(
params
[
:job
],
params
[
:ref_name
])
latest_build
=
builds
.
success
.
latest
.
first
if
latest_build
redirect
(
"/projects/
#{
user_project
.
id
}
/builds/
#{
latest_build
.
id
}
/artifacts"
)
else
else
not_found!
not_found!
end
end
...
@@ -191,6 +206,18 @@ module API
...
@@ -191,6 +206,18 @@ module API
get_build
(
id
)
||
not_found!
get_build
(
id
)
||
not_found!
end
end
def
present_artifact!
(
artifacts_file
)
if
!
artifacts_file
.
file_storage?
redirect_to
(
build
.
artifacts_file
.
url
)
elsif
artifacts_file
.
exists?
present_file!
(
artifacts_file
.
path
,
artifacts_file
.
filename
)
else
not_found!
end
end
def
filter_builds
(
builds
,
scope
)
def
filter_builds
(
builds
,
scope
)
return
builds
if
scope
.
nil?
||
scope
.
empty?
return
builds
if
scope
.
nil?
||
scope
.
empty?
...
...
spec/requests/api/artifacts_spec.rb
View file @
70f508f5
require
'spec_helper'
require
'spec_helper'
require_relative
'../shared/artifacts_context'
require_relative
'../shared/artifacts_context'
describe
API
::
API
,
api:
true
do
describe
API
::
API
,
api:
true
do
include
ApiHelpers
include
ApiHelpers
describe
'GET /projects/:id/artifacts/:ref_name/:build_name'
do
describe
'GET /projects/:id/artifacts/:ref_name/:build_name'
do
include_context
'artifacts from ref and build name'
include_context
'artifacts from ref and build name'
def
path_from_ref
(
ref
=
pipeline
.
sha
,
build_name
=
build
.
name
,
_
=
''
)
def
path_from_ref
(
ref
=
pipeline
.
sha
,
job
=
build
.
name
)
api
(
"/projects/
#{
project
.
id
}
/
artifacts/
#{
ref
}
/
#{
build_name
}
"
,
user
)
api
(
"/projects/
#{
project
.
id
}
/
builds/artifacts/
#{
ref
}
?job=
#{
job
}
"
,
user
)
end
end
context
'401'
do
context
'401'
do
...
...
spec/requests/api/builds_spec.rb
View file @
70f508f5
require
'spec_helper'
require
'spec_helper'
describe
API
::
API
,
api:
true
do
describe
API
::
API
,
api:
true
do
include
ApiHelpers
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
...
...
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