Commit a7aacb4dc4d2cb3875db22dee830553462100a20
Exists in
spb-stable
and in
3 other branches
Merge pull request #6586 from abner/master
added api method to return labels of a given project
Showing
4 changed files
with
54 additions
and
0 deletions
Show diff stats
doc/api/projects.md
| @@ -621,3 +621,29 @@ Parameters: | @@ -621,3 +621,29 @@ Parameters: | ||
| 621 | + query (required) - A string contained in the project name | 621 | + query (required) - A string contained in the project name |
| 622 | + per_page (optional) - number of projects to return per page | 622 | + per_page (optional) - number of projects to return per page |
| 623 | + page (optional) - the page to retrieve | 623 | + page (optional) - the page to retrieve |
| 624 | + | ||
| 625 | + | ||
| 626 | +## Labels | ||
| 627 | + | ||
| 628 | +### List project labels | ||
| 629 | + | ||
| 630 | +Get a list of project labels. | ||
| 631 | + | ||
| 632 | +``` | ||
| 633 | +GET /projects/:id/labels | ||
| 634 | +``` | ||
| 635 | + | ||
| 636 | +Parameters: | ||
| 637 | + | ||
| 638 | ++ `id` (required) - The ID or NAMESPACE/PROJECT_NAME of a project | ||
| 639 | + | ||
| 640 | +```json | ||
| 641 | +[ | ||
| 642 | + { | ||
| 643 | + "name":"featute" | ||
| 644 | + }, | ||
| 645 | + { | ||
| 646 | + "name": "bug" | ||
| 647 | + } | ||
| 648 | +] | ||
| 649 | +``` |
lib/api/entities.rb
lib/api/projects.rb
| @@ -215,6 +215,17 @@ module API | @@ -215,6 +215,17 @@ module API | ||
| 215 | @users = paginate @users | 215 | @users = paginate @users |
| 216 | present @users, with: Entities::User | 216 | present @users, with: Entities::User |
| 217 | end | 217 | end |
| 218 | + | ||
| 219 | + # Get a project labels | ||
| 220 | + # | ||
| 221 | + # Parameters: | ||
| 222 | + # id (required) - The ID of a project | ||
| 223 | + # Example Request: | ||
| 224 | + # GET /projects/:id/labels | ||
| 225 | + get ':id/labels' do | ||
| 226 | + @labels = user_project.issues_labels | ||
| 227 | + present @labels, with: Entities::Label | ||
| 228 | + end | ||
| 218 | end | 229 | end |
| 219 | end | 230 | end |
| 220 | end | 231 | end |
spec/requests/api/projects_spec.rb
| @@ -13,6 +13,7 @@ describe API::API do | @@ -13,6 +13,7 @@ describe API::API do | ||
| 13 | let(:snippet) { create(:project_snippet, author: user, project: project, title: 'example') } | 13 | let(:snippet) { create(:project_snippet, author: user, project: project, title: 'example') } |
| 14 | let(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) } | 14 | let(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) } |
| 15 | let(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) } | 15 | let(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) } |
| 16 | + let(:issue_with_labels) { create(:issue, author: user, assignee: user, project: project, :label_list => "label1, label2") } | ||
| 16 | 17 | ||
| 17 | describe "GET /projects" do | 18 | describe "GET /projects" do |
| 18 | before { project } | 19 | before { project } |
| @@ -632,4 +633,16 @@ describe API::API do | @@ -632,4 +633,16 @@ describe API::API do | ||
| 632 | end | 633 | end |
| 633 | end | 634 | end |
| 634 | end | 635 | end |
| 636 | + | ||
| 637 | + describe "GET /projects/:id/labels" do | ||
| 638 | + before { issue_with_labels } | ||
| 639 | + | ||
| 640 | + it "should return project labels" do | ||
| 641 | + get api("/projects/#{project.id}/labels", user) | ||
| 642 | + response.status.should == 200 | ||
| 643 | + json_response.should be_an Array | ||
| 644 | + json_response.first['name'].should == issue_with_labels.labels.first.name | ||
| 645 | + json_response.last['name'].should == issue_with_labels.labels.last.name | ||
| 646 | + end | ||
| 647 | + end | ||
| 635 | end | 648 | end |