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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
771f14b9
Commit
771f14b9
authored
Feb 02, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First version of "git archive" headers
parent
b1f22aa3
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
41 deletions
+49
-41
app/controllers/projects/repositories_controller.rb
app/controllers/projects/repositories_controller.rb
+3
-1
app/services/archive_repository_service.rb
app/services/archive_repository_service.rb
+0
-23
lib/api/repositories.rb
lib/api/repositories.rb
+2
-5
lib/gitlab/workhorse.rb
lib/gitlab/workhorse.rb
+23
-4
spec/controllers/projects/repositories_controller_spec.rb
spec/controllers/projects/repositories_controller_spec.rb
+3
-8
spec/lib/gitlab/workhorse_spec.rb
spec/lib/gitlab/workhorse_spec.rb
+18
-0
No files found.
app/controllers/projects/repositories_controller.rb
View file @
771f14b9
...
...
@@ -11,7 +11,9 @@ class Projects::RepositoriesController < Projects::ApplicationController
end
def
archive
render
json:
ArchiveRepositoryService
.
new
(
@project
,
params
[
:ref
],
params
[
:format
]).
execute
RepositoryArchiveCacheWorker
.
perform_async
headers
.
store
(
*
Gitlab
::
Workhorse
.
send_git_archive
(
@project
,
params
[
:ref
],
params
[
:format
]))
head
:ok
rescue
=>
ex
logger
.
error
(
"
#{
self
.
class
.
name
}
:
#{
ex
}
"
)
return
git_not_found!
...
...
app/services/archive_repository_service.rb
deleted
100644 → 0
View file @
b1f22aa3
class
ArchiveRepositoryService
attr_reader
:project
,
:ref
,
:format
def
initialize
(
project
,
ref
,
format
)
format
||=
'tar.gz'
@project
,
@ref
,
@format
=
project
,
ref
,
format
.
downcase
end
def
execute
(
options
=
{})
RepositoryArchiveCacheWorker
.
perform_async
metadata
=
project
.
repository
.
archive_metadata
(
ref
,
storage_path
,
format
)
raise
"Repository or ref not found"
if
metadata
.
empty?
metadata
end
private
def
storage_path
Gitlab
.
config
.
gitlab
.
repository_downloads_path
end
end
lib/api/repositories.rb
View file @
771f14b9
...
...
@@ -98,11 +98,8 @@ module API
authorize!
:download_code
,
user_project
begin
ArchiveRepositoryService
.
new
(
user_project
,
params
[
:sha
],
params
[
:format
]
).
execute
RepositoryArchiveCacheWorker
.
perform_async
header
*
Gitlab
::
Workhorse
.
send_git_archive
(
@project
,
params
[
:ref
],
params
[
:format
])
rescue
not_found!
(
'File'
)
end
...
...
lib/gitlab/workhorse.rb
View file @
771f14b9
...
...
@@ -4,18 +4,37 @@ require 'json'
module
Gitlab
class
Workhorse
class
<<
self
SEND_DATA_HEADER
=
'Gitlab-Workhorse-Send-Data'
def
send_git_blob
(
repository
,
blob
)
params
_hash
=
{
params
=
{
'RepoPath'
=>
repository
.
path_to_repo
,
'BlobId'
=>
blob
.
id
,
}
params
=
Base64
.
urlsafe_encode64
(
JSON
.
dump
(
params_hash
))
[
'Gitlab-Workhorse-Send-Data'
,
"git-blob:
#{
params
}
"
,
SEND_DATA_HEADER
,
"git-blob:
#{
encode
(
params
)
}
"
,
]
end
def
send_git_archive
(
project
,
ref
,
format
)
format
||=
'tar.gz'
format
.
downcase!
params
=
project
.
repository
.
archive_metadata
(
ref
,
Gitlab
.
config
.
gitlab
.
repository_downloads_path
,
format
)
raise
"Repository or ref not found"
if
params
.
empty?
[
SEND_DATA_HEADER
,
"git-archive:
#{
encode
(
params
)
}
"
,
]
end
protected
def
encode
(
hash
)
Base64
.
urlsafe_encode64
(
JSON
.
dump
(
hash
))
end
end
end
end
spec/controllers/projects/repositories_controller_spec.rb
View file @
771f14b9
...
...
@@ -8,15 +8,10 @@ describe Projects::RepositoriesController do
before
do
sign_in
(
user
)
project
.
team
<<
[
user
,
:developer
]
allow
(
ArchiveRepositoryService
).
to
receive
(
:new
).
and_return
(
service
)
end
let
(
:service
)
{
ArchiveRepositoryService
.
new
(
project
,
"master"
,
"zip"
)
}
it
"executes ArchiveRepositoryService"
do
expect
(
ArchiveRepositoryService
).
to
receive
(
:new
).
with
(
project
,
"master"
,
"zip"
)
expect
(
service
).
to
receive
(
:execute
)
it
"uses Gitlab::Workhorse"
do
expect
(
Gitlab
::
Workhorse
).
to
receive
(
:send_git_archive
).
with
(
project
,
"master"
,
"zip"
)
get
:archive
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
ref:
"master"
,
format:
"zip"
end
...
...
@@ -24,7 +19,7 @@ describe Projects::RepositoriesController do
context
"when the service raises an error"
do
before
do
allow
(
service
).
to
receive
(
:execut
e
).
and_raise
(
"Archive failed"
)
allow
(
Gitlab
::
Workhorse
).
to
receive
(
:send_git_archiv
e
).
and_raise
(
"Archive failed"
)
end
it
"renders Not Found"
do
...
...
spec/
services/archive_repository_servic
e_spec.rb
→
spec/
lib/gitlab/workhors
e_spec.rb
View file @
771f14b9
require
'spec_helper'
describe
ArchiveRepositoryService
,
services
:
true
do
describe
Gitlab
::
Workhorse
,
lib
:
true
do
let
(
:project
)
{
create
(
:project
)
}
subject
{
ArchiveRepositoryService
.
new
(
project
,
"master"
,
"zip"
)
}
describe
"#execute"
do
it
"cleans old archives"
do
expect
(
RepositoryArchiveCacheWorker
).
to
receive
(
:perform_async
)
subject
.
execute
(
timeout:
0.0
)
end
let
(
:subject
)
{
Gitlab
::
Workhorse
}
describe
"#send_git_archive"
do
context
"when the repository doesn't have an archive file path"
do
before
do
allow
(
project
.
repository
).
to
receive
(
:archive_metadata
).
and_return
(
Hash
.
new
)
end
it
"raises an error"
do
expect
{
subject
.
execute
(
timeout:
0.0
)
}.
to
raise_error
(
RuntimeError
)
expect
{
subject
.
send_git_archive
(
project
,
"master"
,
"zip"
)
}.
to
raise_error
(
RuntimeError
)
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