Commit 715959e5 authored by Douwe Maan's avatar Douwe Maan
Browse files

Fix cross-project milestone ref with invalid project

parent cb6eb236c3e0
......@@ -17,9 +17,7 @@ def references_in(text, pattern = Milestone.reference_pattern)
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 @@ def references_in(text, pattern = Milestone.reference_pattern)
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 @@ def object_link_text(object, matches)
html_safe
end
end
def milestone_params(iid, name)
if name
{ name: name.tr('"', '') }
else
{ iid: iid }
end
end
end
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment