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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
688ff26d
Commit
688ff26d
authored
Nov 18, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'grapify-repository-api' into 'master'
Grapify repository api See merge request !7534
parents
ec3b1c6d
e9710099
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
58 deletions
+39
-58
lib/api/repositories.rb
lib/api/repositories.rb
+39
-58
No files found.
lib/api/repositories.rb
View file @
688ff26d
require
'mime/types'
require
'mime/types'
module
API
module
API
# Projects API
class
Repositories
<
Grape
::
API
class
Repositories
<
Grape
::
API
before
{
authenticate!
}
before
{
authenticate!
}
before
{
authorize!
:download_code
,
user_project
}
before
{
authorize!
:download_code
,
user_project
}
params
do
requires
:id
,
type:
String
,
desc:
'The ID of a project'
end
resource
:projects
do
resource
:projects
do
helpers
do
helpers
do
def
handle_project_member_errors
(
errors
)
def
handle_project_member_errors
(
errors
)
...
@@ -16,43 +18,35 @@ module API
...
@@ -16,43 +18,35 @@ module API
end
end
end
end
# Get a project repository tree
desc
'Get a project repository tree'
do
#
success
Entities
::
RepoTreeObject
# Parameters:
end
# id (required) - The ID of a project
params
do
# ref_name (optional) - The name of a repository branch or tag, if not given the default branch is used
optional
:ref_name
,
type:
String
,
desc:
'The name of a repository branch or tag, if not given the default branch is used'
# recursive (optional) - Used to get a recursive tree
optional
:path
,
type:
String
,
desc:
'The path of the tree'
# Example Request:
optional
:recursive
,
type:
Boolean
,
default:
false
,
desc:
'Used to get a recursive tree'
# GET /projects/:id/repository/tree
end
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
recursive
=
to_boolean
(
params
[
:recursive
])
commit
=
user_project
.
commit
(
ref
)
commit
=
user_project
.
commit
(
ref
)
not_found!
(
'Tree'
)
unless
commit
not_found!
(
'Tree'
)
unless
commit
tree
=
user_project
.
repository
.
tree
(
commit
.
id
,
path
,
recursive:
recursive
)
tree
=
user_project
.
repository
.
tree
(
commit
.
id
,
path
,
recursive:
params
[
:recursive
]
)
present
tree
.
sorted_entries
,
with:
Entities
::
RepoTreeObject
present
tree
.
sorted_entries
,
with:
Entities
::
RepoTreeObject
end
end
# Get a raw file contents
desc
'Get a raw file contents'
#
params
do
# Parameters:
requires
:sha
,
type:
String
,
desc:
'The commit, branch name, or tag name'
# id (required) - The ID of a project
requires
:filepath
,
type:
String
,
desc:
'The path to the file to display'
# sha (required) - The commit or branch name
end
# filepath (required) - The path to the file to display
# Example Request:
# GET /projects/:id/repository/blobs/:sha
get
[
":id/repository/blobs/:sha"
,
":id/repository/commits/:sha/blob"
]
do
get
[
":id/repository/blobs/:sha"
,
":id/repository/commits/:sha/blob"
]
do
required_attributes!
[
:filepath
]
ref
=
params
[
:sha
]
repo
=
user_project
.
repository
repo
=
user_project
.
repository
commit
=
repo
.
commit
(
ref
)
commit
=
repo
.
commit
(
params
[
:sha
]
)
not_found!
"Commit"
unless
commit
not_found!
"Commit"
unless
commit
blob
=
Gitlab
::
Git
::
Blob
.
find
(
repo
,
commit
.
id
,
params
[
:filepath
])
blob
=
Gitlab
::
Git
::
Blob
.
find
(
repo
,
commit
.
id
,
params
[
:filepath
])
...
@@ -61,20 +55,15 @@ module API
...
@@ -61,20 +55,15 @@ module API
send_git_blob
repo
,
blob
send_git_blob
repo
,
blob
end
end
# Get a raw blob contents by blob sha
desc
'Get a raw blob contents by blob sha'
#
params
do
# Parameters:
requires
:sha
,
type:
String
,
desc:
'The commit, branch name, or tag name'
# id (required) - The ID of a project
end
# sha (required) - The blob's sha
# Example Request:
# GET /projects/:id/repository/raw_blobs/:sha
get
':id/repository/raw_blobs/:sha'
do
get
':id/repository/raw_blobs/:sha'
do
ref
=
params
[
:sha
]
repo
=
user_project
.
repository
repo
=
user_project
.
repository
begin
begin
blob
=
Gitlab
::
Git
::
Blob
.
raw
(
repo
,
ref
)
blob
=
Gitlab
::
Git
::
Blob
.
raw
(
repo
,
params
[
:sha
]
)
rescue
rescue
not_found!
'Blob'
not_found!
'Blob'
end
end
...
@@ -84,15 +73,12 @@ module API
...
@@ -84,15 +73,12 @@ module API
send_git_blob
repo
,
blob
send_git_blob
repo
,
blob
end
end
# Get a an archive of the repository
desc
'Get an archive of the repository'
#
params
do
# Parameters:
optional
:sha
,
type:
String
,
desc:
'The commit sha of the archive to be downloaded'
# id (required) - The ID of a project
optional
:format
,
type:
String
,
desc:
'The archive format'
# sha (optional) - the commit sha to download defaults to the tip of the default branch
end
# Example Request:
get
':id/repository/archive'
,
requirements:
{
format:
Gitlab
::
Regex
.
archive_formats_regex
}
do
# GET /projects/:id/repository/archive
get
':id/repository/archive'
,
requirements:
{
format:
Gitlab
::
Regex
.
archive_formats_regex
}
do
authorize!
:download_code
,
user_project
authorize!
:download_code
,
user_project
begin
begin
...
@@ -102,27 +88,22 @@ module API
...
@@ -102,27 +88,22 @@ module API
end
end
end
end
# Compare two branches, tags or commits
desc
'Compare two branches, tags, or commits'
do
#
success
Entities
::
Compare
# Parameters:
end
# id (required) - The ID of a project
params
do
# from (required) - the commit sha or branch name
requires
:from
,
type:
String
,
desc:
'The commit, branch name, or tag name to start comparison'
# to (required) - the commit sha or branch name
requires
:to
,
type:
String
,
desc:
'The commit, branch name, or tag name to stop comparison'
# Example Request:
end
# GET /projects/:id/repository/compare?from=master&to=feature
get
':id/repository/compare'
do
get
':id/repository/compare'
do
authorize!
:download_code
,
user_project
authorize!
:download_code
,
user_project
required_attributes!
[
:from
,
:to
]
compare
=
Gitlab
::
Git
::
Compare
.
new
(
user_project
.
repository
.
raw_repository
,
params
[
:from
],
params
[
:to
])
compare
=
Gitlab
::
Git
::
Compare
.
new
(
user_project
.
repository
.
raw_repository
,
params
[
:from
],
params
[
:to
])
present
compare
,
with:
Entities
::
Compare
present
compare
,
with:
Entities
::
Compare
end
end
# Get repository contributors
desc
'Get repository contributors'
do
#
success
Entities
::
Contributor
# Parameters:
end
# id (required) - The ID of a project
# Example Request:
# GET /projects/:id/repository/contributors
get
':id/repository/contributors'
do
get
':id/repository/contributors'
do
authorize!
:download_code
,
user_project
authorize!
:download_code
,
user_project
...
...
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