2016-09-19 15:04:38 +00:00
|
|
|
class GroupLabel < Label
|
|
|
|
belongs_to :group
|
|
|
|
|
|
|
|
validates :group, presence: true
|
2016-09-29 03:21:47 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# Returns the String necessary to reference this GroupLabel in Markdown
|
|
|
|
#
|
|
|
|
# format - Symbol format to use (default: :id, optional: :name)
|
|
|
|
#
|
|
|
|
# Examples:
|
|
|
|
#
|
|
|
|
# GroupLabel.first.to_reference # => "~1"
|
|
|
|
# GroupLabel.first.to_reference(format: :name) # => "~\"bug\""
|
|
|
|
#
|
|
|
|
# Returns a String
|
|
|
|
#
|
2016-10-11 19:30:40 +00:00
|
|
|
def to_reference(source_project = nil, target_project = nil, format: :id)
|
2016-09-29 03:21:47 +00:00
|
|
|
format_reference = label_format_reference(format)
|
2016-10-11 19:30:40 +00:00
|
|
|
reference = "#{self.class.reference_prefix}#{format_reference}"
|
|
|
|
|
|
|
|
if cross_project_reference?(source_project, target_project)
|
|
|
|
source_project.to_reference + reference
|
|
|
|
else
|
|
|
|
reference
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def cross_project_reference?(source_project, target_project)
|
|
|
|
source_project && target_project && source_project != target_project
|
2016-09-29 03:21:47 +00:00
|
|
|
end
|
2016-09-19 15:04:38 +00:00
|
|
|
end
|