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
7155507a
Commit
7155507a
authored
Jan 27, 2015
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8609 from jubianchi/issues/6289-api-handle-error-project-repo
Handle errors on API when a project does not have a repository
parents
0d86a1a3
39e54e21
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
8 deletions
+45
-8
repositories.rb
lib/api/repositories.rb
+29
-8
repositories_spec.rb
spec/requests/api/repositories_spec.rb
+16
-0
No files found.
lib/api/repositories.rb
View file @
7155507a
...
@@ -58,11 +58,13 @@ module API
...
@@ -58,11 +58,13 @@ module API
# ref_name (optional) - The name of a repository branch or tag, if not given the default branch is used
# ref_name (optional) - The name of a repository branch or tag, if not given the default branch is used
# Example Request:
# Example Request:
# GET /projects/:id/repository/tree
# GET /projects/:id/repository/tree
get
":id/repository/tree"
do
get
':id/repository/tree'
do
ref
=
params
[
:ref_name
]
||
user_project
.
try
(
:default_branch
)
||
'master'
ref
=
params
[
:ref_name
]
||
user_project
.
try
(
:default_branch
)
||
'master'
path
=
params
[
:path
]
||
nil
path
=
params
[
:path
]
||
nil
commit
=
user_project
.
repository
.
commit
(
ref
)
commit
=
user_project
.
repository
.
commit
(
ref
)
not_found!
(
'Tree'
)
unless
commit
tree
=
user_project
.
repository
.
tree
(
commit
.
id
,
path
)
tree
=
user_project
.
repository
.
tree
(
commit
.
id
,
path
)
present
tree
.
sorted_entries
,
with:
Entities
::
RepoTreeObject
present
tree
.
sorted_entries
,
with:
Entities
::
RepoTreeObject
...
@@ -100,14 +102,18 @@ module API
...
@@ -100,14 +102,18 @@ module API
# sha (required) - The blob's sha
# sha (required) - The blob's sha
# Example Request:
# Example Request:
# GET /projects/:id/repository/raw_blobs/:sha
# GET /projects/:id/repository/raw_blobs/:sha
get
":id/repository/raw_blobs/:sha"
do
get
':id/repository/raw_blobs/:sha'
do
ref
=
params
[
:sha
]
ref
=
params
[
:sha
]
repo
=
user_project
.
repository
repo
=
user_project
.
repository
blob
=
Gitlab
::
Git
::
Blob
.
raw
(
repo
,
ref
)
begin
blob
=
Gitlab
::
Git
::
Blob
.
raw
(
repo
,
ref
)
rescue
not_found!
'Blob'
end
not_found!
"Blob"
unless
blob
not_found!
'Blob'
unless
blob
env
[
'api.format'
]
=
:txt
env
[
'api.format'
]
=
:txt
...
@@ -122,13 +128,23 @@ module API
...
@@ -122,13 +128,23 @@ module API
# sha (optional) - the commit sha to download defaults to the tip of the default branch
# sha (optional) - the commit sha to download defaults to the tip of the default branch
# Example Request:
# Example Request:
# GET /projects/:id/repository/archive
# GET /projects/:id/repository/archive
get
":id/repository/archive"
,
requirements:
{
format:
Gitlab
::
Regex
.
archive_formats_regex
}
do
get
':id/repository/archive'
,
requirements:
{
format:
Gitlab
::
Regex
.
archive_formats_regex
}
do
authorize!
:download_code
,
user_project
authorize!
:download_code
,
user_project
file_path
=
ArchiveRepositoryService
.
new
.
execute
(
user_project
,
params
[
:sha
],
params
[
:format
])
begin
file_path
=
ArchiveRepositoryService
.
new
.
execute
(
user_project
,
params
[
:sha
],
params
[
:format
])
rescue
not_found!
(
'File'
)
end
if
file_path
&&
File
.
exists?
(
file_path
)
if
file_path
&&
File
.
exists?
(
file_path
)
data
=
File
.
open
(
file_path
,
'rb'
).
read
data
=
File
.
open
(
file_path
,
'rb'
).
read
header
[
"Content-Disposition"
]
=
"attachment; filename=
\"
#{
File
.
basename
(
file_path
)
}
\"
"
basename
=
File
.
basename
(
file_path
)
header
[
'Content-Disposition'
]
=
"attachment; filename=
\"
#{
basename
}
\"
"
content_type
MIME
::
Types
.
type_for
(
file_path
).
first
.
content_type
content_type
MIME
::
Types
.
type_for
(
file_path
).
first
.
content_type
env
[
'api.format'
]
=
:binary
env
[
'api.format'
]
=
:binary
present
data
present
data
...
@@ -161,7 +177,12 @@ module API
...
@@ -161,7 +177,12 @@ module API
get
':id/repository/contributors'
do
get
':id/repository/contributors'
do
authorize!
:download_code
,
user_project
authorize!
:download_code
,
user_project
present
user_project
.
repository
.
contributors
,
with:
Entities
::
Contributor
begin
present
user_project
.
repository
.
contributors
,
with:
Entities
::
Contributor
rescue
not_found!
end
end
end
end
end
end
end
...
...
spec/requests/api/repositories_spec.rb
View file @
7155507a
...
@@ -101,6 +101,14 @@ describe API::API, api: true do
...
@@ -101,6 +101,14 @@ describe API::API, api: true do
json_response
.
first
[
'type'
].
should
==
'tree'
json_response
.
first
[
'type'
].
should
==
'tree'
json_response
.
first
[
'mode'
].
should
==
'040000'
json_response
.
first
[
'mode'
].
should
==
'040000'
end
end
it
'should return a 404 for unknown ref'
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/tree?ref_name=foo"
,
user
)
response
.
status
.
should
==
404
json_response
.
should
be_an
Object
json_response
[
'message'
]
==
'404 Tree Not Found'
end
end
end
context
"unauthorized user"
do
context
"unauthorized user"
do
...
@@ -145,6 +153,14 @@ describe API::API, api: true do
...
@@ -145,6 +153,14 @@ describe API::API, api: true do
get
api
(
"/projects/
#{
project
.
id
}
/repository/raw_blobs/
#{
sample_blob
.
oid
}
"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/repository/raw_blobs/
#{
sample_blob
.
oid
}
"
,
user
)
response
.
status
.
should
==
200
response
.
status
.
should
==
200
end
end
it
'should return a 404 for unknown blob'
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/raw_blobs/123456"
,
user
)
response
.
status
.
should
==
404
json_response
.
should
be_an
Object
json_response
[
'message'
]
==
'404 Blob Not Found'
end
end
end
describe
"GET /projects/:id/repository/archive(.:format)?:sha"
do
describe
"GET /projects/:id/repository/archive(.:format)?:sha"
do
...
...
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