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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
549c4c22
Commit
549c4c22
authored
Sep 16, 2012
by
Alex Denisov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API attributes refactored
parent
caef9ed1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
52 deletions
+36
-52
lib/api/helpers.rb
lib/api/helpers.rb
+8
-0
lib/api/issues.rb
lib/api/issues.rb
+6
-18
lib/api/milestones.rb
lib/api/milestones.rb
+4
-14
lib/api/projects.rb
lib/api/projects.rb
+18
-20
No files found.
lib/api/helpers.rb
View file @
549c4c22
...
@@ -28,6 +28,14 @@ module Gitlab
...
@@ -28,6 +28,14 @@ module Gitlab
end
end
end
end
def
existed_attributes
(
keys
)
attrs
=
{}
keys
.
each
do
|
key
|
attrs
[
key
]
=
params
[
key
]
if
params
[
key
].
present?
end
attrs
end
# error helpers
# error helpers
def
forbidden!
def
forbidden!
...
...
lib/api/issues.rb
View file @
549c4c22
...
@@ -48,15 +48,10 @@ module Gitlab
...
@@ -48,15 +48,10 @@ module Gitlab
# Example Request:
# Example Request:
# POST /projects/:id/issues
# POST /projects/:id/issues
post
":id/issues"
do
post
":id/issues"
do
@issue
=
user_project
.
issues
.
new
(
attrs
=
existed_attributes
[
:title
,
:description
,
:assignee_id
,
:milestone_id
]
title:
params
[
:title
],
attrs
[
:label_list
]
=
params
[
:labels
]
if
params
[
:labels
].
present?
description:
params
[
:description
],
@issue
=
user_project
.
issues
.
new
attrs
assignee_id:
params
[
:assignee_id
],
milestone_id:
params
[
:milestone_id
],
label_list:
params
[
:labels
]
)
@issue
.
author
=
current_user
@issue
.
author
=
current_user
if
@issue
.
save
if
@issue
.
save
present
@issue
,
with:
Entities
::
Issue
present
@issue
,
with:
Entities
::
Issue
else
else
...
@@ -81,16 +76,9 @@ module Gitlab
...
@@ -81,16 +76,9 @@ module Gitlab
@issue
=
user_project
.
issues
.
find
(
params
[
:issue_id
])
@issue
=
user_project
.
issues
.
find
(
params
[
:issue_id
])
authorize!
:modify_issue
,
@issue
authorize!
:modify_issue
,
@issue
parameters
=
{
attrs
=
existed_attributes
[
:title
,
:description
,
:assignee_id
,
:milestone_id
,
:closed
]
title:
(
params
[
:title
]
||
@issue
.
title
),
attrs
[
:label_list
]
=
params
[
:labels
]
if
params
[
:labels
].
present?
description:
(
params
[
:description
]
||
@issue
.
description
),
if
@issue
.
update_attributes
attrs
assignee_id:
(
params
[
:assignee_id
]
||
@issue
.
assignee_id
),
milestone_id:
(
params
[
:milestone_id
]
||
@issue
.
milestone_id
),
label_list:
(
params
[
:labels
]
||
@issue
.
label_list
),
closed:
(
params
[
:closed
]
||
@issue
.
closed
)
}
if
@issue
.
update_attributes
(
parameters
)
present
@issue
,
with:
Entities
::
Issue
present
@issue
,
with:
Entities
::
Issue
else
else
not_found!
not_found!
...
...
lib/api/milestones.rb
View file @
549c4c22
...
@@ -36,12 +36,8 @@ module Gitlab
...
@@ -36,12 +36,8 @@ module Gitlab
# Example Request:
# Example Request:
# POST /projects/:id/milestones
# POST /projects/:id/milestones
post
":id/milestones"
do
post
":id/milestones"
do
@milestone
=
user_project
.
milestones
.
new
(
attrs
=
existed_attributes
[
:title
,
:description
,
:due_date
]
title:
params
[
:title
],
@milestone
=
user_project
.
milestones
.
new
attrs
description:
params
[
:description
],
due_date:
params
[
:due_date
]
)
if
@milestone
.
save
if
@milestone
.
save
present
@milestone
,
with:
Entities
::
Milestone
present
@milestone
,
with:
Entities
::
Milestone
else
else
...
@@ -64,14 +60,8 @@ module Gitlab
...
@@ -64,14 +60,8 @@ module Gitlab
authorize!
:admin_milestone
,
user_project
authorize!
:admin_milestone
,
user_project
@milestone
=
user_project
.
milestones
.
find
(
params
[
:milestone_id
])
@milestone
=
user_project
.
milestones
.
find
(
params
[
:milestone_id
])
parameters
=
{
attrs
=
existed_attributes
[
:title
,
:description
,
:due_date
,
:closed
]
title:
(
params
[
:title
]
||
@milestone
.
title
),
if
@milestone
.
update_attributes
attrs
description:
(
params
[
:description
]
||
@milestone
.
description
),
due_date:
(
params
[
:due_date
]
||
@milestone
.
due_date
),
closed:
(
params
[
:closed
]
||
@milestone
.
closed
)
}
if
@milestone
.
update_attributes
(
parameters
)
present
@milestone
,
with:
Entities
::
Milestone
present
@milestone
,
with:
Entities
::
Milestone
else
else
not_found!
not_found!
...
...
lib/api/projects.rb
View file @
549c4c22
...
@@ -40,13 +40,16 @@ module Gitlab
...
@@ -40,13 +40,16 @@ module Gitlab
post
do
post
do
params
[
:code
]
||=
params
[
:name
]
params
[
:code
]
||=
params
[
:name
]
params
[
:path
]
||=
params
[
:name
]
params
[
:path
]
||=
params
[
:name
]
project_attrs
=
{}
attrs
=
existed_attributes
[
:code
,
params
.
each_pair
do
|
k
,
v
|
:path
,
if
Project
.
attribute_names
.
include?
k
:name
,
project_attrs
[
k
]
=
v
:description
,
end
:default_branch
,
end
:issues_enabled
,
@project
=
Project
.
create_by_user
(
project_attrs
,
current_user
)
:wall_enabled
,
:merge_requests_enabled
,
:wiki_enabled
]
@project
=
Project
.
create_by_user
(
attrs
,
current_user
)
if
@project
.
saved?
if
@project
.
saved?
present
@project
,
with:
Entities
::
Project
present
@project
,
with:
Entities
::
Project
else
else
...
@@ -204,12 +207,10 @@ module Gitlab
...
@@ -204,12 +207,10 @@ module Gitlab
# Example Request:
# Example Request:
# POST /projects/:id/snippets
# POST /projects/:id/snippets
post
":id/snippets"
do
post
":id/snippets"
do
@snippet
=
user_project
.
snippets
.
new
(
attrs
=
existed_attributes
[
:title
,
:file_name
]
title:
params
[
:title
],
attrs
[
:expires_at
]
=
params
[
:lifetime
]
if
params
[
:lifetime
].
present?
file_name:
params
[
:file_name
],
attrs
[
:content
]
=
params
[
:code
]
if
params
[
:code
].
present?
expires_at:
params
[
:lifetime
],
@snippet
=
user_project
.
snippets
.
new
attrs
content:
params
[
:code
]
)
@snippet
.
author
=
current_user
@snippet
.
author
=
current_user
if
@snippet
.
save
if
@snippet
.
save
...
@@ -234,14 +235,11 @@ module Gitlab
...
@@ -234,14 +235,11 @@ module Gitlab
@snippet
=
user_project
.
snippets
.
find
(
params
[
:snippet_id
])
@snippet
=
user_project
.
snippets
.
find
(
params
[
:snippet_id
])
authorize!
:modify_snippet
,
@snippet
authorize!
:modify_snippet
,
@snippet
parameters
=
{
attrs
=
existed_attributes
[
:title
,
:file_name
]
title:
(
params
[
:title
]
||
@snippet
.
title
),
attrs
[
:expires_at
]
=
params
[
:lifetime
]
if
params
[
:lifetime
].
present?
file_name:
(
params
[
:file_name
]
||
@snippet
.
file_name
),
attrs
[
:content
]
=
params
[
:code
]
if
params
[
:code
].
present?
expires_at:
(
params
[
:lifetime
]
||
@snippet
.
expires_at
),
content:
(
params
[
:code
]
||
@snippet
.
content
)
}
if
@snippet
.
update_attributes
(
parameters
)
if
@snippet
.
update_attributes
attrs
present
@snippet
,
with:
Entities
::
ProjectSnippet
present
@snippet
,
with:
Entities
::
ProjectSnippet
else
else
not_found!
not_found!
...
...
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