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