Commit fa293df2 authored by Sean McGivern's avatar Sean McGivern

Merge branch '35343-inherit-milestones-and-labels' into 'master'

copy milestones and labels from issue when using create merge request button

Closes #35343

See merge request !13461
parents ac8c136e 539694a3
...@@ -3,6 +3,8 @@ module MergeRequests ...@@ -3,6 +3,8 @@ module MergeRequests
def execute def execute
return error('Invalid issue iid') unless issue_iid.present? && issue.present? return error('Invalid issue iid') unless issue_iid.present? && issue.present?
params[:label_ids] = issue.label_ids if issue.label_ids.any?
result = CreateBranchService.new(project, current_user).execute(branch_name, ref) result = CreateBranchService.new(project, current_user).execute(branch_name, ref)
return result if result[:status] == :error return result if result[:status] == :error
...@@ -43,7 +45,8 @@ module MergeRequests ...@@ -43,7 +45,8 @@ module MergeRequests
{ {
source_project_id: project.id, source_project_id: project.id,
source_branch: branch_name, source_branch: branch_name,
target_project_id: project.id target_project_id: project.id,
milestone_id: issue.milestone_id
} }
end end
......
---
title: inherits milestone and labels when a merge request is created from issue
merge_request: 13461
author: haseebeqx
type: added
...@@ -3,7 +3,9 @@ require 'spec_helper' ...@@ -3,7 +3,9 @@ require 'spec_helper'
describe MergeRequests::CreateFromIssueService do describe MergeRequests::CreateFromIssueService do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:issue) { create(:issue, project: project) } let(:label_ids) { create_pair(:label, project: project).map(&:id) }
let(:milestone_id) { create(:milestone, project: project).id }
let(:issue) { create(:issue, project: project, milestone_id: milestone_id) }
subject(:service) { described_class.new(project, user, issue_iid: issue.iid) } subject(:service) { described_class.new(project, user, issue_iid: issue.iid) }
...@@ -25,6 +27,20 @@ describe MergeRequests::CreateFromIssueService do ...@@ -25,6 +27,20 @@ describe MergeRequests::CreateFromIssueService do
described_class.new(project, user, issue_iid: -1).execute described_class.new(project, user, issue_iid: -1).execute
end end
it "inherits labels" do
issue.assign_attributes(label_ids: label_ids)
result = service.execute
expect(result[:merge_request].label_ids).to eq(label_ids)
end
it "inherits milestones" do
result = service.execute
expect(result[:merge_request].milestone_id).to eq(milestone_id)
end
it 'delegates the branch creation to CreateBranchService' do it 'delegates the branch creation to CreateBranchService' do
expect_any_instance_of(CreateBranchService).to receive(:execute).once.and_call_original expect_any_instance_of(CreateBranchService).to receive(:execute).once.and_call_original
......
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