Commit 6b3f0fee authored by micael.bergeron's avatar micael.bergeron

corrects the url building

parent e3565631
class Projects::MergeRequests::ApplicationController < Projects::ApplicationController
before_action :check_merge_requests_available!
before_action :merge_request
before_action :commit
before_action :authorize_read_merge_request!
private
......@@ -10,11 +9,6 @@ class Projects::MergeRequests::ApplicationController < Projects::ApplicationCont
@issuable = @merge_request ||= @project.merge_requests.find_by!(iid: params[:id])
end
def commit
return nil unless commit_id = params[:commit_id].presence
@commit ||= merge_request.target_project.commit(commit_id)
end
def merge_request_params
params.require(:merge_request).permit(merge_request_params_attributes)
end
......
......@@ -4,6 +4,7 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic
include RendersNotes
before_action :apply_diff_view_cookie!
before_action :commit
before_action :define_diff_vars
before_action :define_diff_comment_vars
......@@ -28,6 +29,13 @@ class Projects::MergeRequests::DiffsController < Projects::MergeRequests::Applic
@diffs = @compare.diffs(diff_options)
end
def commit
return nil unless commit_id = params[:commit_id].presence
return nil unless @merge_request.all_commit_shas.include?(commit_id)
@commit ||= @project.commit(commit_id)
end
def find_merge_request_diff_compare
@merge_request_diff =
if diff_id = params[:diff_id].presence
......
......@@ -231,9 +231,9 @@ module CommitsHelper
def commit_path(project, commit, merge_request: nil)
if merge_request&.persisted?
diffs_namespace_project_merge_request_path(project.namespace, project, merge_request, commit_id: commit.id)
diffs_project_merge_request_path(project, merge_request, commit_id: commit.id)
else
namespace_project_commit_path(project.namespace, project, commit.id)
project_commit_path(project, commit)
end
end
end
......@@ -670,11 +670,10 @@ module SystemNoteService
end
def merge_request_commit_url(merge_request, commit)
url_helpers.diffs_namespace_project_merge_request_url(
merge_request.target_project.namespace,
url_helpers.diffs_project_merge_request_url(
merge_request.target_project,
merge_request.iid,
commit_id: commit.id
merge_request,
commit_id: commit
)
end
end
......@@ -87,6 +87,6 @@
This commit is part of merge request
= succeed '.' do
= link_to @merge_request.to_reference, namespace_project_merge_request_path(@project.namespace, @project, @merge_request)
= link_to @merge_request.to_reference, diffs_project_merge_request_path(@project, @merge_request, commit_id: @commit.id)
Comments created here will be created in the context of that merge request.
......@@ -4,13 +4,7 @@
- ref = local_assigns.fetch(:ref) { merge_request&.source_branch }
- link = commit_path(project, commit, merge_request: merge_request)
- if @note_counts
- note_count = @note_counts.fetch(commit.id, 0)
- else
- notes = commit.notes
- note_count = notes.user.count
- cache_key = [project.full_path, commit.id, current_application_settings, note_count, @path.presence, current_controller?(:commits), merge_request, I18n.locale]
- cache_key = [project.full_path, commit.id, current_application_settings, @path.presence, current_controller?(:commits), merge_request.iid, view_details, I18n.locale]
- cache_key.push(commit.status(ref)) if commit.status(ref)
= cache(cache_key, expires_in: 1.day) do
......@@ -55,4 +49,4 @@
= link_to_browse_code(project, commit)
- if view_details && merge_request
= link_to "View details", namespace_project_commit_path(project.namespace, project, commit.id, merge_request_iid: merge_request.iid), class: "btn btn-default"
= link_to "View details", project_commit_path(project, commit.id, merge_request_iid: merge_request.iid), class: "btn btn-default"
......@@ -4,8 +4,8 @@
= icon('info-circle')
Selected versions have different base commits.
Changes will include
= link_to namespace_project_compare_path(@project.namespace, @project, from: @start_version.base_commit_sha, to: @merge_request_diff.base_commit_sha) do
= link_to project_compare_path(@project, from: @start_version.base_commit_sha, to: @merge_request_diff.base_commit_sha) do
new commits
from
= succeed '.' do
%code= @merge_request.target_branch
%code.ref-name= @merge_request.target_branch
......@@ -6,11 +6,11 @@
- if @merge_request_diff&.empty?
.nothing-here-block
= image_tag 'illustrations/merge_request_changes_empty.svg'
%p
Nothing to merge from
%strong= @merge_request.source_branch
into
%strong= @merge_request.target_branch
= succeed '.' do
No changes between
%span.ref-name= @merge_request.source_branch
and
%span.ref-name= @merge_request.target_branch
%p= link_to 'Create commit', project_new_blob_path(@project, @merge_request.source_branch), class: 'btn btn-save'
- else
- diff_viewable = @merge_request_diff ? @merge_request_diff.collected? || @merge_request_diff.overflow? : true
......
- if @commit || @start_version || (@merge_request_diff && !@merge_request_diff.latest?)
.mr-version-controls
.content-block.comments-disabled-notif
.content-block.comments-disabled-notif.clearfix
= icon('info-circle')
Not all comments are displayed because you're
= succeed '.' do
- if @commit
viewing only the changes in commit
= link_to @commit.short_id, diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request, commit_id: @commit.id), class: "commit-sha"
- elsif @start_version
comparing two versions of the diff
Only comments from the following commit are shown below
- else
viewing an old version of the diff
.text-right
= link_to diffs_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), class: 'btn btn-sm' do
Show latest version
= "of the diff" if @commit
Not all comments are displayed because you're
- if @start_version
comparing two versions of the diff
- else
viewing an old version of the diff
.pull-right
= link_to diffs_project_merge_request_path(@project, @merge_request), class: 'btn btn-sm' do
Show latest version
= "of the diff" if @commit
......@@ -690,11 +690,20 @@ describe SystemNoteService do
end
describe '.new_commit_summary' do
let(:merge_request) { create(:merge_request, :simple, target_project: project, source_project: project) }
it 'escapes HTML titles' do
commit = double(title: '<pre>This is a test</pre>', short_id: '12345678')
escaped = '* 12345678 - &lt;pre&gt;This is a test&lt;&#x2F;pre&gt;'
escaped = '&lt;pre&gt;This is a test&lt;&#x2F;pre&gt;'
expect(described_class.new_commit_summary(merge_request, [commit])).to all(match(%r[- #{escaped}]))
end
it 'contains the MR diffs commit url' do
commit = merge_request.commits.last
url = %r[/merge_requests/#{merge_request.iid}/diffs\?commit_id=#{commit.id}]
expect(described_class.new_commit_summary([commit])).to eq([escaped])
expect(described_class.new_commit_summary(merge_request, [commit])).to all(match(url))
end
end
......
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