Commit 21ae36c6 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'update_api_messages' into 'master'

Update api messages

See merge request !1364
parents de6256ee 1fbeaa06
......@@ -13,6 +13,7 @@ v 7.7.0
- Set project path instead of project name in create form
-
-
- Updates to the messages returned by API (sponsored by O'Reilly Media)
- New UI layout with side navigation
-
-
......
......@@ -14,7 +14,8 @@ module API
# Example Request:
# GET /projects/:id/repository/branches
get ":id/repository/branches" do
present user_project.repository.branches.sort_by(&:name), with: Entities::RepoObject, project: user_project
branches = user_project.repository.branches.sort_by(&:name)
present branches, with: Entities::RepoObject, project: user_project
end
# Get a single branch
......@@ -26,7 +27,7 @@ module API
# GET /projects/:id/repository/branches/:branch
get ':id/repository/branches/:branch', requirements: { branch: /.*/ } do
@branch = user_project.repository.branches.find { |item| item.name == params[:branch] }
not_found!("Branch does not exist") if @branch.nil?
not_found!("Branch") unless @branch
present @branch, with: Entities::RepoObject, project: user_project
end
......@@ -43,7 +44,7 @@ module API
authorize_admin_project
@branch = user_project.repository.find_branch(params[:branch])
not_found! unless @branch
not_found!("Branch") unless @branch
protected_branch = user_project.protected_branches.find_by(name: @branch.name)
user_project.protected_branches.create(name: @branch.name) unless protected_branch
......@@ -63,7 +64,7 @@ module API
authorize_admin_project
@branch = user_project.repository.find_branch(params[:branch])
not_found! unless @branch
not_found!("Branch does not exist") unless @branch
protected_branch = user_project.protected_branches.find_by(name: @branch.name)
protected_branch.destroy if protected_branch
......
......@@ -108,7 +108,7 @@ module API
if note.save
present note, with: Entities::CommitNote
else
not_found!
render_api_error!("Failed to save note #{note.errors.messages}", 400)
end
end
end
......
......@@ -35,7 +35,7 @@ module API
file_path = attrs.delete(:file_path)
commit = user_project.repository.commit(ref)
not_found! "Commit" unless commit
not_found! 'Commit' unless commit
blob = user_project.repository.blob_at(commit.sha, file_path)
......@@ -53,7 +53,7 @@ module API
commit_id: commit.id,
}
else
render_api_error!('File not found', 404)
not_found! 'File'
end
end
......
......@@ -54,7 +54,7 @@ module API
if @group.save
present @group, with: Entities::Group
else
not_found!
render_api_error!("Failed to save group #{@group.errors.messages}", 400)
end
end
......@@ -97,7 +97,7 @@ module API
if result
present group
else
not_found!
render_api_error!("Failed to transfer project #{project.errors.messages}", 400)
end
end
end
......
......@@ -42,7 +42,7 @@ module API
def user_project
@project ||= find_project(params[:id])
@project || not_found!
@project || not_found!("Project")
end
def find_project(id)
......
......@@ -233,7 +233,7 @@ module API
if note.save
present note, with: Entities::MRNote
else
render_validation_error!(note)
render_api_error!("Failed to save note #{note.errors.messages}", 400)
end
end
end
......
......@@ -48,7 +48,7 @@ module API
if milestone.valid?
present milestone, with: Entities::Milestone
else
not_found!
render_api_error!("Failed to create milestone #{milestone.errors.messages}", 400)
end
end
......@@ -72,7 +72,7 @@ module API
if milestone.valid?
present milestone, with: Entities::Milestone
else
not_found!
render_api_error!("Failed to update milestone #{milestone.errors.messages}", 400)
end
end
end
......
......@@ -61,7 +61,7 @@ module API
if @note.valid?
present @note, with: Entities::Note
else
not_found!
not_found!("Note #{@note.errors.messages}")
end
end
......@@ -93,7 +93,7 @@ module API
if @note.valid?
present @note, with: Entities::Note
else
bad_request!('Invalid note')
render_api_error!("Failed to save note #{note.errors.messages}", 400)
end
end
......
......@@ -53,7 +53,7 @@ module API
if @hook.errors[:url].present?
error!("Invalid url given", 422)
end
not_found!
not_found!("Project hook #{@hook.errors.messages}")
end
end
......@@ -82,7 +82,7 @@ module API
if @hook.errors[:url].present?
error!("Invalid url given", 422)
end
not_found!
not_found!("Project hook #{@hook.errors.messages}")
end
end
......
......@@ -9,7 +9,7 @@ module API
if errors[:access_level].any?
error!(errors[:access_level], 422)
end
not_found!
not_found!(errors)
end
end
......
......@@ -227,7 +227,7 @@ module API
render_api_error!("Project already forked", 409)
end
else
not_found!
not_found!("Source Project")
end
end
......
......@@ -133,7 +133,7 @@ module API
env['api.format'] = :binary
present data
else
not_found!
not_found!('File')
end
end
......
......@@ -44,7 +44,7 @@ describe API::API, api: true do
it 'should fail on missing project access for the project to fork' do
post api("/projects/fork/#{project.id}", user3)
response.status.should == 404
json_response['message'].should == '404 Not Found'
json_response['message'].should == '404 Project Not Found'
end
it 'should fail if forked project exists in the user namespace' do
......@@ -58,7 +58,7 @@ describe API::API, api: true do
it 'should fail if project to fork from does not exist' do
post api('/projects/fork/424242', user)
response.status.should == 404
json_response['message'].should == '404 Not Found'
json_response['message'].should == '404 Project Not Found'
end
end
......
......@@ -91,7 +91,8 @@ describe API::API, api: true do
it "should not create group, duplicate" do
post api("/groups", admin), {name: "Duplicate Test", path: group2.path}
response.status.should == 404
response.status.should == 400
response.message.should == "Bad Request"
end
it "should return 400 bad request error if name not given" do
......
......@@ -289,7 +289,7 @@ describe API::API, api: true do
it "should return a 404 error if not found" do
get api("/projects/42", user)
response.status.should == 404
json_response['message'].should == '404 Not Found'
json_response['message'].should == '404 Project Not Found'
end
it "should return a 404 error if user is not a member" do
......@@ -340,7 +340,7 @@ describe API::API, api: true do
it "should return a 404 error if not found" do
get api("/projects/42/events", user)
response.status.should == 404
json_response['message'].should == '404 Not Found'
json_response['message'].should == '404 Project Not Found'
end
it "should return a 404 error if user is not a member" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment