Class: Gitlab::ClosingIssueExtractor

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

Constant Summary collapse

%r{((http|https)://[^\s>]{1,300})(?<!\?|!|\.|,|:)}
ISSUE_CLOSING_REGEX =
begin
  link_pattern = HTTP_LINK_PATTERN

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

Instance Method Summary collapse

Constructor Details

#initialize(project, current_user = nil) ⇒ ClosingIssueExtractor

Returns a new instance of ClosingIssueExtractor.



20
21
22
23
# File 'lib/gitlab/closing_issue_extractor.rb', line 20

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

Instance Method Details

#closed_by_message(message) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gitlab/closing_issue_extractor.rb', line 25

def closed_by_message(message)
  return [] if message.nil?

  closing_statements = []
  message.scan(ISSUE_CLOSING_REGEX) do
    closing_statements << Regexp.last_match[0]
  end

  @extractor.analyze(closing_statements.join(" "))
  relevant_records = (@extractor.issues + @extractor.work_items).uniq(&:id)

  relevant_records = relevant_records.first(MAX_CLOSING_ISSUES)
  relevant_records.reject do |issue|
    @extractor.project.forked_from?(issue.project)
  end
end