Commit 01dd8d15 authored by Max Woolf's avatar Max Woolf

Merge branch 'add-job-type-class' into 'master'

Adds kind field to JobType

See merge request gitlab-org/gitlab!83627
parents 74efd0aa 5232517c
# frozen_string_literal: true
module Types
module Ci
class JobKindEnum < BaseEnum
graphql_name 'CiJobKind'
value 'BUILD', value: ::Ci::Build, description: 'Standard CI job.'
value 'BRIDGE', value: ::Ci::Bridge, description: 'Bridge CI job connecting a parent and child pipeline.'
end
end
end
......@@ -17,6 +17,8 @@ module Types
description: 'Duration of the job in seconds.'
field :id, ::Types::GlobalIDType[::CommitStatus].as('JobID'), null: true,
description: 'ID of the job.'
field :kind, type: ::Types::Ci::JobKindEnum, null: false,
description: 'Indicates the type of job.'
field :name, GraphQL::Types::String, null: true,
description: 'Name of the job.'
field :needs, BuildNeedType.connection_type, null: true,
......@@ -87,6 +89,12 @@ module Types
field :triggered, GraphQL::Types::Boolean, null: true,
description: 'Whether the job was triggered.'
def kind
return ::Ci::Build unless [::Ci::Build, ::Ci::Bridge].include?(object.class)
object.class
end
def pipeline
Gitlab::Graphql::Loaders::BatchModelLoader.new(::Ci::Pipeline, object.pipeline_id).find
end
......
......@@ -9353,6 +9353,7 @@ Represents the total number of issues and their weights for a particular day.
| <a id="cijobduration"></a>`duration` | [`Int`](#int) | Duration of the job in seconds. |
| <a id="cijobfinishedat"></a>`finishedAt` | [`Time`](#time) | When a job has finished running. |
| <a id="cijobid"></a>`id` | [`JobID`](#jobid) | ID of the job. |
| <a id="cijobkind"></a>`kind` | [`CiJobKind!`](#cijobkind) | Indicates the type of job. |
| <a id="cijobmanualjob"></a>`manualJob` | [`Boolean`](#boolean) | Whether the job has a manual action. |
| <a id="cijobname"></a>`name` | [`String`](#string) | Name of the job. |
| <a id="cijobneeds"></a>`needs` | [`CiBuildNeedConnection`](#cibuildneedconnection) | References to builds that must complete before the jobs run. (see [Connections](#connections)) |
......@@ -17772,6 +17773,13 @@ Values for YAML processor result.
| <a id="ciconfigstatusinvalid"></a>`INVALID` | Configuration file is not valid. |
| <a id="ciconfigstatusvalid"></a>`VALID` | Configuration file is valid. |
### `CiJobKind`
| Value | Description |
| ----- | ----------- |
| <a id="cijobkindbridge"></a>`BRIDGE` | Bridge CI job connecting a parent and child pipeline. |
| <a id="cijobkindbuild"></a>`BUILD` | Standard CI job. |
### `CiJobStatus`
| Value | Description |
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GitlabSchema.types['CiJobKind'] do
it 'exposes some job type values' do
expect(described_class.values.keys).to match_array(
(%w[BRIDGE BUILD])
)
end
end
......@@ -21,6 +21,7 @@ RSpec.describe Types::Ci::JobType do
downstreamPipeline
finished_at
id
kind
manual_job
name
needs
......
......@@ -52,6 +52,7 @@ RSpec.describe 'Query.project(fullPath).pipelines.job(id)' do
'name' => job_2.name,
'allowFailure' => job_2.allow_failure,
'duration' => 25,
'kind' => 'BUILD',
'queuedDuration' => 2.0,
'status' => job_2.status.upcase
)
......
......@@ -155,6 +155,56 @@ RSpec.describe 'Query.project.pipeline' do
end
end
describe '.jobs.kind' do
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
let(:query) do
%(
query {
project(fullPath: "#{project.full_path}") {
pipeline(iid: "#{pipeline.iid}") {
stages {
nodes {
groups{
nodes {
jobs {
nodes {
kind
}
}
}
}
}
}
}
}
}
)
end
context 'when the job is a build' do
it 'returns BUILD' do
create(:ci_build, pipeline: pipeline)
post_graphql(query, current_user: user)
job_data = graphql_data_at(:project, :pipeline, :stages, :nodes, :groups, :nodes, :jobs, :nodes).first
expect(job_data['kind']).to eq 'BUILD'
end
end
context 'when the job is a bridge' do
it 'returns BRIDGE' do
create(:ci_bridge, pipeline: pipeline)
post_graphql(query, current_user: user)
job_data = graphql_data_at(:project, :pipeline, :stages, :nodes, :groups, :nodes, :jobs, :nodes).first
expect(job_data['kind']).to eq 'BRIDGE'
end
end
end
describe '.jobs.artifacts' do
let_it_be(:pipeline) { create(:ci_pipeline, project: 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