Commit 5e55c9d3 authored by Robert Speicher's avatar Robert Speicher

Merge branch '268301-mr-ide-button' into 'master'

Fix Merge Request "Edit in Web IDE" dropdown link on MR diffs page

See merge request gitlab-org/gitlab!45653
parents 8c878467 ffda1701
......@@ -26,6 +26,25 @@ module BlobHelper
File.join(segments)
end
def ide_merge_request_path(merge_request, path = '')
target_project = merge_request.target_project
source_project = merge_request.source_project
if merge_request.merged?
branch = merge_request.target_branch_exists? ? merge_request.target_branch : target_project.default_branch
return ide_edit_path(target_project, branch, path)
end
if target_project != source_project
params = { target_project: target_project.full_path }
end
result = File.join(ide_path, 'project', source_project.full_path, 'merge_requests', merge_request.to_param)
result += "?#{params.to_query}" unless params.nil?
result
end
def ide_fork_and_edit_path(project = @project, ref = @ref, path = @path, options = {})
fork_path_for_current_user(project, ide_edit_path(project, ref, path))
end
......
......@@ -343,18 +343,6 @@ module GitlabRoutingHelper
Gitlab::UrlBuilder.wiki_page_url(wiki, page, only_path: true, **options)
end
def gitlab_ide_merge_request_path(merge_request)
target_project = merge_request.target_project
source_project = merge_request.source_project
params = {}
if target_project != source_project
params = { target_project: target_project.full_path }
end
ide_merge_request_path(source_project.namespace, source_project, merge_request, params)
end
private
def snippet_query_params(snippet, *args)
......
......@@ -48,7 +48,7 @@ class DiffFileBaseEntity < Grape::Entity
next unless has_edit_path?(merge_request)
gitlab_ide_merge_request_path(merge_request)
ide_merge_request_path(merge_request, diff_file.new_path)
end
expose :old_path_html do |diff_file|
......
---
title: Fix Merge Request "Edit in Web IDE" dropdown link on MR diffs page
merge_request: 45653
author:
type: fixed
......@@ -122,7 +122,6 @@ Rails.application.routes.draw do
get 'ide' => 'ide#index'
get 'ide/*vueroute' => 'ide#index', format: false
get 'ide/project/:namespace/:project/merge_requests/:id' => 'ide#index', format: false, as: :ide_merge_request
draw :operations
draw :jira_connect
......
......@@ -444,6 +444,55 @@ RSpec.describe BlobHelper do
end
end
describe '#ide_merge_request_path' do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:merge_request) { create(:merge_request, source_project: project)}
it 'returns IDE path for the given MR if MR is not merged' do
expect(helper.ide_merge_request_path(merge_request)).to eq("/-/ide/project/#{project.full_path}/merge_requests/#{merge_request.iid}")
end
context 'when the MR comes from a fork' do
include ProjectForksHelper
let(:forked_project) { fork_project(project, nil, repository: true) }
let(:merge_request) { create(:merge_request, source_project: forked_project, target_project: project) }
it 'returns IDE path for MR in the forked repo with target project included as param' do
expect(helper.ide_merge_request_path(merge_request)).to eq("/-/ide/project/#{forked_project.full_path}/merge_requests/#{merge_request.iid}?target_project=#{CGI.escape(project.full_path)}")
end
end
context 'when the MR is merged' do
let(:current_user) { build(:user) }
let_it_be(:merge_request) { create(:merge_request, :merged, source_project: project, source_branch: 'testing-1', target_branch: 'feature-1') }
before do
allow(helper).to receive(:current_user).and_return(current_user)
allow(helper).to receive(:can?).and_return(true)
end
it 'returns default IDE url with master branch' do
expect(helper.ide_merge_request_path(merge_request)).to eq("/-/ide/project/#{project.full_path}/edit/master")
end
it 'includes file path passed' do
expect(helper.ide_merge_request_path(merge_request, 'README.md')).to eq("/-/ide/project/#{project.full_path}/edit/master/-/README.md")
end
context 'when target branch exists' do
before do
allow(merge_request).to receive(:target_branch_exists?).and_return(true)
end
it 'returns IDE edit url with the target branch' do
expect(helper.ide_merge_request_path(merge_request)).to eq("/-/ide/project/#{project.full_path}/edit/feature-1")
end
end
end
end
describe '#ide_fork_and_edit_path' do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
......
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