BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
d25b5d02
Commit
d25b5d02
authored
Jan 04, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5891 from jhollingsworth/feature/zip-archive
Add support for various archive formats.
parents
e680228b
7cc25205
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
8 deletions
+44
-8
repositories_controller.rb
app/controllers/projects/repositories_controller.rb
+1
-1
routes.rb
config/routes.rb
+1
-1
repositories.rb
lib/api/repositories.rb
+8
-4
regex.rb
lib/gitlab/regex.rb
+5
-0
repositories_spec.rb
spec/requests/api/repositories_spec.rb
+21
-2
project_routing_spec.rb
spec/routing/project_routing_spec.rb
+8
-0
No files found.
app/controllers/projects/repositories_controller.rb
View file @
d25b5d02
...
...
@@ -16,7 +16,7 @@ class Projects::RepositoriesController < Projects::ApplicationController
storage_path
=
Rails
.
root
.
join
(
"tmp"
,
"repositories"
)
file_path
=
@repository
.
archive_repo
(
params
[
:ref
],
storage_path
)
file_path
=
@repository
.
archive_repo
(
params
[
:ref
],
storage_path
,
params
[
:format
].
downcase
)
if
file_path
# Send file to user
...
...
config/routes.rb
View file @
d25b5d02
...
...
@@ -217,7 +217,7 @@ Gitlab::Application.routes.draw do
resource
:repository
,
only:
[
:show
]
do
member
do
get
"stats"
get
"archive"
get
"archive"
,
constraints:
{
format:
Gitlab
::
Regex
.
archive_formats_regex
}
end
end
...
...
lib/api/repositories.rb
View file @
d25b5d02
require
'mime/types'
module
API
# Projects API
class
Repositories
<
Grape
::
API
...
...
@@ -206,18 +208,20 @@ module API
# sha (optional) - the commit sha to download defaults to the tip of the default branch
# Example Request:
# GET /projects/:id/repository/archive
get
":id/repository/archive"
do
get
":id/repository/archive"
,
requirements:
{
format:
Gitlab
::
Regex
.
archive_formats_regex
}
do
authorize!
:download_code
,
user_project
repo
=
user_project
.
repository
ref
=
params
[
:sha
]
format
=
params
[
:format
]
storage_path
=
Rails
.
root
.
join
(
"tmp"
,
"repositories"
)
file_path
=
repo
.
archive_repo
(
ref
,
storage_path
)
file_path
=
repo
.
archive_repo
(
ref
,
storage_path
,
format
)
if
file_path
&&
File
.
exists?
(
file_path
)
data
=
File
.
open
(
file_path
,
'rb'
).
read
header
"Content-Disposition:"
,
" infile; filename=
\"
#{
File
.
basename
(
file_path
)
}
\"
"
content_type
'application/x-gzip'
header
[
"Content-Disposition"
]
=
"attachment; filename=
\"
#{
File
.
basename
(
file_path
)
}
\"
"
content_type
MIME
::
Types
.
type_for
(
file_path
).
first
.
content_type
env
[
'api.format'
]
=
:binary
...
...
lib/gitlab/regex.rb
View file @
d25b5d02
...
...
@@ -17,6 +17,11 @@ module Gitlab
def
path_regex
default_regex
end
def
archive_formats_regex
#|zip|tar| tar.gz | tar.bz2 |
/(zip|tar|tar\.gz|tgz|gz|tar\.bz2|tbz|tbz2|tb2|bz2)/
end
def
git_reference_regex
# Valid git ref regex, see:
...
...
spec/requests/api/repositories_spec.rb
View file @
d25b5d02
require
'spec_helper'
require
'mime/types'
describe
API
::
API
do
include
ApiHelpers
...
...
@@ -232,11 +233,29 @@ describe API::API do
end
end
describe
"GET /projects/:id/repository/archive
/
:sha"
do
describe
"GET /projects/:id/repository/archive
(.:format)?
:sha"
do
it
"should get the archive"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/archive"
,
user
)
repo_name
=
project
.
repository
.
name
.
gsub
(
"
\.
git"
,
""
)
response
.
status
.
should
==
200
response
.
content_type
.
should
==
'application/x-gzip'
response
.
headers
[
'Content-Disposition'
].
should
=~
/filename\=\"
#{
repo_name
}
\-[^\.]+\.tar.gz\"/
response
.
content_type
.
should
==
MIME
::
Types
.
type_for
(
'file.tar.gz'
).
first
.
content_type
end
it
"should get the archive.zip"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/archive.zip"
,
user
)
repo_name
=
project
.
repository
.
name
.
gsub
(
"
\.
git"
,
""
)
response
.
status
.
should
==
200
response
.
headers
[
'Content-Disposition'
].
should
=~
/filename\=\"
#{
repo_name
}
\-[^\.]+\.zip\"/
response
.
content_type
.
should
==
MIME
::
Types
.
type_for
(
'file.zip'
).
first
.
content_type
end
it
"should get the archive.tar.bz2"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/archive.tar.bz2"
,
user
)
repo_name
=
project
.
repository
.
name
.
gsub
(
"
\.
git"
,
""
)
response
.
status
.
should
==
200
response
.
headers
[
'Content-Disposition'
].
should
=~
/filename\=\"
#{
repo_name
}
\-[^\.]+\.tar.bz2\"/
response
.
content_type
.
should
==
MIME
::
Types
.
type_for
(
'file.tar.bz2'
).
first
.
content_type
end
it
"should return 404 for invalid sha"
do
...
...
spec/routing/project_routing_spec.rb
View file @
d25b5d02
...
...
@@ -130,6 +130,14 @@ describe Projects::RepositoriesController, "routing" do
get
(
"/gitlab/gitlabhq/repository/archive"
).
should
route_to
(
'projects/repositories#archive'
,
project_id:
'gitlab/gitlabhq'
)
end
it
"to #archive format:zip"
do
get
(
"/gitlab/gitlabhq/repository/archive.zip"
).
should
route_to
(
'projects/repositories#archive'
,
project_id:
'gitlab/gitlabhq'
,
format:
'zip'
)
end
it
"to #archive format:tar.bz2"
do
get
(
"/gitlab/gitlabhq/repository/archive.tar.bz2"
).
should
route_to
(
'projects/repositories#archive'
,
project_id:
'gitlab/gitlabhq'
,
format:
'tar.bz2'
)
end
it
"to #show"
do
get
(
"/gitlab/gitlabhq/repository"
).
should
route_to
(
'projects/repositories#show'
,
project_id:
'gitlab/gitlabhq'
)
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