diff options
author | Robert Schilling <rschilling@student.tugraz.at> | 2014-08-12 14:16:25 +0200 |
---|---|---|
committer | Robert Schilling <rschilling@student.tugraz.at> | 2014-08-13 12:28:19 +0200 |
commit | 9284038dbef5153dac40eda14f1685a72efe1d1a (patch) | |
tree | 1b195e94518f115316da6f98195943dc8d22c2c0 /lib/api | |
parent | 53ead2e35c9195ae1f68bf5d7154e341636caf1b (diff) | |
download | gitlab-ce-9284038dbef5153dac40eda14f1685a72efe1d1a.tar.gz |
Add, delete labels via API
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/api.rb | 1 | ||||
-rw-r--r-- | lib/api/entities.rb | 2 | ||||
-rw-r--r-- | lib/api/labels.rb | 65 | ||||
-rw-r--r-- | lib/api/projects.rb | 11 |
4 files changed, 67 insertions, 12 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb index ce4cc8b34f7..2c7cd9038c3 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -46,5 +46,6 @@ module API mount Commits mount Namespaces mount Branches + mount Labels end end diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 8731db59e57..9f1e5cded53 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -192,7 +192,7 @@ module API end class Label < Grape::Entity - expose :name + expose :name, :color end class RepoDiff < Grape::Entity diff --git a/lib/api/labels.rb b/lib/api/labels.rb new file mode 100644 index 00000000000..dc61294d588 --- /dev/null +++ b/lib/api/labels.rb @@ -0,0 +1,65 @@ +module API + # Labels API + class Labels < Grape::API + before { authenticate! } + + resource :projects do + # Get all labels of the project + # + # Parameters: + # id (required) - The ID of a project + # Example Request: + # GET /projects/:id/labels + get ':id/labels' do + present user_project.labels, with: Entities::Label + end + + # Creates a new label + # + # Parameters: + # id (required) - The ID of a project + # name (required) - The name of the label to be deleted + # color (required) - Color of the label given in 6-digit hex + # notation with leading '#' sign (e.g. #FFAABB) + # Example Request: + # POST /projects/:id/labels + post ':id/labels' do + required_attributes! [:name, :color] + + attrs = attributes_for_keys [:name, :color] + label = user_project.find_label(attrs[:name]) + + if label + return render_api_error!('Label already exists', 409) + end + + label = user_project.labels.create(attrs) + + if label.valid? + present label, with: Entities::Label + else + render_api_error!(label.errors.full_messages.join(', '), 405) + end + end + + # Deletes an existing label + # + # Parameters: + # id (required) - The ID of a project + # name (required) - The name of the label to be deleted + # + # Example Request: + # DELETE /projects/:id/labels + delete ':id/labels' do + required_attributes! [:name] + + label = user_project.find_label(params[:name]) + if !label + return render_api_error!('Label not found', 404) + end + + label.destroy + end + end + end +end diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 149678e6803..55f7975bbf7 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -224,17 +224,6 @@ module API @users = paginate @users present @users, with: Entities::UserBasic 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.labels - present @labels, with: Entities::Label - end end end end |