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
This commit is contained in:
Sean McGivern 2017-08-21 10:10:49 +00:00
commit fa293df2b7
3 changed files with 27 additions and 3 deletions

View file

@ -3,6 +3,8 @@ module MergeRequests
def execute
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)
return result if result[:status] == :error
@ -43,7 +45,8 @@ module MergeRequests
{
source_project_id: project.id,
source_branch: branch_name,
target_project_id: project.id
target_project_id: project.id,
milestone_id: issue.milestone_id
}
end

View file

@ -0,0 +1,5 @@
---
title: inherits milestone and labels when a merge request is created from issue
merge_request: 13461
author: haseebeqx
type: added

View file

@ -2,8 +2,10 @@ require 'spec_helper'
describe MergeRequests::CreateFromIssueService do
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let(:issue) { create(:issue, project: project) }
let(:user) { create(:user) }
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) }
@ -25,6 +27,20 @@ describe MergeRequests::CreateFromIssueService do
described_class.new(project, user, issue_iid: -1).execute
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
expect_any_instance_of(CreateBranchService).to receive(:execute).once.and_call_original