Commit c8be7f1c authored by Mariusz Jachimowicz's avatar Mariusz Jachimowicz

api - expose label description

parent 6b95be1d
...@@ -4,6 +4,7 @@ v 8.7.0 (unreleased) ...@@ -4,6 +4,7 @@ v 8.7.0 (unreleased)
- Preserve time notes/comments have been updated at when moving issue - Preserve time notes/comments have been updated at when moving issue
- Make HTTP(s) label consistent on clone bar (Stan Hu) - Make HTTP(s) label consistent on clone bar (Stan Hu)
- Fix avatar stretching by providing a cropping feature - Fix avatar stretching by providing a cropping feature
- Expose label description in API (Mariusz Jachimowicz)
v 8.6.1 v 8.6.1
- Add option to reload the schema before restoring a database backup. !2807 - Add option to reload the schema before restoring a database backup. !2807
......
...@@ -9,7 +9,7 @@ GET /projects/:id/labels ...@@ -9,7 +9,7 @@ GET /projects/:id/labels
``` ```
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ------- | -------- | --------------------- |
| `id` | integer | yes | The ID of the project | | `id` | integer | yes | The ID of the project |
```bash ```bash
...@@ -22,35 +22,43 @@ Example response: ...@@ -22,35 +22,43 @@ Example response:
[ [
{ {
"name" : "bug", "name" : "bug",
"color" : "#d9534f" "color" : "#d9534f",
"description": "Bug reported by user"
}, },
{ {
"color" : "#d9534f", "color" : "#d9534f",
"name" : "confirmed" "name" : "confirmed",
"description": "Confirmed issue"
}, },
{ {
"name" : "critical", "name" : "critical",
"color" : "#d9534f" "color" : "#d9534f",
"description": "Criticalissue. Need fix ASAP"
}, },
{ {
"color" : "#428bca", "color" : "#428bca",
"name" : "discussion" "name" : "discussion",
"description": "Issue that needs further discussion"
}, },
{ {
"name" : "documentation", "name" : "documentation",
"color" : "#f0ad4e" "color" : "#f0ad4e",
"description": "Issue about documentation"
}, },
{ {
"color" : "#5cb85c", "color" : "#5cb85c",
"name" : "enhancement" "name" : "enhancement",
"description": "Enhancement proposal"
}, },
{ {
"color" : "#428bca", "color" : "#428bca",
"name" : "suggestion" "name" : "suggestion",
"description": "Suggestion"
}, },
{ {
"color" : "#f0ad4e", "color" : "#f0ad4e",
"name" : "support" "name" : "support",
"description": "Support issue"
} }
] ]
``` ```
...@@ -67,10 +75,11 @@ POST /projects/:id/labels ...@@ -67,10 +75,11 @@ POST /projects/:id/labels
``` ```
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | ------------- | ------- | -------- | ---------------------------- |
| `id` | integer | yes | The ID of the project | | `id` | integer | yes | The ID of the project |
| `name` | string | yes | The name of the label | | `name` | string | yes | The name of the label |
| `color` | string | yes | The color of the label in 6-digit hex notation with leading `#` sign | | `color` | string | yes | The color of the label in 6-digit hex notation with leading `#` sign |
| `description` | string | no | The description of the label |
```bash ```bash
curl --data "name=feature&color=#5843AD" -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/labels" curl --data "name=feature&color=#5843AD" -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/labels"
...@@ -81,7 +90,8 @@ Example response: ...@@ -81,7 +90,8 @@ Example response:
```json ```json
{ {
"name" : "feature", "name" : "feature",
"color" : "#5843AD" "color" : "#5843AD",
"description":null
} }
``` ```
...@@ -98,7 +108,7 @@ DELETE /projects/:id/labels ...@@ -98,7 +108,7 @@ DELETE /projects/:id/labels
``` ```
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ------- | -------- | --------------------- |
| `id` | integer | yes | The ID of the project | | `id` | integer | yes | The ID of the project |
| `name` | string | yes | The name of the label | | `name` | string | yes | The name of the label |
...@@ -112,6 +122,7 @@ Example response: ...@@ -112,6 +122,7 @@ Example response:
{ {
"title" : "feature", "title" : "feature",
"color" : "#5843AD", "color" : "#5843AD",
"description": "New feature proposal",
"updated_at" : "2015-11-03T21:22:30.737Z", "updated_at" : "2015-11-03T21:22:30.737Z",
"template" : false, "template" : false,
"project_id" : 1, "project_id" : 1,
...@@ -134,14 +145,15 @@ PUT /projects/:id/labels ...@@ -134,14 +145,15 @@ PUT /projects/:id/labels
``` ```
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------------- | ------- | --------------------------------- | ------------------------------- |
| `id` | integer | yes | The ID of the project | | `id` | integer | yes | The ID of the project |
| `name` | string | yes | The name of the existing label | | `name` | string | yes | The name of the existing label |
| `new_name` | string | yes if `color` if not provided | The new name of the label | | `new_name` | string | yes if `color` if not provided | The new name of the label |
| `color` | string | yes if `new_name` is not provided | The new color of the label in 6-digit hex notation with leading `#` sign | | `color` | string | yes if `new_name` is not provided | The new color of the label in 6-digit hex notation with leading `#` sign |
| `description` | string | no | The new description of the label |
```bash ```bash
curl -X PUT --data "name=documentation&new_name=docs&color=#8E44AD" -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/labels" curl -X PUT --data "name=documentation&new_name=docs&color=#8E44AD&description=Documentation" -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/labels"
``` ```
Example response: Example response:
...@@ -149,6 +161,7 @@ Example response: ...@@ -149,6 +161,7 @@ Example response:
```json ```json
{ {
"color" : "#8E44AD", "color" : "#8E44AD",
"name" : "docs" "name" : "docs",
"description": "Documentation"
} }
``` ```
...@@ -292,7 +292,7 @@ module API ...@@ -292,7 +292,7 @@ module API
end end
class Label < Grape::Entity class Label < Grape::Entity
expose :name, :color expose :name, :color, :description
end end
class Compare < Grape::Entity class Compare < Grape::Entity
......
...@@ -18,16 +18,17 @@ module API ...@@ -18,16 +18,17 @@ module API
# #
# Parameters: # Parameters:
# id (required) - The ID of a project # id (required) - The ID of a project
# name (required) - The name of the label to be deleted # name (required) - The name of the label to be created
# color (required) - Color of the label given in 6-digit hex # color (required) - Color of the label given in 6-digit hex
# notation with leading '#' sign (e.g. #FFAABB) # notation with leading '#' sign (e.g. #FFAABB)
# description (optional) - The description of label to be created
# Example Request: # Example Request:
# POST /projects/:id/labels # POST /projects/:id/labels
post ':id/labels' do post ':id/labels' do
authorize! :admin_label, user_project authorize! :admin_label, user_project
required_attributes! [:name, :color] required_attributes! [:name, :color]
attrs = attributes_for_keys [:name, :color] attrs = attributes_for_keys [:name, :color, :description]
label = user_project.find_label(attrs[:name]) label = user_project.find_label(attrs[:name])
conflict!('Label already exists') if label conflict!('Label already exists') if label
...@@ -67,6 +68,7 @@ module API ...@@ -67,6 +68,7 @@ module API
# new_name (optional) - The new name of the label # new_name (optional) - The new name of the label
# color (optional) - Color of the label given in 6-digit hex # color (optional) - Color of the label given in 6-digit hex
# notation with leading '#' sign (e.g. #FFAABB) # notation with leading '#' sign (e.g. #FFAABB)
# description (optional) - The description of label to be created
# Example Request: # Example Request:
# PUT /projects/:id/labels # PUT /projects/:id/labels
put ':id/labels' do put ':id/labels' do
...@@ -76,7 +78,7 @@ module API ...@@ -76,7 +78,7 @@ module API
label = user_project.find_label(params[:name]) label = user_project.find_label(params[:name])
not_found!('Label not found') unless label not_found!('Label not found') unless label
attrs = attributes_for_keys [:new_name, :color] attrs = attributes_for_keys [:new_name, :color, :description]
if attrs.empty? if attrs.empty?
render_api_error!('Required parameters "new_name" or "color" ' \ render_api_error!('Required parameters "new_name" or "color" ' \
......
...@@ -23,13 +23,25 @@ describe API::API, api: true do ...@@ -23,13 +23,25 @@ describe API::API, api: true do
end end
describe 'POST /projects/:id/labels' do describe 'POST /projects/:id/labels' do
it 'should return created label' do it 'should return created label when all params' do
post api("/projects/#{project.id}/labels", user),
name: 'Foo',
color: '#FFAABB',
description: 'test'
expect(response.status).to eq(201)
expect(json_response['name']).to eq('Foo')
expect(json_response['color']).to eq('#FFAABB')
expect(json_response['description']).to eq('test')
end
it 'should return created label when only required params' do
post api("/projects/#{project.id}/labels", user), post api("/projects/#{project.id}/labels", user),
name: 'Foo', name: 'Foo',
color: '#FFAABB' color: '#FFAABB'
expect(response.status).to eq(201) expect(response.status).to eq(201)
expect(json_response['name']).to eq('Foo') expect(json_response['name']).to eq('Foo')
expect(json_response['color']).to eq('#FFAABB') expect(json_response['color']).to eq('#FFAABB')
expect(json_response['description']).to be_nil
end end
it 'should return a 400 bad request if name not given' do it 'should return a 400 bad request if name not given' do
...@@ -94,14 +106,16 @@ describe API::API, api: true do ...@@ -94,14 +106,16 @@ describe API::API, api: true do
end end
describe 'PUT /projects/:id/labels' do describe 'PUT /projects/:id/labels' do
it 'should return 200 if name and colors are changed' do it 'should return 200 if name and colors and description are changed' do
put api("/projects/#{project.id}/labels", user), put api("/projects/#{project.id}/labels", user),
name: 'label1', name: 'label1',
new_name: 'New Label', new_name: 'New Label',
color: '#FFFFFF' color: '#FFFFFF',
description: 'test'
expect(response.status).to eq(200) expect(response.status).to eq(200)
expect(json_response['name']).to eq('New Label') expect(json_response['name']).to eq('New Label')
expect(json_response['color']).to eq('#FFFFFF') expect(json_response['color']).to eq('#FFFFFF')
expect(json_response['description']).to eq('test')
end end
it 'should return 200 if name is changed' do it 'should return 200 if name is changed' do
...@@ -122,6 +136,15 @@ describe API::API, api: true do ...@@ -122,6 +136,15 @@ describe API::API, api: true do
expect(json_response['color']).to eq('#FFFFFF') expect(json_response['color']).to eq('#FFFFFF')
end end
it 'should return 200 if description is changed' do
put api("/projects/#{project.id}/labels", user),
name: 'label1',
description: 'test'
expect(response.status).to eq(200)
expect(json_response['name']).to eq(label1.name)
expect(json_response['description']).to eq('test')
end
it 'should return 404 if label does not exist' do it 'should return 404 if label does not exist' do
put api("/projects/#{project.id}/labels", user), put api("/projects/#{project.id}/labels", user),
name: 'label2', name: 'label2',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment