summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Schilling <rschilling@student.tugraz.at>2019-02-13 22:51:53 +0100
committerRobert Schilling <rschilling@student.tugraz.at>2019-08-26 10:45:37 +0200
commit41412f73604159ca735420396df73f7b6eef6f86 (patch)
tree64bac28e7e965699707331301995801fb5b6d330
parent2e83665ed30259a7908350d316605a9c100f0876 (diff)
downloadgitlab-ce-41412f73604159ca735420396df73f7b6eef6f86.tar.gz
Add docs and first specs
-rw-r--r--doc/api/labels.md34
-rw-r--r--lib/api/labels.rb6
-rw-r--r--spec/requests/api/labels_spec.rb23
3 files changed, 60 insertions, 3 deletions
diff --git a/doc/api/labels.md b/doc/api/labels.md
index fde1d861cf6..9b640a0203d 100644
--- a/doc/api/labels.md
+++ b/doc/api/labels.md
@@ -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
Subscribes the authenticated user to a label to receive notifications.
diff --git a/lib/api/labels.rb b/lib/api/labels.rb
index 5079d95c2b4..9f847c39fac 100644
--- a/lib/api/labels.rb
+++ b/lib/api/labels.rb
@@ -71,12 +71,12 @@ module API
requires :name, type: String, desc: 'The name of the label to be promoted'
end
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
- 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
present group_label, with: Entities::GroupLabel, current_user: current_user, parent: user_project.group
diff --git a/spec/requests/api/labels_spec.rb b/spec/requests/api/labels_spec.rb
index f6640fe41d0..047e8b6c507 100644
--- a/spec/requests/api/labels_spec.rb
+++ b/spec/requests/api/labels_spec.rb
@@ -473,6 +473,29 @@ describe API::Labels do
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
context "when label_id is a label title" do
it "subscribes to the label" do