From 6b0ea951cac3905437abb2bbacaf422371f097e0 Mon Sep 17 00:00:00 2001 From: Jacopo Date: Fri, 19 Oct 2018 09:16:58 +0200 Subject: Creates /create_merge_request quickaction With this quick action the user can create a new MR starting from the current issue using as `source_branch` the given `branch name` and as `target_branch` the project default branch. If the `branch name` is omitted a name is automatically created starting from the issue title. --- .../quick_actions/interpret_service_spec.rb | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'spec/services/quick_actions') diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb index 5a7cafcb60f..938764f40b0 100644 --- a/spec/services/quick_actions/interpret_service_spec.rb +++ b/spec/services/quick_actions/interpret_service_spec.rb @@ -1222,6 +1222,37 @@ describe QuickActions::InterpretService do expect(commands).to be_empty expect(text).to eq("#{described_class::SHRUG}\n/close") end + + context '/create_merge_request command' do + let(:branch_name) { '1-feature' } + let(:content) { "/create_merge_request #{branch_name}" } + let(:issuable) { issue } + + context 'if issuable is not an Issue' do + let(:issuable) { merge_request } + + it_behaves_like 'empty command' + end + + context "when logged user cannot create_merge_requests in the project" do + let(:project) { create(:project, :archived) } + + it_behaves_like 'empty command' + end + + context 'when logged user cannot push code to the project' do + let(:project) { create(:project, :private) } + let(:service) { described_class.new(project, create(:user)) } + + it_behaves_like 'empty command' + end + + it 'populates create_merge_request with branch_name and issue iid' do + _, updates = service.execute(content, issuable) + + expect(updates).to eq(create_merge_request: { branch_name: branch_name, issue_iid: issuable.iid }) + end + end end describe '#explain' do @@ -1473,5 +1504,27 @@ describe QuickActions::InterpretService do end end end + + describe 'create a merge request' do + context 'with no branch name' do + let(:content) { '/create_merge_request' } + + it 'uses the default branch name' do + _, explanations = service.explain(content, issue) + + expect(explanations).to eq(['Creates a branch and a merge request to resolve this issue']) + end + end + + context 'with a branch name' do + let(:content) { '/create_merge_request foo' } + + it 'uses the given branch name' do + _, explanations = service.explain(content, issue) + + expect(explanations).to eq(["Creates branch 'foo' and a merge request to resolve this issue"]) + end + end + end end end -- cgit v1.2.3