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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
972 B
Ruby
Raw Normal View History

# frozen_string_literal: true
module Gitlab
2015-04-03 16:03:26 +00:00
class ClosingIssueExtractor
ISSUE_CLOSING_REGEX = begin
link_pattern = Banzai::Filter::AutolinkFilter::LINK_PATTERN
2015-12-02 17:48:39 +00:00
pattern = Gitlab.config.gitlab.issue_closing_pattern
2015-12-02 17:48:39 +00:00
pattern = pattern.sub('%{issue_ref}', "(?:(?:#{link_pattern})|(?:#{Issue.reference_pattern}))")
Regexp.new(pattern).freeze
end
2015-04-03 16:03:26 +00:00
def initialize(project, current_user = nil)
@project = project
2015-04-03 16:03:26 +00:00
@extractor = Gitlab::ReferenceExtractor.new(project, current_user)
end
2015-04-03 16:03:26 +00:00
def closed_by_message(message)
return [] if message.nil?
2015-05-21 20:35:15 +00:00
closing_statements = []
message.scan(ISSUE_CLOSING_REGEX) do
closing_statements << Regexp.last_match[0]
end
@extractor.analyze(closing_statements.join(" "))
@extractor.issues.reject do |issue|
@extractor.project.forked_from?(issue.project) ||
!issue.project.autoclose_referenced_issues
end
end
end
end