diff --git a/app/models/group_label.rb b/app/models/group_label.rb index c7efa29a5f6..a1d8d087726 100644 --- a/app/models/group_label.rb +++ b/app/models/group_label.rb @@ -3,32 +3,7 @@ class GroupLabel < Label validates :group, presence: true - ## - # 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 - # def to_reference(source_project = nil, target_project = nil, format: :id) - format_reference = label_format_reference(format) - 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 + super(source_project, target_project, format: format) end end diff --git a/app/models/label.rb b/app/models/label.rb index 7dd2d8790b0..444f45fa09e 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -97,8 +97,36 @@ class Label < ActiveRecord::Base write_attribute(:title, sanitize_title(value)) if value.present? end + ## + # Returns the String necessary to reference this Label in Markdown + # + # format - Symbol format to use (default: :id, optional: :name) + # + # Examples: + # + # Label.first.to_reference # => "~1" + # Label.first.to_reference(format: :name) # => "~\"bug\"" + # Label.first.to_reference(project1, project2) # => "gitlab-org/gitlab-ce~1" + # + # Returns a String + # + def to_reference(source_project = nil, target_project = nil, format: :id) + format_reference = label_format_reference(format) + 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 + end + def issues_count(user, params = {}) IssuesFinder.new(user, { label_name: title, scope: 'all' }.merge(params)) .execute diff --git a/app/models/project_label.rb b/app/models/project_label.rb index 2fc074dc401..a246a90435d 100644 --- a/app/models/project_label.rb +++ b/app/models/project_label.rb @@ -7,28 +7,8 @@ class ProjectLabel < Label delegate :group, to: :project, allow_nil: true - ## - # Returns the String necessary to reference this ProjectLabel in Markdown - # - # format - Symbol format to use (default: :id, optional: :name) - # - # Examples: - # - # ProjectLabel.first.to_reference # => "~1" - # ProjectLabel.first.to_reference(format: :name) # => "~\"bug\"" - # ProjectLabel.first.to_reference(project) # => "gitlab-org/gitlab-ce~1" - # - # Returns a String - # - def to_reference(from_project = nil, format: :id) - format_reference = label_format_reference(format) - reference = "#{self.class.reference_prefix}#{format_reference}" - - if cross_project_reference?(from_project) - project.to_reference + reference - else - reference - end + def to_reference(target_project = nil, format: :id) + super(project, target_project, format: format) end private