Commit b72a8bf8 authored by Dmytro Zaporozhets (DZ)'s avatar Dmytro Zaporozhets (DZ)

Merge branch 'lm-add-scheduling-type-to-job' into 'master'

Adds scheduling_type to Job and UsesNeeds to Pipeline

See merge request gitlab-org/gitlab!57398
parents 2d978b49 f05ffcb7
......@@ -45,6 +45,8 @@ module Types
description: 'Artifacts generated by the job.'
field :short_sha, type: GraphQL::STRING_TYPE, null: false,
description: 'Short SHA1 ID of the commit.'
field :scheduling_type, GraphQL::STRING_TYPE, null: true,
description: 'Type of pipeline scheduling. Value is `dag` if the pipeline uses the `needs` keyword, and `stage` otherwise.'
def pipeline
Gitlab::Graphql::Loaders::BatchModelLoader.new(::Ci::Pipeline, object.pipeline_id).find
......
......@@ -118,6 +118,10 @@ module Types
field :active, GraphQL::BOOLEAN_TYPE, null: false, method: :active?,
description: 'Indicates if the pipeline is active.'
field :uses_needs, GraphQL::BOOLEAN_TYPE, null: true,
method: :uses_needs?,
description: 'Indicates if the pipeline has jobs with `needs` dependencies.'
def detailed_status
object.detailed_status(current_user)
end
......
......@@ -446,6 +446,10 @@ module Ci
@auto_devops_pipelines_completed_total ||= Gitlab::Metrics.counter(:auto_devops_pipelines_completed_total, 'Number of completed auto devops pipelines')
end
def uses_needs?
builds.where(scheduling_type: :dag).any?
end
def stages_count
statuses.select(:stage).distinct.count
end
......
---
title: Exposes schedulingType on CiJobType and adds usesNeeds to PipelineType
merge_request: 57398
author:
type: added
......@@ -1220,6 +1220,7 @@ An edge in a connection.
| `pipeline` | [`Pipeline`](#pipeline) | Pipeline the job belongs to. |
| `queuedAt` | [`Time`](#time) | When the job was enqueued and marked as pending. |
| `scheduledAt` | [`Time`](#time) | Schedule for the build. |
| `schedulingType` | [`String`](#string) | Type of pipeline scheduling. Value is `dag` if the pipeline uses the `needs` keyword, and `stage` otherwise. |
| `shortSha` | [`String!`](#string) | Short SHA1 ID of the commit. |
| `stage` | [`CiStage`](#cistage) | Stage of the job. |
| `startedAt` | [`Time`](#time) | When the job was started. |
......@@ -4622,6 +4623,7 @@ Information about pagination in a connection.
| `upstream` | [`Pipeline`](#pipeline) | Pipeline that triggered the pipeline. |
| `user` | [`User`](#user) | Pipeline user. |
| `userPermissions` | [`PipelinePermissions!`](#pipelinepermissions) | Permissions for the current user on the resource. |
| `usesNeeds` | [`Boolean`](#boolean) | Indicates if the pipeline has jobs with `needs` dependencies. |
| `warnings` | [`Boolean!`](#boolean) | Indicates if a pipeline has warnings. |
### `PipelineAnalytics`
......
......@@ -20,7 +20,7 @@ RSpec.describe Types::Ci::JobType do
pipeline
queued_at
scheduledAt
scheduledAt
schedulingType
shortSha
stage
started_at
......
......@@ -11,8 +11,8 @@ RSpec.describe Types::Ci::PipelineType do
expected_fields = %w[
id iid sha before_sha status detailed_status config_source duration
coverage created_at updated_at started_at finished_at committed_at
stages user retryable cancelable jobs job source_job downstream
upstream path project active user_permissions warnings commit_path
stages user retryable cancelable jobs source_job job downstream
upstream path project active user_permissions warnings commit_path uses_needs
]
if Gitlab.ee?
......
......@@ -3782,6 +3782,26 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
end
end
describe '#uses_needs?' do
let_it_be(:pipeline) { create(:ci_pipeline) }
context 'when the scheduling type is `dag`' do
it 'returns true' do
create(:ci_build, pipeline: pipeline, scheduling_type: :dag)
expect(pipeline.uses_needs?).to eq(true)
end
end
context 'when the scheduling type is nil or stage' do
it 'returns false' do
create(:ci_build, pipeline: pipeline, scheduling_type: :stage)
expect(pipeline.uses_needs?).to eq(false)
end
end
end
describe '#total_size' do
let(:pipeline) { create(:ci_pipeline) }
let!(:build_job1) { create(:ci_build, pipeline: pipeline, stage_idx: 0) }
......
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