diff options
Diffstat (limited to 'app/graphql/types/ci/job_type.rb')
-rw-r--r-- | app/graphql/types/ci/job_type.rb | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/app/graphql/types/ci/job_type.rb b/app/graphql/types/ci/job_type.rb index f2529b8e5c8..eb235e6ee73 100644 --- a/app/graphql/types/ci/job_type.rb +++ b/app/graphql/types/ci/job_type.rb @@ -6,7 +6,9 @@ module Types graphql_name 'CiJob' authorize :read_commit_status - field :id, GraphQL::ID_TYPE, null: false, + connection_type_class(Types::CountableConnectionType) + + field :id, ::Types::GlobalIDType[::CommitStatus].as('JobID'), null: true, description: 'ID of the job.' field :pipeline, Types::Ci::PipelineType, null: true, description: 'Pipeline the job belongs to.' @@ -14,16 +16,33 @@ module Types description: 'Name of the job.' field :needs, BuildNeedType.connection_type, null: true, description: 'References to builds that must complete before the jobs run.' - field :detailed_status, Types::Ci::DetailedStatusType, null: true, - description: 'Detailed status of the job.' + field :status, + type: ::Types::Ci::JobStatusEnum, + null: true, + description: "Status of the job." + field :stage, Types::Ci::StageType, null: true, + description: 'Stage of the job.' + field :allow_failure, ::GraphQL::BOOLEAN_TYPE, null: false, + description: 'Whether this job is allowed to fail.' + field :duration, GraphQL::INT_TYPE, null: true, + description: 'Duration of the job in seconds.' + + # Life-cycle timestamps: + field :created_at, Types::TimeType, null: false, + description: "When the job was created." + field :queued_at, Types::TimeType, null: true, + description: 'When the job was enqueued and marked as pending.' + field :started_at, Types::TimeType, null: true, + description: 'When the job was started.' + field :finished_at, Types::TimeType, null: true, + description: 'When a job has finished running.' field :scheduled_at, Types::TimeType, null: true, description: 'Schedule for the build.' + + field :detailed_status, Types::Ci::DetailedStatusType, null: true, + description: 'Detailed status of the job.' field :artifacts, Types::Ci::JobArtifactType.connection_type, null: true, description: 'Artifacts generated by the job.' - field :finished_at, Types::TimeType, null: true, - description: 'When a job has finished running.' - field :duration, GraphQL::INT_TYPE, null: true, - description: 'Duration of the job in seconds.' field :short_sha, type: GraphQL::STRING_TYPE, null: false, description: 'Short SHA1 ID of the commit.' @@ -40,6 +59,30 @@ module Types object.job_artifacts end end + + def stage + ::Gitlab::Graphql::Lazy.with_value(pipeline) do |pl| + BatchLoader::GraphQL.for([pl, object.stage]).batch do |ids, loader| + by_pipeline = ids + .group_by(&:first) + .transform_values { |grp| grp.map(&:second) } + + by_pipeline.each do |p, names| + p.stages.by_name(names).each { |s| loader.call([p, s.name], s) } + end + end + end + end + + # This class is a secret union! + # TODO: turn this into an actual union, so that fields can be referenced safely! + def id + return unless object.id.present? + + model_name = object.type || ::CommitStatus.name + id = object.id + Gitlab::GlobalId.build(model_name: model_name, id: id) + end end end end |