2015-12-15 14:51:16 +00:00
|
|
|
module Banzai
|
|
|
|
module Filter
|
2015-04-03 00:46:43 +00:00
|
|
|
# HTML filter that replaces merge request references with links. References
|
2015-04-14 22:34:01 +00:00
|
|
|
# to merge requests that do not exist are ignored.
|
2015-04-03 00:46:43 +00:00
|
|
|
#
|
|
|
|
# This filter supports cross-project references.
|
2015-11-16 20:56:28 +00:00
|
|
|
class MergeRequestReferenceFilter < AbstractReferenceFilter
|
|
|
|
def self.object_class
|
|
|
|
MergeRequest
|
2015-04-03 00:46:43 +00:00
|
|
|
end
|
|
|
|
|
2015-11-16 20:56:28 +00:00
|
|
|
def find_object(project, id)
|
|
|
|
project.merge_requests.find_by(iid: id)
|
2015-04-03 00:46:43 +00:00
|
|
|
end
|
|
|
|
|
2015-11-16 20:56:28 +00:00
|
|
|
def url_for_object(mr, project)
|
2015-08-26 01:42:46 +00:00
|
|
|
h = Gitlab::Application.routes.url_helpers
|
2015-04-03 00:46:43 +00:00
|
|
|
h.namespace_project_merge_request_url(project.namespace, project, mr,
|
|
|
|
only_path: context[:only_path])
|
|
|
|
end
|
2015-11-30 20:14:46 +00:00
|
|
|
|
|
|
|
def object_link_text_extras(object, matches)
|
|
|
|
extras = super
|
|
|
|
|
2015-12-08 12:04:59 +00:00
|
|
|
path = matches[:path] if matches.names.include?("path")
|
|
|
|
case path
|
|
|
|
when '/diffs'
|
2015-11-30 20:14:46 +00:00
|
|
|
extras.unshift "diffs"
|
2015-12-08 12:04:59 +00:00
|
|
|
when '/commits'
|
|
|
|
extras.unshift "commits"
|
2015-12-08 21:28:28 +00:00
|
|
|
when '/builds'
|
|
|
|
extras.unshift "builds"
|
2015-11-30 20:14:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
extras
|
|
|
|
end
|
2015-04-03 00:46:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|