Commit d368b2d2 authored by haseeb's avatar haseeb

moved merge parms to service

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