Commit aa18cc20 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'issue_14532_assign_labels_milestone_when_moving_issue' into 'master'

Assign labels milestone when moving issue

Closes #14532.

See merge request !3934
parents 622a33e9 e016cdb7
Please view this file on the master branch, on stable branches it's out of date.
v 8.8.0 (unreleased)
- Assign labels and milestone to target project when moving issue. !3934 (Long Nguyen)
- Project#open_branches has been cleaned up and no longer loads entire records into memory.
- Log to application.log when an admin starts and stops impersonating a user
- Updated gitlab_git to 10.1.0
......
......@@ -41,14 +41,25 @@ module Issues
private
def create_new_issue
new_params = { id: nil, iid: nil, label_ids: [], milestone: nil,
new_params = { id: nil, iid: nil, label_ids: cloneable_label_ids,
milestone_id: cloneable_milestone_id,
project: @new_project, author: @old_issue.author,
description: rewrite_content(@old_issue.description) }
new_params = @old_issue.serializable_hash.merge(new_params)
new_params = @old_issue.serializable_hash.symbolize_keys.merge(new_params)
CreateService.new(@new_project, @current_user, new_params).execute
end
def cloneable_label_ids
@new_project.labels
.where(title: @old_issue.labels.pluck(:title)).pluck(:id)
end
def cloneable_milestone_id
@new_project.milestones
.find_by(title: @old_issue.milestone.try(:title)).try(:id)
end
def rewrite_notes
@old_issue.notes.find_each do |note|
new_note = note.dup
......
......@@ -7,10 +7,11 @@ describe Issues::MoveService, services: true do
let(:description) { 'Some issue description' }
let(:old_project) { create(:project) }
let(:new_project) { create(:project) }
let(:milestone1) { create(:milestone, project_id: old_project.id, title: 'v9.0') }
let(:old_issue) do
create(:issue, title: title, description: description,
project: old_project, author: author)
project: old_project, author: author, milestone: milestone1)
end
let(:move_service) do
......@@ -21,11 +22,24 @@ describe Issues::MoveService, services: true do
before do
old_project.team << [user, :reporter]
new_project.team << [user, :reporter]
['label1', 'label2'].each do |label|
old_issue.labels << create(:label,
project_id: old_project.id,
title: label)
end
new_project.labels << create(:label, title: 'label1')
new_project.labels << create(:label, title: 'label2')
end
end
describe '#execute' do
shared_context 'issue move executed' do
let!(:milestone2) do
create(:milestone, project_id: new_project.id, title: 'v9.0')
end
let!(:new_issue) { move_service.execute(old_issue, new_project) }
end
......@@ -39,6 +53,23 @@ describe Issues::MoveService, services: true do
expect(new_issue.project).to eq new_project
end
it 'assigns milestone to new issue' do
expect(new_issue.reload.milestone.title).to eq 'v9.0'
expect(new_issue.reload.milestone).to eq(milestone2)
end
it 'assign labels to new issue' do
expected_label_titles = new_issue.reload.labels.map(&:title)
expect(expected_label_titles).to include 'label1'
expect(expected_label_titles).to include 'label2'
expect(expected_label_titles.size).to eq 2
new_issue.labels.each do |label|
expect(new_project.labels).to include(label)
expect(old_project.labels).not_to include(label)
end
end
it 'rewrites issue title' do
expect(new_issue.title).to eq title
end
......@@ -72,11 +103,6 @@ describe Issues::MoveService, services: true do
expect(new_issue.author).to eq author
end
it 'removes data that is invalid in new context' do
expect(new_issue.milestone).to be_nil
expect(new_issue.labels).to be_empty
end
it 'creates a new internal id for issue' do
expect(new_issue.iid).to be 1
end
......
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