Commit b5607e47 authored by Robert Speicher's avatar Robert Speicher Committed by Robert Speicher

Merge branch 'fix-external-issue-links' into 'master'

Handle external issues in IssueReferenceFilter

Handling of external issues was broken when I refactored
`IssueReferenceFilter` to use fewer SQL queries.

Fixes #18827

See merge request !4789
parent d37fa9db
...@@ -17,6 +17,7 @@ v 8.9.1 (unreleased) ...@@ -17,6 +17,7 @@ v 8.9.1 (unreleased)
- Fix header vertical centering. !4170 - Fix header vertical centering. !4170
- Fix subsequent SAML sign ins. !4718 - Fix subsequent SAML sign ins. !4718
- Prevent invalid URLs from raising exceptions in WikiLink Filter. !4775 - Prevent invalid URLs from raising exceptions in WikiLink Filter. !4775
- Handle external issues in IssueReferenceFilter. !4789
v 8.9.0 v 8.9.0
- Fix builds API response not including commit data - Fix builds API response not including commit data
......
...@@ -31,10 +31,14 @@ module Banzai ...@@ -31,10 +31,14 @@ module Banzai
projects_per_reference.each do |path, project| projects_per_reference.each do |path, project|
issue_ids = references_per_project[path] issue_ids = references_per_project[path]
next unless project.default_issues_tracker? if project.default_issues_tracker?
issues = project.issues.where(iid: issue_ids.to_a)
else
issues = issue_ids.map { |id| ExternalIssue.new(id, project) }
end
project.issues.where(iid: issue_ids.to_a).each do |issue| issues.each do |issue|
hash[project][issue.iid] = issue hash[project][issue.iid.to_i] = issue
end end
end end
......
...@@ -198,4 +198,40 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do ...@@ -198,4 +198,40 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do
expect(doc.to_html).to match(/\(<a.+>Reference<\/a>\.\)/) expect(doc.to_html).to match(/\(<a.+>Reference<\/a>\.\)/)
end end
end end
describe '#issues_per_Project' do
context 'using an internal issue tracker' do
it 'returns a Hash containing the issues per project' do
doc = Nokogiri::HTML.fragment('')
filter = described_class.new(doc, project: project)
expect(filter).to receive(:projects_per_reference).
and_return({ project.path_with_namespace => project })
expect(filter).to receive(:references_per_project).
and_return({ project.path_with_namespace => Set.new([issue.iid]) })
expect(filter.issues_per_project).
to eq({ project => { issue.iid => issue } })
end
end
context 'using an external issue tracker' do
it 'returns a Hash containing the issues per project' do
doc = Nokogiri::HTML.fragment('')
filter = described_class.new(doc, project: project)
expect(project).to receive(:default_issues_tracker?).and_return(false)
expect(filter).to receive(:projects_per_reference).
and_return({ project.path_with_namespace => project })
expect(filter).to receive(:references_per_project).
and_return({ project.path_with_namespace => Set.new([1]) })
expect(filter.issues_per_project[project][1]).
to be_an_instance_of(ExternalIssue)
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