Simplify pipelines count query

parent 28ab2325
# frozen_string_literal: true # frozen_string_literal: true
module Projects::OnDemandScansHelper module Projects::OnDemandScansHelper
include API::Helpers::GraphqlHelpers # rubocop: disable CodeReuse/ActiveRecord
def on_demand_scans_data(project) def on_demand_scans_data(project)
query = %(
{
project(fullPath: "#{project.full_path}") {
pipelines(source: "dast") {
count
}
}
}
)
pipelines_count = run_graphql!(
query: query,
context: { current_user: current_user },
transform: -> (result) { result.dig('data', 'project', 'pipelines', 'count') }
)
common_data(project).merge({ common_data(project).merge({
'pipelines-count' => pipelines_count, 'pipelines-count' => project.all_pipelines.where(source: Enums::Ci::Pipeline.sources[:ondemand_dast_scan]).count,
'new-dast-scan-path' => new_project_on_demand_scan_path(project), 'new-dast-scan-path' => new_project_on_demand_scan_path(project),
'empty-state-svg-path' => image_path('illustrations/empty-state/ondemand-scan-empty.svg') 'empty-state-svg-path' => image_path('illustrations/empty-state/ondemand-scan-empty.svg')
}) })
end end
# rubocop: enable CodeReuse/ActiveRecord
def on_demand_scans_form_data(project) def on_demand_scans_form_data(project)
common_data(project).merge({ common_data(project).merge({
......
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Projects::OnDemandScansHelper do RSpec.describe Projects::OnDemandScansHelper do
include Devise::Test::ControllerHelpers
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
before do before do
...@@ -13,7 +11,7 @@ RSpec.describe Projects::OnDemandScansHelper do ...@@ -13,7 +11,7 @@ RSpec.describe Projects::OnDemandScansHelper do
describe '#on_demand_scans_data' do describe '#on_demand_scans_data' do
before do before do
allow(helper).to receive(:run_graphql!).and_return(12) create_list(:ci_pipeline, 12, project: project, ref: 'master', source: :ondemand_dast_scan)
end end
it 'returns proper data' do it 'returns proper data' 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