2014-09-02 18:07:02 +05:30
|
|
|
module Gitlab
|
2015-04-26 12:48:37 +05:30
|
|
|
class ClosingIssueExtractor
|
2015-12-23 02:04:40 +05:30
|
|
|
ISSUE_CLOSING_REGEX = begin
|
2018-03-17 18:26:18 +05:30
|
|
|
link_pattern = Banzai::Filter::AutolinkFilter::LINK_PATTERN
|
2015-12-23 02:04:40 +05:30
|
|
|
|
|
|
|
pattern = Gitlab.config.gitlab.issue_closing_pattern
|
|
|
|
pattern = pattern.sub('%{issue_ref}', "(?:(?:#{link_pattern})|(?:#{Issue.reference_pattern}))")
|
|
|
|
Regexp.new(pattern).freeze
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def initialize(project, current_user = nil)
|
|
|
|
@extractor = Gitlab::ReferenceExtractor.new(project, current_user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def closed_by_message(message)
|
|
|
|
return [] if message.nil?
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
closing_statements = []
|
|
|
|
message.scan(ISSUE_CLOSING_REGEX) do
|
|
|
|
closing_statements << Regexp.last_match[0]
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
@extractor.analyze(closing_statements.join(" "))
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
@extractor.issues.reject do |issue|
|
2018-03-17 18:26:18 +05:30
|
|
|
# Don't extract issues from the project this project was forked from
|
|
|
|
@extractor.project.forked_from?(issue.project)
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|