Commit 76eb2c96 authored by Robert Speicher's avatar Robert Speicher

Merge branch '223770-link-issues-on-security-dashboard' into 'master'

Create emphemeral IssueLink if Feedback is present

See merge request gitlab-org/gitlab!38592
parents 67739c5b 43d4c395
......@@ -9,10 +9,16 @@ module Resolvers
required: false,
description: 'Filter issue links by link type'
delegate :issue_links, to: :object, private: true
delegate :issue_links, :finding, to: :object, private: true
def resolve(link_type: nil, **)
issue_links.by_link_type(link_type)
links = issue_links.by_link_type(link_type)
return links if links.present? || link_type != 'created'
issue_feedback = finding.issue_feedback
return [] if issue_feedback.blank?
issue_links.build(issue_id: issue_feedback.id, link_type: :created)
end
end
end
......
......@@ -8,8 +8,10 @@ RSpec.describe Resolvers::Vulnerabilities::IssueLinksResolver do
describe '#resolve' do
let_it_be(:user) { create(:user) }
let_it_be(:vulnerability) { create(:vulnerability) }
let_it_be(:issue) { create(:issue, project: vulnerability.project) }
let_it_be(:vulnerability_feedback) { create(:vulnerability_feedback, issue: issue, feedback_type: 'issue', project: vulnerability.project) }
let_it_be(:related_issue) { create(:vulnerabilities_issue_link, :related, vulnerability: vulnerability) }
let_it_be(:created_issue) { create(:vulnerabilities_issue_link, :created, vulnerability: vulnerability) }
let!(:created_issue) { create(:vulnerabilities_issue_link, :created, vulnerability: vulnerability) }
subject { resolve(described_class, obj: vulnerability, args: filters, ctx: { current_user: user }) }
......@@ -24,6 +26,12 @@ RSpec.describe Resolvers::Vulnerabilities::IssueLinksResolver do
let(:filters) { { link_type: 'CREATED' } }
it { is_expected.to match_array([created_issue]) }
context 'and there is no created_issue, but finding has a vulnerability_feedback' do
let!(:created_issue) { nil }
it { is_expected.to all(have_attributes(issue_id: vulnerability_feedback.issue_id, link_type: :created)) }
end
end
context 'when the filter is `RELATED`' do
......
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