BigW Consortium Gitlab

closing_issue_extractor.rb 885 Bytes
Newer Older
1
module Gitlab
2
  class ClosingIssueExtractor
3
    ISSUE_CLOSING_REGEX = begin
4 5
      link_pattern = URI.regexp(%w(http https))

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

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

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

18 19 20 21
      closing_statements = []
      message.scan(ISSUE_CLOSING_REGEX) do
        closing_statements << Regexp.last_match[0]
      end
22

23
      @extractor.analyze(closing_statements.join(" "))
24

25 26 27
      @extractor.issues.reject do |issue|
        @extractor.project.forked_from?(issue.project) # Don't extract issues on original project
      end
28 29 30
    end
  end
end