summaryrefslogtreecommitdiff
path: root/app/models/project_label.rb
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-09-29 00:21:47 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-19 14:58:25 -0200
commit07709c5576a06179c5365b0d7fe154c5f67ca7e5 (patch)
tree88ab5e1296d4b7775c524b8cef2da8e4b14b463f /app/models/project_label.rb
parent484f19ed1c5c07cbf8ea26fab8b6759961fcf9ca (diff)
downloadgitlab-ce-07709c5576a06179c5365b0d7fe154c5f67ca7e5.tar.gz
Unfold references for group labels when moving issue to another project
Diffstat (limited to 'app/models/project_label.rb')
-rw-r--r--app/models/project_label.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/app/models/project_label.rb b/app/models/project_label.rb
index 1171aa2dbb3..2fc074dc401 100644
--- a/app/models/project_label.rb
+++ b/app/models/project_label.rb
@@ -7,6 +7,30 @@ 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
+ end
+
private
def title_must_not_exist_at_group_level