Commit 6775a749 authored by Michał Zając's avatar Michał Zając

Add #project_default_branch to Vulnerability

parent 4ab27275
......@@ -60,6 +60,8 @@ class Vulnerability < ApplicationRecord
scope :with_severities, -> (severities) { where(severity: severities) }
scope :with_states, -> (states) { where(state: states) }
delegate :default_branch, to: :project, prefix: :project
# There will only be one finding associated with a vulnerability for the foreseeable future
def finding
findings.first
......@@ -72,8 +74,7 @@ class Vulnerability < ApplicationRecord
end
def resolved_on_default_branch
default_branch = project.default_branch
latest_pipeline_for_default_branch = project.pipeline_for(default_branch)
latest_pipeline_for_default_branch = project.pipeline_for(project_default_branch)
latest_pipeline_with_vulnerability = finding.pipelines.order(created_at: :desc).first
latest_pipeline_with_vulnerability != latest_pipeline_for_default_branch
end
......
......@@ -17,6 +17,7 @@ module EE
expose :finding
expose :resolved_on_default_branch
expose :project_default_branch
expose :author_id
expose :updated_by_id
......
......@@ -172,6 +172,15 @@ describe Vulnerability do
it { is_expected.to eq(finding.scanner_name) }
end
describe '#project_default_branch' do
let_it_be(:project) { create(:project, :repository, :with_vulnerabilities) }
let_it_be(:vulnerability) { project.vulnerabilities.first }
subject { vulnerability.project_default_branch }
it { is_expected.to eq("master") }
end
describe '#resolved_on_default_branch' do
let_it_be(:project) { create(:project, :repository, :with_vulnerabilities) }
let_it_be(:pipeline_with_vulnerability) { create(:ci_pipeline, project: project, sha: project.commit.id) }
......
......@@ -72,4 +72,4 @@ DEPENDENCIES
scss_lint (~> 0.56.0)
BUNDLED WITH
1.17.3
2.1.4
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