gitlab-org--gitlab-foss/app/models/external_issue.rb
Sean McGivern 9f612cc428 Fix issues mentioned but not closed for JIRA
The `ReferenceExtractor` would return an array of `ExternalIssue`
objects, and then perform `Array#-` to remove the issues
closed. `ExternalIssue`s had `==` defined, but not `hash` or `eql?`,
which are used by `Array#-`.
2017-03-06 14:18:49 +00:00

55 lines
886 B
Ruby

class ExternalIssue
include Referable
def initialize(issue_identifier, project)
@issue_identifier, @project = issue_identifier, project
end
def to_s
@issue_identifier.to_s
end
def id
@issue_identifier.to_s
end
def iid
@issue_identifier.to_s
end
def title
"External Issue #{self}"
end
def ==(other)
other.is_a?(self.class) && (to_s == other.to_s)
end
alias_method :eql?, :==
def hash
[self.class, to_s].hash
end
def project
@project
end
def project_id
@project.id
end
# Pattern used to extract `JIRA-123` issue references from text
def self.reference_pattern
@reference_pattern ||= %r{(?<issue>\b([A-Z][A-Z0-9_]+-)\d+)}
end
def to_reference(_from_project = nil, full: nil)
id
end
def reference_link_text(from_project = nil)
return "##{id}" if id =~ /^\d+$/
id
end
end