diff options
author | Robert Schilling <rschilling@student.tugraz.at> | 2019-02-18 15:27:05 +0100 |
---|---|---|
committer | Robert Schilling <rschilling@student.tugraz.at> | 2019-02-18 19:57:20 +0100 |
commit | 3a6f44511bb8f3022588c03334257ce9b80a7a19 (patch) | |
tree | 5bc4ce71c340b52f6d372aa5717f38b7e7e8a1cd | |
parent | 43c1dd9a342d0fe6284a207df244aa709e0da584 (diff) | |
download | gitlab-ce-57657-promote-label-to-group-label-via-api-endpoint.tar.gz |
-rw-r--r-- | app/services/labels/promote_service.rb | 16 | ||||
-rw-r--r-- | spec/requests/api/labels_spec.rb | 17 |
2 files changed, 33 insertions, 0 deletions
diff --git a/app/services/labels/promote_service.rb b/app/services/labels/promote_service.rb index e73e6476c12..a29a6da46ba 100644 --- a/app/services/labels/promote_service.rb +++ b/app/services/labels/promote_service.rb @@ -9,9 +9,13 @@ module Labels return unless project.group && label.is_a?(ProjectLabel) + pp "First check" + Label.transaction do new_label = clone_label_to_group_label(label) + pp "label cloned" + label_ids_for_merge(new_label).find_in_batches(batch_size: BATCH_SIZE) do |batched_ids| update_issuables(new_label, batched_ids) update_resource_label_events(new_label, batched_ids) @@ -22,9 +26,14 @@ module Labels update_project_labels(batched_ids) end + pp "pre validation" + + # We skipped validations during creation. Let's run them now, after deleting conflicting labels raise ActiveRecord::RecordInvalid.new(new_label) unless new_label.valid? + pp "validated" + new_label end end @@ -93,12 +102,19 @@ module Labels def clone_label_to_group_label(label) params = label.attributes.slice('title', 'description', 'color') + + pp "clone label" + pp label + pp params # Since the title of the new label has to be the same as the previous labels # and we're merging old labels in batches we'll skip validation to omit 2-step # merge process and do it in one batch # We'll be forcing validation at the end of the transaction to ensure everything # was merged correctly new_label = GroupLabel.new(params.merge(group: project.group)) + + pp new_label + new_label.save(validate: false) new_label diff --git a/spec/requests/api/labels_spec.rb b/spec/requests/api/labels_spec.rb index c601ff29664..8e83642bab9 100644 --- a/spec/requests/api/labels_spec.rb +++ b/spec/requests/api/labels_spec.rb @@ -380,10 +380,27 @@ describe API::Labels do end it 'returns 400 if group label already exists' do + pp label1 + create(:group_label, title: label1.name, group: group) + pp group.labels + l = group.labels.first + pp l.title + + pp l.group + pp project.labels + put api("/projects/#{project.id}/labels/promote", user), params: { name: label1.name } + pp json_response + pp project.labels + + group.labels.each do |l| + pp l + pp l.title + end + expect(response).to have_gitlab_http_status(400) expect(json_response['message']).to eq('Failed to promote project label to group label') end |