add support for commit (in mr) to reference filter
This commit is contained in:
parent
6b3f0fee15
commit
3d8fbd12b8
|
@ -3,7 +3,7 @@ module RendersNotes
|
|||
preload_noteable_for_regular_notes(notes)
|
||||
preload_max_access_for_authors(notes, @project)
|
||||
preload_first_time_contribution_for_authors(noteable, notes)
|
||||
Notes::RenderService.new(current_user).execute(notes, @project)
|
||||
Notes::RenderService.new(current_user).execute(notes, @project, noteable_context(noteable))
|
||||
|
||||
notes
|
||||
end
|
||||
|
@ -26,4 +26,13 @@ module RendersNotes
|
|||
|
||||
notes.each {|n| n.specialize_for_first_contribution!(noteable)}
|
||||
end
|
||||
|
||||
def noteable_context(noteable)
|
||||
case noteable
|
||||
when MergeRequest
|
||||
{ merge_request: noteable }
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1021,4 +1021,13 @@ class MergeRequest < ActiveRecord::Base
|
|||
|
||||
project.merge_requests.merged.where(author_id: author_id).empty?
|
||||
end
|
||||
|
||||
def banzai_render_context(field)
|
||||
# this will be used to reference these commit in the context of the MR
|
||||
# the URL are built differently
|
||||
{
|
||||
merge_request: self,
|
||||
mr_commit_shas: all_commit_shas
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -405,6 +405,10 @@ class Note < ActiveRecord::Base
|
|||
noteable_object&.touch
|
||||
end
|
||||
|
||||
def banzai_render_context(field)
|
||||
super.merge(noteable: noteable)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def keep_around_commit
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
- ref = local_assigns.fetch(:ref) { merge_request&.source_branch }
|
||||
- link = commit_path(project, commit, merge_request: merge_request)
|
||||
|
||||
- cache_key = [project.full_path, commit.id, current_application_settings, @path.presence, current_controller?(:commits), merge_request.iid, view_details, 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
|
||||
|
|
|
@ -24,8 +24,18 @@ module Banzai
|
|||
|
||||
def url_for_object(commit, project)
|
||||
h = Gitlab::Routing.url_helpers
|
||||
h.project_commit_url(project, commit,
|
||||
only_path: context[:only_path])
|
||||
noteable = context[:merge_request] || context[:noteable]
|
||||
|
||||
if noteable.is_a?(MergeRequest) &&
|
||||
noteable.all_commit_shas.include?(commit.id)
|
||||
|
||||
# the internal shas are in the context?
|
||||
# why not preload in the object?, just make sure we have the same ref
|
||||
# in all the rendering
|
||||
h.diffs_project_merge_request_url(project, noteable, commit_id: commit.id)
|
||||
else
|
||||
h.project_commit_url(project, commit, only_path: context[:only_path])
|
||||
end
|
||||
end
|
||||
|
||||
def object_link_text_extras(object, matches)
|
||||
|
|
|
@ -18,10 +18,10 @@ module Banzai
|
|||
# project - A Project to use for redacting Markdown.
|
||||
# user - The user viewing the Markdown/HTML documents, if any.
|
||||
# context - A Hash containing extra attributes to use during redaction
|
||||
def initialize(project, user = nil, redaction_context = {})
|
||||
def initialize(project, user = nil, context = {})
|
||||
@project = project
|
||||
@user = user
|
||||
@redaction_context = redaction_context
|
||||
@context = base_context.merge(context)
|
||||
end
|
||||
|
||||
# Renders and redacts an Array of objects.
|
||||
|
@ -48,7 +48,8 @@ module Banzai
|
|||
pipeline = HTML::Pipeline.new([])
|
||||
|
||||
objects.map do |object|
|
||||
pipeline.to_document(Banzai.render_field(object, attribute))
|
||||
context = context_for(object, attribute)
|
||||
pipeline.to_document(Banzai.render_field(object, attribute, context))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -73,20 +74,19 @@ module Banzai
|
|||
|
||||
# Returns a Banzai context for the given object and attribute.
|
||||
def context_for(object, attribute)
|
||||
base_context.merge(object.banzai_render_context(attribute))
|
||||
@context.merge(object.banzai_render_context(attribute))
|
||||
end
|
||||
|
||||
def base_context
|
||||
@base_context ||= @redaction_context.merge(
|
||||
{
|
||||
current_user: user,
|
||||
project: project,
|
||||
skip_redaction: true
|
||||
)
|
||||
}
|
||||
end
|
||||
|
||||
def save_options
|
||||
return {} unless base_context[:xhtml]
|
||||
|
||||
return {} unless @context[:xhtml]
|
||||
{ save_with: Nokogiri::XML::Node::SaveOptions::AS_XHTML }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue