Commit aca7d01d authored by Rémy Coutable's avatar Rémy Coutable

Merge remote-tracking branch 'origin/labels-api'

See merge request !7014
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 8c2b1f25
......@@ -6,6 +6,7 @@ Please view this file on the master branch, on stable branches it's out of date.
- Disable reference Markdown for unavailable features.
- Fix lightweight tags not processed correctly by GitTagPushService. !6532
- Allow owners to fetch source code in CI builds. !6943
- Return conflict error in label API when title is taken by group label. !7014
- Reduce the overhead to calculate number of open/closed issues and merge requests within the group or project. !7123
- Fix builds tab visibility. !7178
- Fix project features default values. !7181
......
......@@ -1097,10 +1097,6 @@ class Project < ActiveRecord::Base
forks.count
end
def find_label(name)
labels.find_by(name: name)
end
def origin_merge_requests
merge_requests.where(source_project_id: self.id)
end
......
......@@ -29,8 +29,8 @@ module API
required_attributes! [:name, :color]
attrs = attributes_for_keys [:name, :color, :description]
label = user_project.find_label(attrs[:name])
label = available_labels.find_by(title: attrs[:name])
conflict!('Label already exists') if label
label = user_project.labels.create(attrs)
......@@ -54,7 +54,7 @@ module API
authorize! :admin_label, user_project
required_attributes! [:name]
label = user_project.find_label(params[:name])
label = user_project.labels.find_by(title: params[:name])
not_found!('Label') unless label
label.destroy
......@@ -75,7 +75,7 @@ module API
authorize! :admin_label, user_project
required_attributes! [:name]
label = user_project.find_label(params[:name])
label = user_project.labels.find_by(title: params[:name])
not_found!('Label not found') unless label
attrs = attributes_for_keys [:new_name, :color, :description]
......
......@@ -82,7 +82,20 @@ describe API::API, api: true do
expect(json_response['message']['title']).to eq(['is invalid'])
end
it 'returns 409 if label already exists' do
it 'returns 409 if label already exists in group' do
group = create(:group)
group_label = create(:group_label, group: group)
project.update(group: group)
post api("/projects/#{project.id}/labels", user),
name: group_label.name,
color: '#FFAABB'
expect(response).to have_http_status(409)
expect(json_response['message']).to eq('Label already exists')
end
it 'returns 409 if label already exists in project' do
post api("/projects/#{project.id}/labels", user),
name: 'label1',
color: '#FFAABB'
......
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