Commit de5b6c31 authored by Phil Hughes's avatar Phil Hughes

Change create merge request from issue flow

Changes the flow from the create a merge request dropdown
to instead go to the create form instead of directly creating
a new merge request.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/349566
parent 9ea6a83a
...@@ -69,11 +69,11 @@ export default class CreateMergeRequestDropdown { ...@@ -69,11 +69,11 @@ export default class CreateMergeRequestDropdown {
this.regexps = { this.regexps = {
branch: { branch: {
createBranchPath: new RegExp('(branch_name=)(.+?)(?=&issue)'), createBranchPath: new RegExp('(branch_name=)(.+?)(?=&issue)'),
createMrPath: new RegExp('(branch_name=)(.+?)(?=&ref)'), createMrPath: new RegExp('(source_branch%5D=)(.+?)(?=&)'),
}, },
ref: { ref: {
createBranchPath: new RegExp('(ref=)(.+?)$'), createBranchPath: new RegExp('(ref=)(.+?)$'),
createMrPath: new RegExp('(ref=)(.+?)$'), createMrPath: new RegExp('(target_branch%5D=)(.+?)$'),
}, },
}; };
...@@ -167,23 +167,18 @@ export default class CreateMergeRequestDropdown { ...@@ -167,23 +167,18 @@ export default class CreateMergeRequestDropdown {
} }
createMergeRequest() { createMergeRequest() {
this.isCreatingMergeRequest = true; return new Promise(() => {
this.isCreatingMergeRequest = true;
return axios
.post(this.createMrPath, { return this.createBranch().then(() => {
target_project_id: canCreateConfidentialMergeRequest() window.location.href = canCreateConfidentialMergeRequest()
? confidentialMergeRequestState.selectedProject.id ? this.createMrPath.replace(
: null, this.projectPath,
}) confidentialMergeRequestState.selectedProject.pathWithNamespace,
.then(({ data }) => { )
this.mergeRequestCreated = true; : this.createMrPath;
window.location.href = data.url; });
}) });
.catch(() =>
createFlash({
message: __('Failed to create merge request. Please try again.'),
}),
);
} }
disable() { disable() {
...@@ -562,5 +557,7 @@ export default class CreateMergeRequestDropdown { ...@@ -562,5 +557,7 @@ export default class CreateMergeRequestDropdown {
this.regexps[target].createMrPath, this.regexps[target].createMrPath,
pathReplacement, pathReplacement,
); );
this.wrapperEl.dataset.createMrPath = this.createMrPath;
} }
} }
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
- create_mr_text = can_create_confidential_merge_request? ? _('Create confidential merge request') : _('Create merge request') - create_mr_text = can_create_confidential_merge_request? ? _('Create confidential merge request') : _('Create merge request')
- can_create_path = can_create_branch_project_issue_path(@project, @issue) - can_create_path = can_create_branch_project_issue_path(@project, @issue)
- create_mr_path = create_merge_request_project_issue_path(@project, @issue, branch_name: @issue.to_branch_name, ref: @project.default_branch) - create_mr_path = project_new_merge_request_path(@project, merge_request: { source_branch: @issue.to_branch_name, target_branch: @project.default_branch })
- create_branch_path = project_branches_path(@project, branch_name: @issue.to_branch_name, ref: @project.default_branch, issue_iid: @issue.iid) - create_branch_path = project_branches_path(@project, branch_name: @issue.to_branch_name, ref: @project.default_branch, issue_iid: @issue.iid, format: :json)
- refs_path = refs_namespace_project_path(@project.namespace, @project, search: '') - refs_path = refs_namespace_project_path(@project.namespace, @project, search: '')
.create-mr-dropdown-wrap.d-inline-block.full-width-mobile.js-create-mr{ data: { project_path: @project.full_path, project_id: @project.id, can_create_path: can_create_path, create_mr_path: create_mr_path, create_branch_path: create_branch_path, refs_path: refs_path, is_confidential: can_create_confidential_merge_request?.to_s } } .create-mr-dropdown-wrap.d-inline-block.full-width-mobile.js-create-mr{ data: { project_path: @project.full_path, project_id: @project.id, can_create_path: can_create_path, create_mr_path: create_mr_path, create_branch_path: create_branch_path, refs_path: refs_path, is_confidential: can_create_confidential_merge_request?.to_s } }
......
...@@ -14713,9 +14713,6 @@ msgstr "" ...@@ -14713,9 +14713,6 @@ msgstr ""
msgid "Failed to create import label for jira import." msgid "Failed to create import label for jira import."
msgstr "" msgstr ""
msgid "Failed to create merge request. Please try again."
msgstr ""
msgid "Failed to create new access token: %{token_response_message}" msgid "Failed to create new access token: %{token_response_message}"
msgstr "" msgstr ""
......
...@@ -71,16 +71,10 @@ RSpec.describe 'User creates branch and merge request on issue page', :js do ...@@ -71,16 +71,10 @@ RSpec.describe 'User creates branch and merge request on issue page', :js do
perform_enqueued_jobs do perform_enqueued_jobs do
select_dropdown_option('create-mr') select_dropdown_option('create-mr')
expect(page).to have_content('Draft: Resolve "Cherry-Coloured Funk"') expect(page).to have_content('New merge request')
expect(current_path).to eq(project_merge_request_path(project, MergeRequest.first)) expect(page).to have_content("From #{issue.to_branch_name} into #{project.default_branch}")
expect(page).to have_current_path(project_new_merge_request_path(project, merge_request: { source_branch: issue.to_branch_name, target_branch: project.default_branch }))
wait_for_requests
end end
visit project_issue_path(project, issue)
expect(page).to have_content("created merge request !1 to address this issue")
expect(page).to have_content('mentioned in merge request !1')
end end
it 'creates a branch' do it 'creates a branch' do
...@@ -100,17 +94,10 @@ RSpec.describe 'User creates branch and merge request on issue page', :js do ...@@ -100,17 +94,10 @@ RSpec.describe 'User creates branch and merge request on issue page', :js do
perform_enqueued_jobs do perform_enqueued_jobs do
select_dropdown_option('create-mr', branch_name) select_dropdown_option('create-mr', branch_name)
expect(page).to have_content('Draft: Resolve "Cherry-Coloured Funk"') expect(page).to have_content('New merge request')
expect(page).to have_content('Request to merge custom-branch-name into') expect(page).to have_content("From #{branch_name} into #{project.default_branch}")
expect(current_path).to eq(project_merge_request_path(project, MergeRequest.first)) expect(page).to have_current_path(project_new_merge_request_path(project, merge_request: { source_branch: branch_name, target_branch: project.default_branch }))
wait_for_requests
end end
visit project_issue_path(project, issue)
expect(page).to have_content("created merge request !1 to address this issue")
expect(page).to have_content('mentioned in merge request !1')
end end
it 'creates a branch' do it 'creates a branch' do
......
...@@ -59,7 +59,7 @@ describe('CreateMergeRequestDropdown', () => { ...@@ -59,7 +59,7 @@ describe('CreateMergeRequestDropdown', () => {
describe('updateCreatePaths', () => { describe('updateCreatePaths', () => {
it('escapes branch names correctly', () => { it('escapes branch names correctly', () => {
dropdown.createBranchPath = `${TEST_HOST}/branches?branch_name=some-branch&issue=42`; dropdown.createBranchPath = `${TEST_HOST}/branches?branch_name=some-branch&issue=42`;
dropdown.createMrPath = `${TEST_HOST}/create_merge_request?branch_name=some-branch&ref=main`; dropdown.createMrPath = `${TEST_HOST}/create_merge_request?merge_request%5Bsource_branch%5D=test&merge_request%5Btarget_branch%5D=master`;
dropdown.updateCreatePaths('branch', 'contains#hash'); dropdown.updateCreatePaths('branch', 'contains#hash');
...@@ -68,7 +68,7 @@ describe('CreateMergeRequestDropdown', () => { ...@@ -68,7 +68,7 @@ describe('CreateMergeRequestDropdown', () => {
); );
expect(dropdown.createMrPath).toBe( expect(dropdown.createMrPath).toBe(
`${TEST_HOST}/create_merge_request?branch_name=contains%23hash&ref=main`, `${TEST_HOST}/create_merge_request?merge_request%5Bsource_branch%5D=contains%23hash&merge_request%5Btarget_branch%5D=master`,
); );
}); });
}); });
......
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