2014-06-13 10:19:08 -04:00
|
|
|
module Gitlab
|
2015-04-03 12:03:26 -04:00
|
|
|
class ClosingIssueExtractor
|
2015-11-30 15:15:19 -05:00
|
|
|
ISSUE_CLOSING_REGEX = begin
|
2017-09-21 06:42:16 -04:00
|
|
|
link_pattern = Banzai::Filter::AutolinkFilter::LINK_PATTERN
|
2015-12-02 12:48:39 -05:00
|
|
|
|
2015-11-30 15:15:19 -05:00
|
|
|
pattern = Gitlab.config.gitlab.issue_closing_pattern
|
2015-12-02 12:48:39 -05:00
|
|
|
pattern = pattern.sub('%{issue_ref}', "(?:(?:#{link_pattern})|(?:#{Issue.reference_pattern}))")
|
2015-11-30 15:15:19 -05:00
|
|
|
Regexp.new(pattern).freeze
|
|
|
|
end
|
2014-06-13 10:19:08 -04:00
|
|
|
|
2015-04-03 12:03:26 -04:00
|
|
|
def initialize(project, current_user = nil)
|
|
|
|
@extractor = Gitlab::ReferenceExtractor.new(project, current_user)
|
|
|
|
end
|
2014-09-17 13:08:35 -04:00
|
|
|
|
2015-04-03 12:03:26 -04:00
|
|
|
def closed_by_message(message)
|
|
|
|
return [] if message.nil?
|
2015-05-21 16:35:15 -04:00
|
|
|
|
2015-11-30 15:15:19 -05:00
|
|
|
closing_statements = []
|
|
|
|
message.scan(ISSUE_CLOSING_REGEX) do
|
|
|
|
closing_statements << Regexp.last_match[0]
|
|
|
|
end
|
2014-09-17 13:08:35 -04:00
|
|
|
|
2015-11-30 15:15:19 -05:00
|
|
|
@extractor.analyze(closing_statements.join(" "))
|
2014-09-17 13:08:35 -04:00
|
|
|
|
2016-08-04 05:56:58 -04:00
|
|
|
@extractor.issues.reject do |issue|
|
|
|
|
@extractor.project.forked_from?(issue.project) # Don't extract issues on original project
|
|
|
|
end
|
2014-06-13 10:19:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|