diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 8b4519af2d1ca9ad621544980f8db39671a3d701..9fa8506926c2b64eb5f738374a3c35397bbd1673 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -187,5 +187,9 @@ class ProjectWithAccess < Project end end end + + class Label < Grape::Entity + expose :name + end end end diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 4d48d2194f8007b75f62af269fb05092fcd897fd..40b5ce86c936738a45e74475ed7ae15212c860fd 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -215,6 +215,15 @@ def map_public_to_visibility_level(attrs) @users = paginate @users present @users, with: Entities::User end + + # Get a labels list + # + # Example Request: + # GET /users + get ':id/labels' do + @labels = user_project.issues_labels + present @labels, with: Entities::Label + end end end end diff --git a/spec/requests/api/labels_spec.rb b/spec/requests/api/labels_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..ba5efb6c603fa530d06b6370ebf889c57ac0c104 --- /dev/null +++ b/spec/requests/api/labels_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +describe API::API do + include ApiHelpers + before(:each) { ActiveRecord::Base.observers.enable(:user_observer) } + after(:each) { ActiveRecord::Base.observers.disable(:user_observer) } + + let(:user) { create(:user) } + let!(:project) { create(:project, namespace: user.namespace ) } + let!(:issue) { create(:issue, author: user, assignee: user, project: project, :label_list => "label1, label2") } + before { project.team << [user, :reporter] } + + + describe "GET /projects/:id/labels" do + it "should return project labels" do + get api("/projects/#{project.id}/labels", user) + response.status.should == 200 + json_response.should be_an Array + json_response.first['name'].should == 'label1' + json_response.last['name'].should == 'label2' + end + end + + +end +