diff options
author | Douwe Maan <douwe@selenight.nl> | 2016-04-23 13:34:09 +0300 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2016-04-23 13:34:09 +0300 |
commit | 715959e58190eca661ea377b949af3515d8da913 (patch) | |
tree | 66f8a89e92799401d56eefc01374721b52bba857 /lib/banzai | |
parent | ab1734f9e1e3f07482185c8a4cb168be463fcff5 (diff) |
Fix cross-project milestone ref with invalid project
Diffstat (limited to 'lib/banzai')
-rw-r--r-- | lib/banzai/filter/milestone_reference_filter.rb | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/lib/banzai/filter/milestone_reference_filter.rb b/lib/banzai/filter/milestone_reference_filter.rb index 746e768061c..dad0768f51b 100644 --- a/lib/banzai/filter/milestone_reference_filter.rb +++ b/lib/banzai/filter/milestone_reference_filter.rb @@ -17,9 +17,7 @@ module Banzai return super(text, pattern) if pattern != Milestone.reference_pattern text.gsub(pattern) do |match| - project = project_from_ref($~[:project]) - params = milestone_params($~[:milestone_iid].to_i, $~[:milestone_name]) - milestone = project.milestones.find_by(params) + milestone = find_milestone($~[:project], $~[:milestone_iid], $~[:milestone_name]) if milestone yield match, milestone.iid, $~[:project], $~ @@ -29,6 +27,22 @@ module Banzai end end + def find_milestone(project_ref, milestone_id, milestone_name) + project = project_from_ref(project_ref) + return unless project + + milestone_params = milestone_params(milestone_id, milestone_name) + project.milestones.find_by(milestone_params) + end + + def milestone_params(iid, name) + if name + { name: name.tr('"', '') } + else + { iid: iid.to_i } + end + end + def url_for_object(milestone, project) h = Gitlab::Routing.url_helpers h.namespace_project_milestone_url(project.namespace, project, milestone, @@ -43,14 +57,6 @@ module Banzai html_safe end end - - def milestone_params(iid, name) - if name - { name: name.tr('"', '') } - else - { iid: iid } - end - end end end end |