summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/api/projects.md26
-rw-r--r--lib/api/entities.rb4
-rw-r--r--lib/api/projects.rb11
-rw-r--r--spec/requests/api/projects_spec.rb13
4 files changed, 54 insertions, 0 deletions
diff --git a/doc/api/projects.md b/doc/api/projects.md
index 6e82ddd9903..54618d7c045 100644
--- a/doc/api/projects.md
+++ b/doc/api/projects.md
@@ -621,3 +621,29 @@ Parameters:
+ query (required) - A string contained in the project name
+ per_page (optional) - number of projects to return per page
+ page (optional) - the page to retrieve
+
+
+## Labels
+
+### List project labels
+
+Get a list of project labels.
+
+```
+GET /projects/:id/labels
+```
+
+Parameters:
+
++ `id` (required) - The ID or NAMESPACE/PROJECT_NAME of a project
+
+```json
+[
+ {
+ "name":"featute"
+ },
+ {
+ "name": "bug"
+ }
+]
+```
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 8b4519af2d1..9fa8506926c 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -187,5 +187,9 @@ module API
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 4d48d2194f8..9d290c75ba9 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -215,6 +215,17 @@ module API
@users = paginate @users
present @users, with: Entities::User
end
+
+ # Get a project labels
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # Example Request:
+ # GET /projects/:id/labels
+ get ':id/labels' do
+ @labels = user_project.issues_labels
+ present @labels, with: Entities::Label
+ end
end
end
end
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb
index 149c5bffcda..7fe65639657 100644
--- a/spec/requests/api/projects_spec.rb
+++ b/spec/requests/api/projects_spec.rb
@@ -13,6 +13,7 @@ describe API::API do
let(:snippet) { create(:project_snippet, author: user, project: project, title: 'example') }
let(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) }
let(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) }
+ let(:issue_with_labels) { create(:issue, author: user, assignee: user, project: project, :label_list => "label1, label2") }
describe "GET /projects" do
before { project }
@@ -632,4 +633,16 @@ describe API::API do
end
end
end
+
+ describe "GET /projects/:id/labels" do
+ before { issue_with_labels }
+
+ 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 == issue_with_labels.labels.first.name
+ json_response.last['name'].should == issue_with_labels.labels.last.name
+ end
+ end
end