Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-27 00:07:45 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-27 00:07:45 +0300
commitea335f33ff8c6870e641385a254c1f993bb04038 (patch)
tree2f2c7b69388e11c15864bbe5e9f052699c094319 /app/models/concerns/timebox.rb
parent6ee98e127334fd235f251c4a4a76a396f301ee77 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/concerns/timebox.rb')
-rw-r--r--app/models/concerns/timebox.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/app/models/concerns/timebox.rb b/app/models/concerns/timebox.rb
index d29e6a01c56..16b86401b50 100644
--- a/app/models/concerns/timebox.rb
+++ b/app/models/concerns/timebox.rb
@@ -7,6 +7,7 @@ module Timebox
include CacheMarkdownField
include Gitlab::SQL::Pattern
include IidRoutes
+ include Referable
include StripAttribute
TimeboxStruct = Struct.new(:title, :name, :id) do
@@ -122,6 +123,35 @@ module Timebox
end
end
+ ##
+ # Returns the String necessary to reference a Timebox in Markdown. Group
+ # timeboxes only support name references, and do not support cross-project
+ # references.
+ #
+ # format - Symbol format to use (default: :iid, optional: :name)
+ #
+ # Examples:
+ #
+ # Milestone.first.to_reference # => "%1"
+ # Iteration.first.to_reference(format: :name) # => "*iteration:\"goal\""
+ # Milestone.first.to_reference(cross_namespace_project) # => "gitlab-org/gitlab-foss%1"
+ # Iteration.first.to_reference(same_namespace_project) # => "gitlab-foss*iteration:1"
+ #
+ def to_reference(from = nil, format: :name, full: false)
+ format_reference = timebox_format_reference(format)
+ reference = "#{self.class.reference_prefix}#{format_reference}"
+
+ if project
+ "#{project.to_reference_base(from, full: full)}#{reference}"
+ else
+ reference
+ end
+ end
+
+ def reference_link_text(from = nil)
+ self.class.reference_prefix + self.title
+ end
+
def title=(value)
write_attribute(:title, sanitize_title(value)) if value.present?
end
@@ -162,6 +192,20 @@ module Timebox
private
+ def timebox_format_reference(format = :iid)
+ raise ArgumentError, _('Unknown format') unless [:iid, :name].include?(format)
+
+ if group_timebox? && format == :iid
+ raise ArgumentError, _('Cannot refer to a group %{timebox_type} by an internal id!') % { timebox_type: timebox_name }
+ end
+
+ if format == :name && !name.include?('"')
+ %("#{name}")
+ else
+ iid
+ end
+ end
+
# Timebox titles must be unique across project and group timeboxes
def uniqueness_of_title
if project