diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-03-18 14:48:55 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-03-19 18:46:01 +0100 |
commit | 9b13ce0b7a50e65dfba31d4865a728c725daa3fe (patch) | |
tree | be153fe1447886f53975123b0214a6d1d6b608d1 /lib/gitlab | |
parent | fcf106897e2ff38e16e785ad9bcb18d117490fbf (diff) | |
download | gitlab-ce-9b13ce0b7a50e65dfba31d4865a728c725daa3fe.tar.gz |
Improvements in issue move feaure (refactoring)
According to endbosses' suggestions.
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/gfm/reference_unfolder.rb | 25 | ||||
-rw-r--r-- | lib/gitlab/reference_extractor.rb | 10 |
2 files changed, 16 insertions, 19 deletions
diff --git a/lib/gitlab/gfm/reference_unfolder.rb b/lib/gitlab/gfm/reference_unfolder.rb index 0a68d6f977f..cf8de88b856 100644 --- a/lib/gitlab/gfm/reference_unfolder.rb +++ b/lib/gitlab/gfm/reference_unfolder.rb @@ -7,7 +7,9 @@ module Gitlab # in context of. # # `unfold` method tries to find all local references and unfold each of - # those local references to cross reference format. + # those local references to cross reference format, assuming that the + # argument passed to this method is a project that references will be + # viewed from (see `Referable#to_reference method). # # Examples: # @@ -34,17 +36,12 @@ module Gitlab end def unfold(from_project) - return @text unless @text =~ references_pattern + pattern = Gitlab::ReferenceExtractor.references_pattern + return @text unless @text =~ pattern - unfolded = @text.gsub(references_pattern) do |reference| + @text.gsub(pattern) do |reference| unfold_reference(reference, Regexp.last_match, from_project) end - - unless substitution_valid?(unfolded) - raise StandardError, 'Invalid references unfolding!' - end - - unfolded end private @@ -61,16 +58,6 @@ module Gitlab substitution_valid?(new_text) ? cross_reference : reference end - def references_pattern - return @pattern if @pattern - - patterns = Gitlab::ReferenceExtractor::REFERABLES.map do |ref| - ref.to_s.classify.constantize.try(:reference_pattern) - end - - @pattern = Regexp.union(patterns.compact) - end - def referables return @referables if @referables diff --git a/lib/gitlab/reference_extractor.rb b/lib/gitlab/reference_extractor.rb index 8c698d43bef..13c4d64c99b 100644 --- a/lib/gitlab/reference_extractor.rb +++ b/lib/gitlab/reference_extractor.rb @@ -37,6 +37,16 @@ module Gitlab @references.values.flatten end + def self.references_pattern + return @pattern if @pattern + + patterns = REFERABLES.map do |ref| + ref.to_s.classify.constantize.try(:reference_pattern) + end + + @pattern = Regexp.union(patterns.compact) + end + private def reference_context |