2015-12-15 09:51:16 -05:00
|
|
|
require 'banzai'
|
2015-09-01 13:28:19 -04:00
|
|
|
|
2013-05-30 19:16:49 -04:00
|
|
|
module Gitlab
|
|
|
|
# Extract possible GFM references from an arbitrary String for further processing.
|
2015-12-15 09:51:16 -05:00
|
|
|
class ReferenceExtractor < Banzai::ReferenceExtractor
|
|
|
|
attr_accessor :project, :current_user
|
2013-05-30 19:16:49 -04:00
|
|
|
|
2015-12-15 09:51:16 -05:00
|
|
|
def initialize(project, current_user = nil)
|
2015-03-27 06:37:45 -04:00
|
|
|
@project = project
|
2015-03-27 07:58:23 -04:00
|
|
|
@current_user = current_user
|
2013-05-30 19:16:49 -04:00
|
|
|
|
2015-10-22 09:40:36 -04:00
|
|
|
@references = {}
|
2015-12-15 09:51:16 -05:00
|
|
|
|
|
|
|
super()
|
2015-10-14 15:29:35 -04:00
|
|
|
end
|
2015-10-14 13:27:23 -04:00
|
|
|
|
2015-12-15 09:51:16 -05:00
|
|
|
def analyze(text, context = {})
|
|
|
|
super(text, context.merge(project: project))
|
2013-05-30 19:16:49 -04:00
|
|
|
end
|
|
|
|
|
2015-12-17 17:08:14 -05:00
|
|
|
%i(user label merge_request snippet commit commit_range).each do |type|
|
2015-06-02 07:17:11 -04:00
|
|
|
define_method("#{type}s") do
|
2015-12-15 09:51:16 -05:00
|
|
|
@references[type] ||= references(type, project: project, current_user: current_user)
|
2015-06-02 07:17:11 -04:00
|
|
|
end
|
2013-05-30 19:16:49 -04:00
|
|
|
end
|
2015-12-17 17:08:14 -05:00
|
|
|
|
|
|
|
def issues
|
|
|
|
options = { project: project, current_user: current_user }
|
|
|
|
|
|
|
|
if project && project.jira_tracker?
|
|
|
|
@references[:external_issue] ||= references(:external_issue, options)
|
|
|
|
else
|
|
|
|
@references[:issue] ||= references(:issue, options)
|
|
|
|
end
|
|
|
|
end
|
2013-05-30 19:16:49 -04:00
|
|
|
end
|
|
|
|
end
|