Commit 777ec210 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'mr-branch-link-use-tree' into 'master'

MR branch link now links to tree instead of commits

Closes #34243

See merge request !12763
parents bc1bb506 531157f5
...@@ -92,13 +92,13 @@ export default { ...@@ -92,13 +92,13 @@ export default {
:class="{'label-truncated has-tooltip': isBranchTitleLong(mr.targetBranch)}" :class="{'label-truncated has-tooltip': isBranchTitleLong(mr.targetBranch)}"
:title="isBranchTitleLong(mr.targetBranch) ? mr.targetBranch : ''" :title="isBranchTitleLong(mr.targetBranch) ? mr.targetBranch : ''"
data-placement="bottom"> data-placement="bottom">
<a :href="mr.targetBranchPath">{{mr.targetBranch}}</a> <a :href="mr.targetBranchTreePath">{{mr.targetBranch}}</a>
</span> </span>
</strong> </strong>
<span <span
v-if="shouldShowCommitsBehindText" v-if="shouldShowCommitsBehindText"
class="diverged-commits-count"> class="diverged-commits-count">
({{mr.divergedCommitsCount}} {{commitsText}} behind) (<a :href="mr.targetBranchPath">{{mr.divergedCommitsCount}} {{commitsText}} behind</a>)
</span> </span>
</div> </div>
</div> </div>
......
...@@ -48,6 +48,7 @@ export default class MergeRequestStore { ...@@ -48,6 +48,7 @@ export default class MergeRequestStore {
this.sourceBranchLink = data.source_branch_with_namespace_link; this.sourceBranchLink = data.source_branch_with_namespace_link;
this.mergeError = data.merge_error; this.mergeError = data.merge_error;
this.targetBranchPath = data.target_branch_commits_path; this.targetBranchPath = data.target_branch_commits_path;
this.targetBranchTreePath = data.target_branch_tree_path;
this.conflictResolutionPath = data.conflict_resolution_path; this.conflictResolutionPath = data.conflict_resolution_path;
this.cancelAutoMergePath = data.cancel_merge_when_pipeline_succeeds_path; this.cancelAutoMergePath = data.cancel_merge_when_pipeline_succeeds_path;
this.removeWIPPath = data.remove_wip_path; this.removeWIPPath = data.remove_wip_path;
......
...@@ -76,6 +76,12 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated ...@@ -76,6 +76,12 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated
end end
end end
def target_branch_tree_path
if target_branch_exists?
project_tree_path(project, target_branch)
end
end
def target_branch_commits_path def target_branch_commits_path
if target_branch_exists? if target_branch_exists?
project_commits_path(project, target_branch) project_commits_path(project, target_branch)
...@@ -94,7 +100,7 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated ...@@ -94,7 +100,7 @@ class MergeRequestPresenter < Gitlab::View::Presenter::Delegated
if source_branch_exists? if source_branch_exists?
namespace = link_to(namespace, project_path(source_project)) namespace = link_to(namespace, project_path(source_project))
branch = link_to(branch, project_commits_path(source_project, source_branch)) branch = link_to(branch, project_tree_path(source_project, source_branch))
end end
if for_fork? if for_fork?
......
...@@ -97,6 +97,10 @@ class MergeRequestEntity < IssuableEntity ...@@ -97,6 +97,10 @@ class MergeRequestEntity < IssuableEntity
presenter(merge_request).target_branch_commits_path presenter(merge_request).target_branch_commits_path
end end
expose :target_branch_tree_path do |merge_request|
presenter(merge_request).target_branch_tree_path
end
expose :new_blob_path do |merge_request| expose :new_blob_path do |merge_request|
if can?(current_user, :push_code, merge_request.project) if can?(current_user, :push_code, merge_request.project)
project_new_blob_path(merge_request.project, merge_request.source_branch) project_new_blob_path(merge_request.project, merge_request.source_branch)
......
---
title: MR branch link now links to tree instead of commits
merge_request:
author:
...@@ -930,7 +930,7 @@ module Gitlab ...@@ -930,7 +930,7 @@ module Gitlab
return unless commit_object && commit_object.type == :COMMIT return unless commit_object && commit_object.type == :COMMIT
gitmodules = gitaly_commit_client.tree_entry(ref, '.gitmodules', Blob::MAX_DATA_DISPLAY_SIZE) gitmodules = gitaly_commit_client.tree_entry(ref, '.gitmodules', Gitlab::Git::Blob::MAX_DATA_DISPLAY_SIZE)
found_module = GitmodulesParser.new(gitmodules.data).parse[path] found_module = GitmodulesParser.new(gitmodules.data).parse[path]
found_module && found_module['url'] found_module && found_module['url']
......
...@@ -75,6 +75,7 @@ ...@@ -75,6 +75,7 @@
"additionalProperties": false "additionalProperties": false
}, },
"target_branch_commits_path": { "type": "string" }, "target_branch_commits_path": { "type": "string" },
"target_branch_tree_path": { "type": "string" },
"source_branch_path": { "type": "string" }, "source_branch_path": { "type": "string" },
"conflict_resolution_path": { "type": ["string", "null"] }, "conflict_resolution_path": { "type": ["string", "null"] },
"cancel_merge_when_pipeline_succeeds_path": { "type": "string" }, "cancel_merge_when_pipeline_succeeds_path": { "type": "string" },
......
...@@ -54,6 +54,7 @@ describe('MRWidgetHeader', () => { ...@@ -54,6 +54,7 @@ describe('MRWidgetHeader', () => {
sourceBranch: 'mr-widget-refactor', sourceBranch: 'mr-widget-refactor',
sourceBranchLink: `<a href="${sourceBranchPath}">mr-widget-refactor</a>`, sourceBranchLink: `<a href="${sourceBranchPath}">mr-widget-refactor</a>`,
targetBranchPath: 'foo/bar/commits-path', targetBranchPath: 'foo/bar/commits-path',
targetBranchTreePath: 'foo/bar/tree/path',
targetBranch: 'master', targetBranch: 'master',
isOpen: true, isOpen: true,
emailPatchesPath: '/mr/email-patches', emailPatchesPath: '/mr/email-patches',
...@@ -69,12 +70,14 @@ describe('MRWidgetHeader', () => { ...@@ -69,12 +70,14 @@ describe('MRWidgetHeader', () => {
expect(el.classList.contains('mr-source-target')).toBeTruthy(); expect(el.classList.contains('mr-source-target')).toBeTruthy();
const sourceBranchLink = el.querySelectorAll('.label-branch')[0]; const sourceBranchLink = el.querySelectorAll('.label-branch')[0];
const targetBranchLink = el.querySelectorAll('.label-branch')[1]; const targetBranchLink = el.querySelectorAll('.label-branch')[1];
const commitsCount = el.querySelector('.diverged-commits-count');
expect(sourceBranchLink.textContent).toContain(mr.sourceBranch); expect(sourceBranchLink.textContent).toContain(mr.sourceBranch);
expect(targetBranchLink.textContent).toContain(mr.targetBranch); expect(targetBranchLink.textContent).toContain(mr.targetBranch);
expect(sourceBranchLink.querySelector('a').getAttribute('href')).toEqual(sourceBranchPath); expect(sourceBranchLink.querySelector('a').getAttribute('href')).toEqual(sourceBranchPath);
expect(targetBranchLink.querySelector('a').getAttribute('href')).toEqual(mr.targetBranchPath); expect(targetBranchLink.querySelector('a').getAttribute('href')).toEqual(mr.targetBranchTreePath);
expect(el.querySelector('.diverged-commits-count').textContent).toContain('12 commits behind'); expect(commitsCount.textContent).toContain('12 commits behind');
expect(commitsCount.querySelector('a').getAttribute('href')).toEqual(mr.targetBranchPath);
expect(el.textContent).toContain('Check out branch'); expect(el.textContent).toContain('Check out branch');
expect(el.querySelectorAll('.dropdown li a')[0].getAttribute('href')).toEqual(mr.emailPatchesPath); expect(el.querySelectorAll('.dropdown li a')[0].getAttribute('href')).toEqual(mr.emailPatchesPath);
......
...@@ -332,7 +332,31 @@ describe MergeRequestPresenter do ...@@ -332,7 +332,31 @@ describe MergeRequestPresenter do
end end
end end
context 'when target branch does not exists' do context 'when target branch does not exist' do
it 'returns nil' do
allow(resource).to receive(:target_branch_exists?) { false }
is_expected.to be_nil
end
end
end
describe '#target_branch_tree_path' do
subject do
described_class.new(resource, current_user: user)
.target_branch_tree_path
end
context 'when target branch exists' do
it 'returns path' do
allow(resource).to receive(:target_branch_exists?) { true }
is_expected
.to eq("/#{resource.target_project.full_path}/tree/#{resource.target_branch}")
end
end
context 'when target branch does not exist' do
it 'returns nil' do it 'returns nil' do
allow(resource).to receive(:target_branch_exists?) { false } allow(resource).to receive(:target_branch_exists?) { false }
...@@ -355,7 +379,7 @@ describe MergeRequestPresenter do ...@@ -355,7 +379,7 @@ describe MergeRequestPresenter do
end end
end end
context 'when source branch does not exists' do context 'when source branch does not exist' do
it 'returns nil' do it 'returns nil' do
allow(resource).to receive(:source_branch_exists?) { false } allow(resource).to receive(:source_branch_exists?) { false }
...@@ -363,4 +387,17 @@ describe MergeRequestPresenter do ...@@ -363,4 +387,17 @@ describe MergeRequestPresenter do
end end
end end
end end
describe '#source_branch_with_namespace_link' do
subject do
described_class.new(resource, current_user: user).source_branch_with_namespace_link
end
it 'returns link' do
allow(resource).to receive(:source_branch_exists?) { true }
is_expected
.to eq("<a href=\"/#{resource.source_project.full_path}/tree/#{resource.source_branch}\">#{resource.source_branch}</a>")
end
end
end end
...@@ -47,7 +47,7 @@ describe MergeRequestEntity do ...@@ -47,7 +47,7 @@ describe MergeRequestEntity do
:cancel_merge_when_pipeline_succeeds_path, :cancel_merge_when_pipeline_succeeds_path,
:create_issue_to_resolve_discussions_path, :create_issue_to_resolve_discussions_path,
:source_branch_path, :target_branch_commits_path, :source_branch_path, :target_branch_commits_path,
:commits_count) :target_branch_tree_path, :commits_count)
end end
it 'has email_patches_path' do it 'has email_patches_path' 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