Class: Gitlab::ClosingIssueExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/closing_issue_extractor.rb

Constant Summary collapse

ISSUE_CLOSING_REGEX =
begin
  link_pattern = Banzai::Filter::AutolinkFilter::LINK_PATTERN

  pattern = Gitlab.config.gitlab.issue_closing_pattern
  pattern = pattern.sub('%{issue_ref}', "(?:(?:#{link_pattern})|(?:#{Issue.reference_pattern}))")
  Regexp.new(pattern).freeze
end

Instance Method Summary collapse

Constructor Details

#initialize(project, current_user = nil) ⇒ ClosingIssueExtractor

Returns a new instance of ClosingIssueExtractor.


13
14
15
16
# File 'lib/gitlab/closing_issue_extractor.rb', line 13

def initialize(project, current_user = nil)
  @project = project
  @extractor = Gitlab::ReferenceExtractor.new(project, current_user)
end

Instance Method Details

#closed_by_message(message) ⇒ Object


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gitlab/closing_issue_extractor.rb', line 18

def closed_by_message(message)
  return [] if message.nil?
  return [] unless @project.autoclose_referenced_issues

  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|
    # Don't extract issues from the project this project was forked from
    @extractor.project.forked_from?(issue.project)
  end
end