Commit eb5dc4be authored by David Fernandez's avatar David Fernandez

Merge branch...

Merge branch '275818-be-add-info-error-messages-to-security-widget-summary-up-to-date' into 'master'

Add securityReportsUpToDateOnTargetBranch GraphQL

See merge request gitlab-org/gitlab!53907
parents fde6d7e4 6c6d924c
......@@ -2736,6 +2736,7 @@ Autogenerated return type of MarkAsSpamSnippet.
| `reference` | String! | Internal reference of the merge request. Returned in shortened format by default. |
| `reviewers` | UserConnection | Users from whom a review has been requested. |
| `securityAutoFix` | Boolean | Indicates if the merge request is created by @GitLab-Security-Bot. |
| `securityReportsUpToDateOnTargetBranch` | Boolean! | Indicates if the target branch security reports are out of date. |
| `shouldBeRebased` | Boolean! | Indicates if the merge request will be rebased. |
| `shouldRemoveSourceBranch` | Boolean | Indicates if the source branch of the merge request will be deleted after merge. |
| `sourceBranch` | String! | Source branch of the merge request. |
......
......@@ -19,6 +19,10 @@ module EE
null: false, calls_gitaly: true,
method: :has_security_reports?,
description: 'Indicates if the source branch has any security reports.'
field :security_reports_up_to_date_on_target_branch, GraphQL::BOOLEAN_TYPE,
null: false, calls_gitaly: true,
method: :security_reports_up_to_date?,
description: 'Indicates if the target branch security reports are out of date.'
end
def merge_trains_count
......
......@@ -270,6 +270,10 @@ module EE
end
end
def security_reports_up_to_date?
project.security_reports_up_to_date_for_ref?(target_branch)
end
private
def has_approved_license_check?
......
......@@ -301,6 +301,10 @@ module EE
all_pipelines.newest_first(ref: default_branch).with_reports(reports).take
end
def security_reports_up_to_date_for_ref?(ref)
latest_pipeline_with_security_reports(only_successful: true) == ci_pipelines.newest_first(ref: ref).take
end
def ensure_external_webhook_token
return if external_webhook_token.present?
......
---
title: Add securityReportsUpToDateOnTargetBranch field to MergeRequestType to indicate
if the security reports are up to date on the target branch
merge_request: 53907
author:
type: changed
......@@ -7,4 +7,5 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do
it { expect(described_class).to have_graphql_field(:approved, complexity: 2, calls_gitaly?: true) }
it { expect(described_class).to have_graphql_field(:approvals_left, complexity: 2, calls_gitaly?: true) }
it { expect(described_class).to have_graphql_field(:has_security_reports, calls_gitaly?: true) }
it { expect(described_class).to have_graphql_field(:security_reports_up_to_date_on_target_branch, calls_gitaly?: true) }
end
......@@ -1257,4 +1257,33 @@ RSpec.describe MergeRequest do
end
end
end
describe '#security_reports_up_to_date?' do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:merge_request) do
create(:ee_merge_request,
source_project: project,
source_branch: 'feature1',
target_branch: project.default_branch)
end
let_it_be(:pipeline) do
create(:ee_ci_pipeline,
:with_sast_report,
project: project,
ref: merge_request.target_branch)
end
subject { merge_request.security_reports_up_to_date? }
context 'when the target branch security reports are up to date' do
it { is_expected.to be true }
end
context 'when the target branch security reports are out of date' do
let_it_be(:bad_pipeline) { create(:ee_ci_pipeline, :failed, project: project, ref: merge_request.target_branch) }
it { is_expected.to be false }
end
end
end
......@@ -1717,6 +1717,35 @@ RSpec.describe Project do
end
end
describe '#security_reports_up_to_date_for_ref?' do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:merge_request) do
create(:ee_merge_request,
source_project: project,
source_branch: 'feature1',
target_branch: project.default_branch)
end
let_it_be(:pipeline) do
create(:ee_ci_pipeline,
:with_sast_report,
project: project,
ref: merge_request.target_branch)
end
subject { project.security_reports_up_to_date_for_ref?(merge_request.target_branch) }
context 'when the target branch security reports are up to date' do
it { is_expected.to be true }
end
context 'when the target branch security reports are out of date' do
let_it_be(:bad_pipeline) { create(:ee_ci_pipeline, :failed, project: project, ref: merge_request.target_branch) }
it { is_expected.to be false }
end
end
describe '#protected_environment_by_name' do
let_it_be(:project) { create(:project) }
......
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