diff options
author | micael.bergeron <micaelbergeron@gmail.com> | 2017-11-20 09:02:01 -0500 |
---|---|---|
committer | micael.bergeron <micaelbergeron@gmail.com> | 2017-12-07 09:01:27 -0500 |
commit | 3d8fbd12b8f234aa62f4b5ceed21076a7afbcd23 (patch) | |
tree | 605b07654f65bb07c34b6d88a77b57f9b4b0b229 /lib | |
parent | 6b3f0fee151283348b44a69342ec1a6738cd2de0 (diff) | |
download | gitlab-ce-3d8fbd12b8f234aa62f4b5ceed21076a7afbcd23.tar.gz |
add support for commit (in mr) to reference filter
Diffstat (limited to 'lib')
-rw-r--r-- | lib/banzai/filter/commit_reference_filter.rb | 14 | ||||
-rw-r--r-- | lib/banzai/object_renderer.rb | 16 |
2 files changed, 20 insertions, 10 deletions
diff --git a/lib/banzai/filter/commit_reference_filter.rb b/lib/banzai/filter/commit_reference_filter.rb index 714e0319025..f4e0c3111f5 100644 --- a/lib/banzai/filter/commit_reference_filter.rb +++ b/lib/banzai/filter/commit_reference_filter.rb @@ -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) diff --git a/lib/banzai/object_renderer.rb b/lib/banzai/object_renderer.rb index ecb3affbba5..29c4e60f70c 100644 --- a/lib/banzai/object_renderer.rb +++ b/lib/banzai/object_renderer.rb @@ -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 |