gitlab-org--gitlab-foss/lib/gitlab/reference_extractor.rb

41 lines
1.0 KiB
Ruby
Raw Normal View History

module Gitlab
# Extract possible GFM references from an arbitrary String for further processing.
class ReferenceExtractor < Banzai::ReferenceExtractor
attr_accessor :project, :current_user, :author
def initialize(project, current_user = nil, author = nil)
2015-03-27 10:37:45 +00:00
@project = project
2015-03-27 11:58:23 +00:00
@current_user = current_user
@author = author
2015-10-22 13:40:36 +00:00
@references = {}
super()
end
def analyze(text, context = {})
super(text, context.merge(project: project))
end
2015-12-24 13:43:07 +00:00
%i(user label milestone merge_request snippet commit commit_range).each do |type|
define_method("#{type}s") do
@references[type] ||= references(type, reference_context)
end
end
2015-12-17 22:08:14 +00:00
def issues
if project && project.jira_tracker?
@references[:external_issue] ||= references(:external_issue, reference_context)
2015-12-17 22:08:14 +00:00
else
@references[:issue] ||= references(:issue, reference_context)
2015-12-17 22:08:14 +00:00
end
end
private
def reference_context
{ project: project, current_user: current_user, author: author }
end
end
end