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
b5ef6d22
Commit
b5ef6d22
authored
Mar 05, 2013
by
Sebastian Ziebell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API: refactored and simplified error handling in merge requests API
parent
cce35b6d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
18 deletions
+8
-18
lib/api/merge_requests.rb
lib/api/merge_requests.rb
+6
-17
lib/api/projects.rb
lib/api/projects.rb
+2
-1
No files found.
lib/api/merge_requests.rb
View file @
b5ef6d22
...
@@ -4,21 +4,12 @@ module Gitlab
...
@@ -4,21 +4,12 @@ module Gitlab
before
{
authenticate!
}
before
{
authenticate!
}
resource
:projects
do
resource
:projects
do
helpers
do
helpers
do
# If an error occurred this helper method provides an appropriate status code
def
handle_merge_request_errors!
(
errors
)
#
if
errors
[
:project_access
].
any?
# Parameters:
error!
(
errors
[
:project_access
],
422
)
# merge_request_errors (required) - The errors collection of MR
#
def
handle_merge_request_error
(
merge_request_errors
)
if
merge_request_errors
[
:target_branch
].
any?
bad_request!
(
:target_branch
)
elsif
merge_request_errors
[
:source_branch
].
any?
bad_request!
(
:source_branch
)
elsif
merge_request_errors
[
:base
].
any?
error!
(
merge_request_errors
[
:base
],
422
)
end
end
not_found!
end
end
end
end
...
@@ -78,8 +69,7 @@ module Gitlab
...
@@ -78,8 +69,7 @@ module Gitlab
merge_request
.
reload_code
merge_request
.
reload_code
present
merge_request
,
with:
Entities
::
MergeRequest
present
merge_request
,
with:
Entities
::
MergeRequest
else
else
handle_merge_request_error
(
merge_request
.
errors
)
handle_merge_request_errors!
merge_request
.
errors
not_found!
end
end
end
end
...
@@ -107,8 +97,7 @@ module Gitlab
...
@@ -107,8 +97,7 @@ module Gitlab
merge_request
.
mark_as_unchecked
merge_request
.
mark_as_unchecked
present
merge_request
,
with:
Entities
::
MergeRequest
present
merge_request
,
with:
Entities
::
MergeRequest
else
else
handle_merge_request_error
(
merge_request
.
errors
)
handle_merge_request_errors!
merge_request
.
errors
not_found!
end
end
end
end
...
...
lib/api/projects.rb
View file @
b5ef6d22
...
@@ -233,7 +233,7 @@ module Gitlab
...
@@ -233,7 +233,7 @@ module Gitlab
end
end
end
end
# Delete
project hook
# Delete
s project hook. This is an idempotent function.
#
#
# Parameters:
# Parameters:
# id (required) - The ID of a project
# id (required) - The ID of a project
...
@@ -248,6 +248,7 @@ module Gitlab
...
@@ -248,6 +248,7 @@ module Gitlab
@hook
=
ProjectHook
.
find
(
params
[
:hook_id
])
@hook
=
ProjectHook
.
find
(
params
[
:hook_id
])
@hook
.
destroy
@hook
.
destroy
rescue
rescue
# ProjectHook can raise Error if hook_id not found
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