Add docs and first specs

This commit is contained in:
Robert Schilling 2019-02-13 22:51:53 +01:00
parent 2e83665ed3
commit 41412f7360
3 changed files with 60 additions and 3 deletions

View File

@ -186,6 +186,40 @@ Example response:
} }
``` ```
## Promote a project label to a group label
> [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/25218) in GitLab 11.9.
Promotes a project label to a group label.
```
POST /projects/:id/labels/promote
```
| Attribute | Type | Required | Description |
| --------------- | ------- | --------------------------------- | ------------------------------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
| `name` | string | yes | The name of the existing label |
```bash
curl --request POST --data "name=documentation" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/labels/promote"
```
Example response:
```json
{
"id" : 8,
"name" : "documentation",
"color" : "#8E44AD",
"description": "Documentation",
"open_issues_count": 1,
"closed_issues_count": 0,
"open_merge_requests_count": 2,
"subscribed": false
}
```
## Subscribe to a label ## Subscribe to a label
Subscribes the authenticated user to a label to receive notifications. Subscribes the authenticated user to a label to receive notifications.

View File

@ -71,12 +71,12 @@ module API
requires :name, type: String, desc: 'The name of the label to be promoted' requires :name, type: String, desc: 'The name of the label to be promoted'
end end
post ':id/labels/promote' do post ':id/labels/promote' do
authorize! :admin_label, parent authorize! :admin_label, user_project
label = find_label(parent, params[:name], include_ancestor_groups: false) label = find_label(user_project, params[:name], include_ancestor_groups: false)
begin begin
group_label = Labels::PromoteService.new(user_project, current_user).execute(label) group_label = ::Labels::PromoteService.new(user_project, current_user).execute(label)
if group_label if group_label
present group_label, with: Entities::GroupLabel, current_user: current_user, parent: user_project.group present group_label, with: Entities::GroupLabel, current_user: current_user, parent: user_project.group

View File

@ -473,6 +473,29 @@ describe API::Labels do
end end
end end
describe 'POST /projects/:id/labels/promote' do
it 'returns 200 if label is promoted' do
post api("/projects/#{project.id}/labels/promote", user), params: { name: 'label1' }
expect(response).to have_gitlab_http_status(200)
expect(json_response['name']).to eq(label1.name)
expect(json_response['color']).to eq('#FFFFFF')
end
it 'returns 404 if label does not exist' do
post api("/projects/#{project.id}/labels/promote", user), params: { name: 'unknown' }
expect(response).to have_gitlab_http_status(404)
end
it 'returns 400 if no label name given' do
post api("/projects/#{project.id}/labels/promote", user)
expect(response).to have_gitlab_http_status(400)
expect(json_response['error']).to eq('name is missing')
end
end
describe "POST /projects/:id/labels/:label_id/subscribe" do describe "POST /projects/:id/labels/:label_id/subscribe" do
context "when label_id is a label title" do context "when label_id is a label title" do
it "subscribes to the label" do it "subscribes to the label" do