Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorRobert Schilling <rschilling@student.tugraz.at>2014-08-13 14:23:51 +0400
committerRobert Schilling <rschilling@student.tugraz.at>2014-08-13 14:29:03 +0400
commitcf3ba0209dc7dc8b9ac93d574a8f6296b858be40 (patch)
tree07fa92aa498deb4866ba6f75ed2e9cf03e1a2df6 /lib/api
parent9284038dbef5153dac40eda14f1685a72efe1d1a (diff)
Update labels via API
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/labels.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/api/labels.rb b/lib/api/labels.rb
index dc61294d588..c73a4dbe916 100644
--- a/lib/api/labels.rb
+++ b/lib/api/labels.rb
@@ -60,6 +60,41 @@ module API
label.destroy
end
+
+ # Updates an existing label. At least one optional parameter is required.
+ #
+ # Parameters:
+ # id (required) - The ID of a project
+ # name (optional) - The name of the label to be deleted
+ # color (optional) - Color of the label given in 6-digit hex
+ # notation with leading '#' sign (e.g. #FFAABB)
+ # Example Request:
+ # PUT /projects/:id/labels
+ put ':id/labels' do
+ required_attributes! [:name]
+
+ label = user_project.find_label(params[:name])
+ if !label
+ return render_api_error!('Label not found', 404)
+ end
+
+ attrs = attributes_for_keys [:new_name, :color]
+
+ if attrs.empty?
+ return render_api_error!('Required parameters "name" or "color" ' \
+ 'missing',
+ 400)
+ end
+
+ # Rename new name to the actual label attribute name
+ attrs[:name] = attrs.delete(:new_name) if attrs.key?(:new_name)
+
+ if label.update(attrs)
+ present label, with: Entities::Label
+ else
+ render_api_error!(label.errors.full_messages.join(', '), 405)
+ end
+ end
end
end
end