Commit d368b2d2 authored by haseeb's avatar haseeb

moved merge parms to service

parent 59d7ffad
......@@ -212,7 +212,7 @@ class Projects::IssuesController < Projects::ApplicationController
end
def create_merge_request
result = ::MergeRequests::CreateFromIssueService.new(project, current_user, merge_request_params).execute
result = ::MergeRequests::CreateFromIssueService.new(project, current_user, issue_iid: issue.iid).execute
if result[:status] == :success
render json: MergeRequestCreateSerializer.new.represent(result[:merge_request])
......@@ -287,14 +287,4 @@ class Projects::IssuesController < Projects::ApplicationController
redirect_to new_user_session_path, notice: notice
end
private
def merge_request_params
{
issue_iid: issue.iid,
label_ids: issue.label_ids,
milestone_id: issue.milestone_id
}
end
end
......@@ -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
......
......@@ -3,22 +3,11 @@ require 'spec_helper'
describe MergeRequests::CreateFromIssueService do
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let(:issue) { create(:issue, project: project) }
let(:milestone) { create(:milestone, project: project) }
let(:labels) { create_pair(:label, 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(:service2) do
described_class.new(
project,
user,
{
issue_iid: issue.iid,
milestone_id: milestone.id,
label_ids: labels.map(&:id)
}
)
end
before do
project.add_developer(user)
......@@ -38,16 +27,18 @@ describe MergeRequests::CreateFromIssueService do
described_class.new(project, user, issue_iid: -1).execute
end
it "can inherit labels" do
result = service2.execute
it "inherits labels" do
issue.assign_attributes(label_ids: label_ids)
expect(result[:merge_request].label_ids).to eq(labels.map(&:id))
result = service.execute
expect(result[:merge_request].label_ids).to eq(label_ids)
end
it "can inherit milestones" do
result = service2.execute
it "inherits milestones" do
result = service.execute
expect(result[:merge_request].milestone_id).to eq(milestone.id)
expect(result[:merge_request].milestone_id).to eq(milestone_id)
end
it 'delegates the branch creation to CreateBranchService' do
......
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