diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-10-11 22:51:11 +0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2016-10-19 19:58:26 +0300 |
commit | 0e8dd599134f17e58cf533ab21cf3c4a5b50c353 (patch) | |
tree | 3d55561fe27868758ee974ab005b2e69d32916bc /app | |
parent | 247859c82915a0ee88944c1fcda3f6faf49e54c0 (diff) |
Move common logic to reference group/project label to Label#to_reference
Diffstat (limited to 'app')
-rw-r--r-- | app/models/group_label.rb | 27 | ||||
-rw-r--r-- | app/models/label.rb | 28 | ||||
-rw-r--r-- | app/models/project_label.rb | 24 |
3 files changed, 31 insertions, 48 deletions
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 |