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
0f604e62
Commit
0f604e62
authored
Jul 06, 2012
by
Nihad Abbasov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor projects API
parent
0a6b64e6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
21 deletions
+13
-21
lib/api/entities.rb
lib/api/entities.rb
+1
-5
lib/api/helpers.rb
lib/api/helpers.rb
+4
-0
lib/api/projects.rb
lib/api/projects.rb
+8
-16
No files found.
lib/api/entities.rb
View file @
0f604e62
...
...
@@ -16,11 +16,7 @@ module Gitlab
expose
:issues_enabled
,
:merge_requests_enabled
,
:wall_enabled
,
:wiki_enabled
,
:created_at
end
class
ProjectRepositoryBranches
<
Grape
::
Entity
expose
:name
,
:commit
end
class
ProjectRepositoryTags
<
Grape
::
Entity
class
RepoObject
<
Grape
::
Entity
expose
:name
,
:commit
end
...
...
lib/api/helpers.rb
View file @
0f604e62
...
...
@@ -4,6 +4,10 @@ module Gitlab
@current_user
||=
User
.
find_by_authentication_token
(
params
[
:private_token
])
end
def
user_project
@project
||=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
end
def
authenticate!
error!
({
'message'
=>
'401 Unauthorized'
},
401
)
unless
current_user
end
...
...
lib/api/projects.rb
View file @
0f604e62
...
...
@@ -20,8 +20,7 @@ module Gitlab
# Example Request:
# GET /projects/:id
get
":id"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
present
@project
,
:with
=>
Entities
::
Project
present
user_project
,
:with
=>
Entities
::
Project
end
# Get a project repository branches
...
...
@@ -31,8 +30,7 @@ module Gitlab
# Example Request:
# GET /projects/:id/repository/branches
get
":id/repository/branches"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
present
@project
.
repo
.
heads
.
sort_by
(
&
:name
),
:with
=>
Entities
::
ProjectRepositoryBranches
present
user_project
.
repo
.
heads
.
sort_by
(
&
:name
),
:with
=>
Entities
::
RepoObject
end
# Get a project repository tags
...
...
@@ -42,8 +40,7 @@ module Gitlab
# Example Request:
# GET /projects/:id/repository/tags
get
":id/repository/tags"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
present
@project
.
repo
.
tags
.
sort_by
(
&
:name
).
reverse
,
:with
=>
Entities
::
ProjectRepositoryTags
present
user_project
.
repo
.
tags
.
sort_by
(
&
:name
).
reverse
,
:with
=>
Entities
::
RepoObject
end
# Get a project snippet
...
...
@@ -54,8 +51,7 @@ module Gitlab
# Example Request:
# GET /projects/:id/snippets/:snippet_id
get
":id/snippets/:snippet_id"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
@snippet
=
@project
.
snippets
.
find
(
params
[
:snippet_id
])
@snippet
=
user_project
.
snippets
.
find
(
params
[
:snippet_id
])
present
@snippet
,
:with
=>
Entities
::
ProjectSnippet
end
...
...
@@ -70,8 +66,7 @@ module Gitlab
# Example Request:
# POST /projects/:id/snippets
post
":id/snippets"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
@snippet
=
@project
.
snippets
.
new
(
@snippet
=
user_project
.
snippets
.
new
(
:title
=>
params
[
:title
],
:file_name
=>
params
[
:file_name
],
:expires_at
=>
params
[
:lifetime
],
...
...
@@ -98,8 +93,7 @@ module Gitlab
# Example Request:
# PUT /projects/:id/snippets/:snippet_id
put
":id/snippets/:snippet_id"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
@snippet
=
@project
.
snippets
.
find
(
params
[
:snippet_id
])
@snippet
=
user_project
.
snippets
.
find
(
params
[
:snippet_id
])
parameters
=
{
:title
=>
(
params
[
:title
]
||
@snippet
.
title
),
:file_name
=>
(
params
[
:file_name
]
||
@snippet
.
file_name
),
...
...
@@ -122,8 +116,7 @@ module Gitlab
# Example Request:
# DELETE /projects/:id/snippets/:snippet_id
delete
":id/snippets/:snippet_id"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
@snippet
=
@project
.
snippets
.
find
(
params
[
:snippet_id
])
@snippet
=
user_project
.
snippets
.
find
(
params
[
:snippet_id
])
@snippet
.
destroy
end
...
...
@@ -135,8 +128,7 @@ module Gitlab
# Example Request:
# GET /projects/:id/snippets/:snippet_id/raw
get
":id/snippets/:snippet_id/raw"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
@snippet
=
@project
.
snippets
.
find
(
params
[
:snippet_id
])
@snippet
=
user_project
.
snippets
.
find
(
params
[
:snippet_id
])
present
@snippet
.
content
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