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
8c3ba8d6
Commit
8c3ba8d6
authored
Jun 06, 2016
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add workhorse controller and API helpers
parent
3cb69f0c
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
45 additions
and
24 deletions
+45
-24
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+1
-0
app/controllers/projects/avatars_controller.rb
app/controllers/projects/avatars_controller.rb
+1
-4
app/controllers/projects/raw_controller.rb
app/controllers/projects/raw_controller.rb
+1
-4
app/controllers/projects/repositories_controller.rb
app/controllers/projects/repositories_controller.rb
+1
-2
app/helpers/workhorse_helper.rb
app/helpers/workhorse_helper.rb
+17
-0
db/schema.rb
db/schema.rb
+1
-0
lib/api/helpers.rb
lib/api/helpers.rb
+10
-0
lib/api/repositories.rb
lib/api/repositories.rb
+3
-7
lib/gitlab/workhorse.rb
lib/gitlab/workhorse.rb
+4
-4
spec/controllers/projects/raw_controller_spec.rb
spec/controllers/projects/raw_controller_spec.rb
+2
-0
spec/controllers/projects/repositories_controller_spec.rb
spec/controllers/projects/repositories_controller_spec.rb
+3
-2
spec/lib/gitlab/workhorse_spec.rb
spec/lib/gitlab/workhorse_spec.rb
+1
-1
No files found.
app/controllers/application_controller.rb
View file @
8c3ba8d6
...
@@ -6,6 +6,7 @@ class ApplicationController < ActionController::Base
...
@@ -6,6 +6,7 @@ class ApplicationController < ActionController::Base
include
Gitlab
::
GonHelper
include
Gitlab
::
GonHelper
include
GitlabRoutingHelper
include
GitlabRoutingHelper
include
PageLayoutHelper
include
PageLayoutHelper
include
WorkhorseHelper
before_action
:authenticate_user_from_token!
before_action
:authenticate_user_from_token!
before_action
:authenticate_user!
before_action
:authenticate_user!
...
...
app/controllers/projects/avatars_controller.rb
View file @
8c3ba8d6
...
@@ -10,10 +10,7 @@ class Projects::AvatarsController < Projects::ApplicationController
...
@@ -10,10 +10,7 @@ class Projects::AvatarsController < Projects::ApplicationController
return
if
cached_blob?
return
if
cached_blob?
headers
.
store
(
*
Gitlab
::
Workhorse
.
send_git_blob
(
@repository
,
@blob
))
send_git_blob
@repository
,
@blob
headers
[
'Content-Disposition'
]
=
'inline'
headers
[
'Content-Type'
]
=
safe_content_type
(
@blob
)
head
:ok
# 'render nothing: true' messes up the Content-Type
else
else
render_404
render_404
end
end
...
...
app/controllers/projects/raw_controller.rb
View file @
8c3ba8d6
...
@@ -18,10 +18,7 @@ class Projects::RawController < Projects::ApplicationController
...
@@ -18,10 +18,7 @@ class Projects::RawController < Projects::ApplicationController
if
@blob
.
lfs_pointer?
if
@blob
.
lfs_pointer?
send_lfs_object
send_lfs_object
else
else
headers
.
store
(
*
Gitlab
::
Workhorse
.
send_git_blob
(
@repository
,
@blob
))
send_git_blob
@repository
,
@blob
headers
[
'Content-Disposition'
]
=
'inline'
headers
[
'Content-Type'
]
=
safe_content_type
(
@blob
)
head
:ok
# 'render nothing: true' messes up the Content-Type
end
end
else
else
render_404
render_404
...
...
app/controllers/projects/repositories_controller.rb
View file @
8c3ba8d6
...
@@ -11,8 +11,7 @@ class Projects::RepositoriesController < Projects::ApplicationController
...
@@ -11,8 +11,7 @@ class Projects::RepositoriesController < Projects::ApplicationController
end
end
def
archive
def
archive
headers
.
store
(
*
Gitlab
::
Workhorse
.
send_git_archive
(
@project
,
params
[
:ref
],
params
[
:format
]))
send_git_archive
@repository
,
ref:
params
[
:ref
],
format:
params
[
:format
]
head
:ok
rescue
=>
ex
rescue
=>
ex
logger
.
error
(
"
#{
self
.
class
.
name
}
:
#{
ex
}
"
)
logger
.
error
(
"
#{
self
.
class
.
name
}
:
#{
ex
}
"
)
return
git_not_found!
return
git_not_found!
...
...
app/helpers/workhorse_helper.rb
0 → 100644
View file @
8c3ba8d6
# Helpers to send Git blobs or archives through Workhorse.
# Workhorse will also serve files when using `send_file`.
module
WorkhorseHelper
# Send a Git blob through Workhorse
def
send_git_blob
(
repository
,
blob
)
headers
.
store
(
*
Gitlab
::
Workhorse
.
send_git_blob
(
repository
,
blob
))
headers
[
'Content-Disposition'
]
=
'inline'
headers
[
'Content-Type'
]
=
safe_content_type
(
blob
)
head
:ok
# 'render nothing: true' messes up the Content-Type
end
# Archive a Git repository and send it through Workhorse
def
send_git_archive
(
repository
,
ref
:,
format
:)
headers
.
store
(
*
Gitlab
::
Workhorse
.
send_git_archive
(
repository
,
ref:
ref
,
format:
format
))
head
:ok
end
end
db/schema.rb
View file @
8c3ba8d6
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
20160530150109
)
do
ActiveRecord
::
Schema
.
define
(
version:
20160530150109
)
do
# These are extensions that must be enabled in order to support this database
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
enable_extension
"plpgsql"
enable_extension
"pg_trgm"
enable_extension
"pg_trgm"
...
...
lib/api/helpers.rb
View file @
8c3ba8d6
...
@@ -408,5 +408,15 @@ module API
...
@@ -408,5 +408,15 @@ module API
error!
(
errors
[
:access_level
],
422
)
if
errors
[
:access_level
].
any?
error!
(
errors
[
:access_level
],
422
)
if
errors
[
:access_level
].
any?
not_found!
(
errors
)
not_found!
(
errors
)
end
end
def
send_git_blob
(
repository
,
blob
)
env
[
'api.format'
]
=
:txt
content_type
'text/plain'
header
*
Gitlab
::
Workhorse
.
send_git_blob
(
repository
,
blob
)
end
def
send_git_archive
(
repository
,
ref
:,
format
:)
header
*
Gitlab
::
Workhorse
.
send_git_archive
(
repository
,
ref:
ref
,
format:
format
)
end
end
end
end
end
lib/api/repositories.rb
View file @
8c3ba8d6
...
@@ -56,8 +56,7 @@ module API
...
@@ -56,8 +56,7 @@ module API
blob
=
Gitlab
::
Git
::
Blob
.
find
(
repo
,
commit
.
id
,
params
[
:filepath
])
blob
=
Gitlab
::
Git
::
Blob
.
find
(
repo
,
commit
.
id
,
params
[
:filepath
])
not_found!
"File"
unless
blob
not_found!
"File"
unless
blob
content_type
'text/plain'
send_git_blob
repo
,
blob
header
(
*
Gitlab
::
Workhorse
.
send_git_blob
(
repo
,
blob
))
end
end
# Get a raw blob contents by blob sha
# Get a raw blob contents by blob sha
...
@@ -80,10 +79,7 @@ module API
...
@@ -80,10 +79,7 @@ module API
not_found!
'Blob'
unless
blob
not_found!
'Blob'
unless
blob
env
[
'api.format'
]
=
:txt
send_git_blob
repo
,
blob
content_type
blob
.
mime_type
header
(
*
Gitlab
::
Workhorse
.
send_git_blob
(
repo
,
blob
))
end
end
# Get a an archive of the repository
# Get a an archive of the repository
...
@@ -98,7 +94,7 @@ module API
...
@@ -98,7 +94,7 @@ module API
authorize!
:download_code
,
user_project
authorize!
:download_code
,
user_project
begin
begin
header
(
*
Gitlab
::
Workhorse
.
send_git_archive
(
user_project
,
params
[
:sha
],
params
[
:format
]))
send_git_archive
user_project
.
repository
,
ref:
params
[
:sha
],
format:
params
[
:format
]
rescue
rescue
not_found!
(
'File'
)
not_found!
(
'File'
)
end
end
...
...
lib/gitlab/workhorse.rb
View file @
8c3ba8d6
...
@@ -18,10 +18,10 @@ module Gitlab
...
@@ -18,10 +18,10 @@ module Gitlab
]
]
end
end
def
send_git_archive
(
project
,
ref
,
format
)
def
send_git_archive
(
repository
,
ref
:,
format
:
)
format
||=
'tar.gz'
format
||=
'tar.gz'
format
.
downcase!
format
.
downcase!
params
=
project
.
repository
.
archive_metadata
(
ref
,
Gitlab
.
config
.
gitlab
.
repository_downloads_path
,
format
)
params
=
repository
.
archive_metadata
(
ref
,
Gitlab
.
config
.
gitlab
.
repository_downloads_path
,
format
)
raise
"Repository or ref not found"
if
params
.
empty?
raise
"Repository or ref not found"
if
params
.
empty?
[
[
...
@@ -29,9 +29,9 @@ module Gitlab
...
@@ -29,9 +29,9 @@ module Gitlab
"git-archive:
#{
encode
(
params
)
}
"
,
"git-archive:
#{
encode
(
params
)
}
"
,
]
]
end
end
protected
protected
def
encode
(
hash
)
def
encode
(
hash
)
Base64
.
urlsafe_encode64
(
JSON
.
dump
(
hash
))
Base64
.
urlsafe_encode64
(
JSON
.
dump
(
hash
))
end
end
...
...
spec/controllers/projects/raw_controller_spec.rb
View file @
8c3ba8d6
...
@@ -17,6 +17,7 @@ describe Projects::RawController do
...
@@ -17,6 +17,7 @@ describe Projects::RawController do
expect
(
response
.
header
[
'Content-Type'
]).
to
eq
(
'text/plain; charset=utf-8'
)
expect
(
response
.
header
[
'Content-Type'
]).
to
eq
(
'text/plain; charset=utf-8'
)
expect
(
response
.
header
[
'Content-Disposition'
]).
expect
(
response
.
header
[
'Content-Disposition'
]).
to
eq
(
"inline"
)
to
eq
(
"inline"
)
expect
(
response
.
header
[
Gitlab
::
Workhorse
::
SEND_DATA_HEADER
]).
to
start_with
(
"git-blob:"
)
end
end
end
end
...
@@ -31,6 +32,7 @@ describe Projects::RawController do
...
@@ -31,6 +32,7 @@ describe Projects::RawController do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
header
[
'Content-Type'
]).
to
eq
(
'image/jpeg'
)
expect
(
response
.
header
[
'Content-Type'
]).
to
eq
(
'image/jpeg'
)
expect
(
response
.
header
[
Gitlab
::
Workhorse
::
SEND_DATA_HEADER
]).
to
start_with
(
"git-blob:"
)
end
end
end
end
...
...
spec/controllers/projects/repositories_controller_spec.rb
View file @
8c3ba8d6
...
@@ -20,10 +20,11 @@ describe Projects::RepositoriesController do
...
@@ -20,10 +20,11 @@ describe Projects::RepositoriesController do
project
.
team
<<
[
user
,
:developer
]
project
.
team
<<
[
user
,
:developer
]
sign_in
(
user
)
sign_in
(
user
)
end
end
it
"uses Gitlab::Workhorse"
do
expect
(
Gitlab
::
Workhorse
).
to
receive
(
:send_git_archive
).
with
(
project
,
"master"
,
"zip"
)
it
"uses Gitlab::Workhorse"
do
get
:archive
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
ref:
"master"
,
format:
"zip"
get
:archive
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
ref:
"master"
,
format:
"zip"
expect
(
response
.
header
[
Gitlab
::
Workhorse
::
SEND_DATA_HEADER
]).
to
start_with
(
"git-archive:"
)
end
end
context
"when the service raises an error"
do
context
"when the service raises an error"
do
...
...
spec/lib/gitlab/workhorse_spec.rb
View file @
8c3ba8d6
...
@@ -11,7 +11,7 @@ describe Gitlab::Workhorse, lib: true do
...
@@ -11,7 +11,7 @@ describe Gitlab::Workhorse, lib: true do
end
end
it
"raises an error"
do
it
"raises an error"
do
expect
{
subject
.
send_git_archive
(
project
,
"master"
,
"zip"
)
}.
to
raise_error
(
RuntimeError
)
expect
{
subject
.
send_git_archive
(
project
.
repository
,
ref:
"master"
,
format:
"zip"
)
}.
to
raise_error
(
RuntimeError
)
end
end
end
end
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