Commit b8a9a240 authored by Robert Schilling's avatar Robert Schilling

Expose issue weight on the API

parent 7e9dafcd
---
title: Expose issue weight in the API
merge_request: 1023
author: Robert Schilling
......@@ -81,7 +81,8 @@ Example response:
"user_notes_count": 1,
"due_date": "2016-07-22",
"web_url": "http://example.com/example/example/issues/6",
"confidential": false
"confidential": false,
"weight": null
}
]
```
......@@ -160,7 +161,8 @@ Example response:
"user_notes_count": 1,
"due_date": null,
"web_url": "http://example.com/example/example/issues/1",
"confidential": false
"confidential": false,
"weight": null
}
]
```
......@@ -241,7 +243,8 @@ Example response:
"user_notes_count": 1,
"due_date": "2016-07-22",
"web_url": "http://example.com/example/example/issues/1",
"confidential": false
"confidential": false,
"weight": null
}
]
```
......@@ -307,7 +310,8 @@ Example response:
"user_notes_count": 1,
"due_date": null,
"web_url": "http://example.com/example/example/issues/1",
"confidential": false
"confidential": false,
"weight": null
}
```
......@@ -331,6 +335,7 @@ POST /projects/:id/issues
| `created_at` | string | no | Date time string, ISO 8601 formatted, e.g. `2016-03-11T03:45:40Z` (requires admin or project owner rights) |
| `due_date` | string | no | Date time string in the format YEAR-MONTH-DAY, e.g. `2016-03-11` |
| `merge_request_for_resolving_discussions` | integer | no | The IID of a merge request in which to resolve all issues. This will fill the issue with a default description and mark all discussions as resolved. When passing a description or title, these values will take precedence over the default values. |
| `weight` | integer | no | The weight of the issue in range 0 to 9 |
```bash
curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/4/issues?title=Issues%20with%20auth&labels=bug
......@@ -365,7 +370,8 @@ Example response:
"user_notes_count": 0,
"due_date": null,
"web_url": "http://example.com/example/example/issues/14",
"confidential": false
"confidential": false,
"weight": null
}
```
......@@ -391,6 +397,7 @@ PUT /projects/:id/issues/:issue_id
| `state_event` | string | no | The state event of an issue. Set `close` to close the issue and `reopen` to reopen it |
| `updated_at` | string | no | Date time string, ISO 8601 formatted, e.g. `2016-03-11T03:45:40Z` (requires admin or project owner rights) |
| `due_date` | string | no | Date time string in the format YEAR-MONTH-DAY, e.g. `2016-03-11` |
| `weight` | integer | no | The weight of the issue in range 0 to 9 |
```bash
curl --request PUT --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/4/issues/85?state_event=close
......@@ -425,7 +432,8 @@ Example response:
"user_notes_count": 0,
"due_date": "2016-07-22",
"web_url": "http://example.com/example/example/issues/15",
"confidential": false
"confidential": false,
"weight": null
}
```
......@@ -501,7 +509,8 @@ Example response:
},
"due_date": null,
"web_url": "http://example.com/example/example/issues/11",
"confidential": false
"confidential": false,
"weight": null
}
```
......@@ -556,7 +565,8 @@ Example response:
},
"due_date": null,
"web_url": "http://example.com/example/example/issues/11",
"confidential": false
"confidential": false,
"weight": null
}
```
......@@ -612,7 +622,8 @@ Example response:
"subscribed": false,
"due_date": null,
"web_url": "http://example.com/example/example/issues/12",
"confidential": false
"confidential": false,
"weight": null
}
```
......@@ -700,7 +711,8 @@ Example response:
"downvotes": 0,
"due_date": null,
"web_url": "http://example.com/example/example/issues/110",
"confidential": false
"confidential": false,
"weight": null
},
"target_url": "https://gitlab.example.com/gitlab-org/gitlab-ci/issues/10",
"body": "Vel voluptas atque dicta mollitia adipisci qui at.",
......
......@@ -113,7 +113,7 @@ module API
expose :request_access_enabled
expose :only_allow_merge_if_all_discussions_are_resolved
expose :approvals_before_merge
expose :statistics, using: 'API::Entities::ProjectStatistics', if: :statistics
end
......@@ -284,6 +284,7 @@ module API
expose :upvotes, :downvotes
expose :due_date
expose :confidential
expose :weight
expose :web_url do |issue, options|
Gitlab::UrlBuilder.build(issue)
......
......@@ -37,6 +37,8 @@ module API
optional :labels, type: String, desc: 'Comma-separated list of label names'
optional :due_date, type: String, desc: 'Date string in the format YEAR-MONTH-DAY'
optional :confidential, type: Boolean, desc: 'Boolean parameter if the issue should be confidential'
# Gitlab-EE specific
optional :weight, type: Integer, values: 0..9, desc: 'The weight of the issue'
end
end
......@@ -173,7 +175,8 @@ module API
optional :state_event, type: String, values: %w[reopen close], desc: 'State of the issue'
use :issue_params
at_least_one_of :title, :description, :assignee_id, :milestone_id,
:labels, :created_at, :due_date, :confidential, :state_event
:labels, :created_at, :due_date, :confidential, :state_event,
:weight
end
put ':id/issues/:issue_id' do
issue = user_project.issues.find(params.delete(:issue_id))
......
......@@ -535,6 +535,7 @@ describe API::Issues, api: true do
expect(json_response['assignee']).to be_a Hash
expect(json_response['author']).to be_a Hash
expect(json_response['confidential']).to be_falsy
expect(json_response['weight']).to be_nil
end
it "returns a project issue by id" do
......@@ -602,13 +603,14 @@ describe API::Issues, api: true do
describe "POST /projects/:id/issues" do
it 'creates a new project issue' do
post api("/projects/#{project.id}/issues", user),
title: 'new issue', labels: 'label, label2'
title: 'new issue', labels: 'label, label2', weight: 3
expect(response).to have_http_status(201)
expect(json_response['title']).to eq('new issue')
expect(json_response['description']).to be_nil
expect(json_response['labels']).to eq(['label', 'label2'])
expect(json_response['confidential']).to be_falsy
expect(json_response['weight']).to eq(3)
end
it 'creates a new confidential project issue' do
......@@ -963,6 +965,38 @@ describe API::Issues, api: true do
end
end
describe 'PUT /projects/:id/issues/:issue_id to update weight' do
it 'updates an issue with no weight' do
put api("/projects/#{project.id}/issues/#{issue.id}", user), weight: 5
expect(response).to have_http_status(200)
expect(json_response['weight']).to eq(5)
end
it 'removes a weight from an issue' do
weighted_issue = create(:issue, project: project, weight: 2)
put api("/projects/#{project.id}/issues/#{weighted_issue.id}", user), weight: nil
expect(response).to have_http_status(200)
expect(json_response['weight']).to be_nil
end
it 'returns 400 if weight is less than minimum weight' do
put api("/projects/#{project.id}/issues/#{issue.id}", user), weight: -1
expect(response).to have_http_status(400)
expect(json_response['error']).to eq('weight does not have a valid value')
end
it 'returns 400 if weight is more than maximum weight' do
put api("/projects/#{project.id}/issues/#{issue.id}", user), weight: 10
expect(response).to have_http_status(400)
expect(json_response['error']).to eq('weight does not have a valid value')
end
end
describe "DELETE /projects/:id/issues/:issue_id" do
it "rejects a non member from deleting an issue" do
delete api("/projects/#{project.id}/issues/#{issue.id}", non_member)
......
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