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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kazuhiko Shiozaki
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
...
@@ -16,11 +16,7 @@ module Gitlab
expose
:issues_enabled
,
:merge_requests_enabled
,
:wall_enabled
,
:wiki_enabled
,
:created_at
expose
:issues_enabled
,
:merge_requests_enabled
,
:wall_enabled
,
:wiki_enabled
,
:created_at
end
end
class
ProjectRepositoryBranches
<
Grape
::
Entity
class
RepoObject
<
Grape
::
Entity
expose
:name
,
:commit
end
class
ProjectRepositoryTags
<
Grape
::
Entity
expose
:name
,
:commit
expose
:name
,
:commit
end
end
...
...
lib/api/helpers.rb
View file @
0f604e62
...
@@ -4,6 +4,10 @@ module Gitlab
...
@@ -4,6 +4,10 @@ module Gitlab
@current_user
||=
User
.
find_by_authentication_token
(
params
[
:private_token
])
@current_user
||=
User
.
find_by_authentication_token
(
params
[
:private_token
])
end
end
def
user_project
@project
||=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
end
def
authenticate!
def
authenticate!
error!
({
'message'
=>
'401 Unauthorized'
},
401
)
unless
current_user
error!
({
'message'
=>
'401 Unauthorized'
},
401
)
unless
current_user
end
end
...
...
lib/api/projects.rb
View file @
0f604e62
...
@@ -20,8 +20,7 @@ module Gitlab
...
@@ -20,8 +20,7 @@ module Gitlab
# Example Request:
# Example Request:
# GET /projects/:id
# GET /projects/:id
get
":id"
do
get
":id"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
present
user_project
,
:with
=>
Entities
::
Project
present
@project
,
:with
=>
Entities
::
Project
end
end
# Get a project repository branches
# Get a project repository branches
...
@@ -31,8 +30,7 @@ module Gitlab
...
@@ -31,8 +30,7 @@ module Gitlab
# Example Request:
# Example Request:
# GET /projects/:id/repository/branches
# GET /projects/:id/repository/branches
get
":id/repository/branches"
do
get
":id/repository/branches"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
present
user_project
.
repo
.
heads
.
sort_by
(
&
:name
),
:with
=>
Entities
::
RepoObject
present
@project
.
repo
.
heads
.
sort_by
(
&
:name
),
:with
=>
Entities
::
ProjectRepositoryBranches
end
end
# Get a project repository tags
# Get a project repository tags
...
@@ -42,8 +40,7 @@ module Gitlab
...
@@ -42,8 +40,7 @@ module Gitlab
# Example Request:
# Example Request:
# GET /projects/:id/repository/tags
# GET /projects/:id/repository/tags
get
":id/repository/tags"
do
get
":id/repository/tags"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
present
user_project
.
repo
.
tags
.
sort_by
(
&
:name
).
reverse
,
:with
=>
Entities
::
RepoObject
present
@project
.
repo
.
tags
.
sort_by
(
&
:name
).
reverse
,
:with
=>
Entities
::
ProjectRepositoryTags
end
end
# Get a project snippet
# Get a project snippet
...
@@ -54,8 +51,7 @@ module Gitlab
...
@@ -54,8 +51,7 @@ module Gitlab
# Example Request:
# Example Request:
# GET /projects/:id/snippets/:snippet_id
# GET /projects/:id/snippets/:snippet_id
get
":id/snippets/:snippet_id"
do
get
":id/snippets/:snippet_id"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
@snippet
=
user_project
.
snippets
.
find
(
params
[
:snippet_id
])
@snippet
=
@project
.
snippets
.
find
(
params
[
:snippet_id
])
present
@snippet
,
:with
=>
Entities
::
ProjectSnippet
present
@snippet
,
:with
=>
Entities
::
ProjectSnippet
end
end
...
@@ -70,8 +66,7 @@ module Gitlab
...
@@ -70,8 +66,7 @@ module Gitlab
# Example Request:
# Example Request:
# POST /projects/:id/snippets
# POST /projects/:id/snippets
post
":id/snippets"
do
post
":id/snippets"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
@snippet
=
user_project
.
snippets
.
new
(
@snippet
=
@project
.
snippets
.
new
(
:title
=>
params
[
:title
],
:title
=>
params
[
:title
],
:file_name
=>
params
[
:file_name
],
:file_name
=>
params
[
:file_name
],
:expires_at
=>
params
[
:lifetime
],
:expires_at
=>
params
[
:lifetime
],
...
@@ -98,8 +93,7 @@ module Gitlab
...
@@ -98,8 +93,7 @@ module Gitlab
# Example Request:
# Example Request:
# PUT /projects/:id/snippets/:snippet_id
# PUT /projects/:id/snippets/:snippet_id
put
":id/snippets/:snippet_id"
do
put
":id/snippets/:snippet_id"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
@snippet
=
user_project
.
snippets
.
find
(
params
[
:snippet_id
])
@snippet
=
@project
.
snippets
.
find
(
params
[
:snippet_id
])
parameters
=
{
parameters
=
{
:title
=>
(
params
[
:title
]
||
@snippet
.
title
),
:title
=>
(
params
[
:title
]
||
@snippet
.
title
),
:file_name
=>
(
params
[
:file_name
]
||
@snippet
.
file_name
),
:file_name
=>
(
params
[
:file_name
]
||
@snippet
.
file_name
),
...
@@ -122,8 +116,7 @@ module Gitlab
...
@@ -122,8 +116,7 @@ module Gitlab
# Example Request:
# Example Request:
# DELETE /projects/:id/snippets/:snippet_id
# DELETE /projects/:id/snippets/:snippet_id
delete
":id/snippets/:snippet_id"
do
delete
":id/snippets/:snippet_id"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
@snippet
=
user_project
.
snippets
.
find
(
params
[
:snippet_id
])
@snippet
=
@project
.
snippets
.
find
(
params
[
:snippet_id
])
@snippet
.
destroy
@snippet
.
destroy
end
end
...
@@ -135,8 +128,7 @@ module Gitlab
...
@@ -135,8 +128,7 @@ module Gitlab
# Example Request:
# Example Request:
# GET /projects/:id/snippets/:snippet_id/raw
# GET /projects/:id/snippets/:snippet_id/raw
get
":id/snippets/:snippet_id/raw"
do
get
":id/snippets/:snippet_id/raw"
do
@project
=
current_user
.
projects
.
find_by_code
(
params
[
:id
])
@snippet
=
user_project
.
snippets
.
find
(
params
[
:snippet_id
])
@snippet
=
@project
.
snippets
.
find
(
params
[
:snippet_id
])
present
@snippet
.
content
present
@snippet
.
content
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