diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-02-24 12:18:46 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-03-17 07:39:15 +0100 |
commit | fbb5a8b089d00fb66d8915b0f546dd07e76877e4 (patch) | |
tree | 3ac3aa1ce12c104d151f03ef8bf70da64874d926 /app/services | |
parent | 57eb39548879109dff3813129fca7acbcca23f71 (diff) | |
download | gitlab-ce-fbb5a8b089d00fb66d8915b0f546dd07e76877e4.tar.gz |
Use a new issue create service when moving an issue
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/issues/move_service.rb | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/app/services/issues/move_service.rb b/app/services/issues/move_service.rb index 55239d566f1..510a04e98f7 100644 --- a/app/services/issues/move_service.rb +++ b/app/services/issues/move_service.rb @@ -4,7 +4,7 @@ module Issues super(project, current_user, params) @issue_old = issue - @issue_new = @issue_old.dup + @issue_new = nil @project_old = @project @project_new = Project.find(new_project_id) if new_project_id end @@ -42,8 +42,18 @@ module Issues end def open_new_issue - new_description = rewrite_references(@issue_old, @issue_old.description) - @issue_new.update(project: @project_new, description: new_description) + create_service = CreateService.new(@project_new, current_user, new_issue_params) + @issue_new = create_service.execute + end + + def new_issue_params + new_params = { id: nil, iid: nil, milestone_id: nil, label_ids: [], + project_id: @project_new.id, + author_id: @issue_old.author_id, + description: rewrite_references(@issue_old), + updated_by_id: current_user.id } + + params.merge(new_params) end def rewrite_notes @@ -68,9 +78,9 @@ module Issues SystemNoteService.noteable_moved(:to, @issue_old, @project_old, @issue_new, @current_user) end - def rewrite_references(mentionable, text) - new_content = text.dup + def rewrite_references(mentionable) references = mentionable.all_references + new_content = mentionable_content(mentionable).dup [:issues, :merge_requests, :milestones].each do |type| references.public_send(type).each do |mentioned| @@ -81,5 +91,14 @@ module Issues new_content end + + def mentionable_content(mentionable) + case mentionable + when Issue then mentionable.description + when Note then mentionable.note + else + raise 'Unexpected mentionable while moving an issue' + end + end end end |