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

corrects the url building

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