debian-mirror-gitlab/lib/banzai/filter/commit_reference_filter.rb

44 lines
1.1 KiB
Ruby
Raw Normal View History

2015-12-23 02:04:40 +05:30
module Banzai
module Filter
# HTML filter that replaces commit references with links.
#
# This filter supports cross-project references.
class CommitReferenceFilter < AbstractReferenceFilter
self.reference_type = :commit
2015-12-23 02:04:40 +05:30
def self.object_class
Commit
end
def self.references_in(text, pattern = Commit.reference_pattern)
text.gsub(pattern) do |match|
2017-08-17 22:00:37 +05:30
yield match, $~[:commit], $~[:project], $~[:namespace], $~
2015-12-23 02:04:40 +05:30
end
end
def find_object(project, id)
2015-12-23 02:04:40 +05:30
if project && project.valid_repo?
project.commit(id)
end
end
def url_for_object(commit, project)
2016-06-02 11:05:42 +05:30
h = Gitlab::Routing.url_helpers
2015-12-23 02:04:40 +05:30
h.namespace_project_commit_url(project.namespace, project, commit,
only_path: context[:only_path])
end
def object_link_text_extras(object, matches)
extras = super
path = matches[:path] if matches.names.include?("path")
if path == '/builds'
extras.unshift "builds"
end
extras
end
end
end
end