summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejandroluis24@gmail.com>2016-03-31 21:54:00 -0300
committerAlejandro Rodríguez <alejandroluis24@gmail.com>2016-04-20 22:12:43 -0300
commit375e83bb57dc0143691cf6ef7277bec494f060f0 (patch)
tree24163c348d59ed596aa47328fac7d24ce6a4728c /app
parent077f9a4eeef3c64c5f3e9cc5df5442c8817ee1d6 (diff)
downloadgitlab-ce-375e83bb57dc0143691cf6ef7277bec494f060f0.tar.gz
Consistently using iid when treating milestones as referrables
Also, addint a suffix to the reference text when the milestone is in another project
Diffstat (limited to 'app')
-rw-r--r--app/models/milestone.rb25
1 files changed, 18 insertions, 7 deletions
diff --git a/app/models/milestone.rb b/app/models/milestone.rb
index 39dc8d89614..50fa95d4d4b 100644
--- a/app/models/milestone.rb
+++ b/app/models/milestone.rb
@@ -83,10 +83,10 @@ class Milestone < ActiveRecord::Base
(#{Project.reference_pattern})?
#{Regexp.escape(reference_prefix)}
(?:
- (?<milestone_id>\d+) | # Integer-based milestone ID, or
+ (?<milestone_iid>\d+) | # Integer-based milestone iid, or
(?<milestone_name>
- [A-Za-z0-9_-]+ | # String-based single-word milestone title, or
- "[^"]+" # String-based multi-word milestone surrounded in quotes
+ [A-Za-z0-9_-]+ | # String-based single-word milestone title, or
+ "[^"]+" # String-based multi-word milestone surrounded in quotes
)
)
}x
@@ -100,7 +100,18 @@ class Milestone < ActiveRecord::Base
self.where('due_date > ?', Time.now).reorder(due_date: :asc).first
end
- def to_reference(from_project = nil, format: :id)
+ ##
+ # Returns the String necessary to reference this Milestone in Markdown
+ #
+ # format - Symbol format to use (default: :iid, optional: :name)
+ #
+ # Examples:
+ #
+ # Milestone.first.to_reference # => "%1"
+ # Milestone.first.to_reference(format: :name) # => "%\"goal\""
+ # Milestone.first.to_reference(project) # => "gitlab-org/gitlab-ce%1"
+ #
+ def to_reference(from_project = nil, format: :iid)
format_reference = milestone_format_reference(format)
reference = "#{self.class.reference_prefix}#{format_reference}"
@@ -179,13 +190,13 @@ class Milestone < ActiveRecord::Base
private
- def milestone_format_reference(format = :id)
- raise StandardError, 'Unknown format' unless [:id, :name].include?(format)
+ def milestone_format_reference(format = :iid)
+ raise StandardError, 'Unknown format' unless [:iid, :name].include?(format)
if format == :name && !name.include?('"')
%("#{name}")
else
- id
+ iid
end
end
end