diff options
Diffstat (limited to 'app/graphql/types/ci')
-rw-r--r-- | app/graphql/types/ci/build_need_type.rb | 14 | ||||
-rw-r--r-- | app/graphql/types/ci/ci_cd_setting_type.rb | 4 | ||||
-rw-r--r-- | app/graphql/types/ci/config/config_type.rb | 2 | ||||
-rw-r--r-- | app/graphql/types/ci/config/group_type.rb | 2 | ||||
-rw-r--r-- | app/graphql/types/ci/config/job_restriction_type.rb | 15 | ||||
-rw-r--r-- | app/graphql/types/ci/config/job_type.rb | 33 | ||||
-rw-r--r-- | app/graphql/types/ci/config/stage_type.rb | 2 | ||||
-rw-r--r-- | app/graphql/types/ci/job_type.rb | 6 | ||||
-rw-r--r-- | app/graphql/types/ci/stage_type.rb | 33 |
9 files changed, 99 insertions, 12 deletions
diff --git a/app/graphql/types/ci/build_need_type.rb b/app/graphql/types/ci/build_need_type.rb new file mode 100644 index 00000000000..3bd81f8fa8f --- /dev/null +++ b/app/graphql/types/ci/build_need_type.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Types + module Ci + # rubocop: disable Graphql/AuthorizeTypes + # This type is only accessible from CiJob + class BuildNeedType < BaseObject + graphql_name 'CiBuildNeed' + + field :name, GraphQL::STRING_TYPE, null: true, + description: 'Name of the job we need to complete.' + end + end +end diff --git a/app/graphql/types/ci/ci_cd_setting_type.rb b/app/graphql/types/ci/ci_cd_setting_type.rb index 207c37f9538..e80771cdf9d 100644 --- a/app/graphql/types/ci/ci_cd_setting_type.rb +++ b/app/graphql/types/ci/ci_cd_setting_type.rb @@ -11,8 +11,10 @@ module Types description: 'Whether merge pipelines are enabled.', method: :merge_pipelines_enabled? field :merge_trains_enabled, GraphQL::BOOLEAN_TYPE, null: true, - description: 'Whether merge trains are enabled.', + description: 'Whether merge trains are enabled.', method: :merge_trains_enabled? + field :keep_latest_artifact, GraphQL::BOOLEAN_TYPE, null: true, + description: 'Whether to keep the latest builds artifacts.' field :project, Types::ProjectType, null: true, description: 'Project the CI/CD settings belong to.' end diff --git a/app/graphql/types/ci/config/config_type.rb b/app/graphql/types/ci/config/config_type.rb index e54b345f3d3..29093c6d3c9 100644 --- a/app/graphql/types/ci/config/config_type.rb +++ b/app/graphql/types/ci/config/config_type.rb @@ -11,7 +11,7 @@ module Types description: 'Linting errors' field :merged_yaml, GraphQL::STRING_TYPE, null: true, description: 'Merged CI config YAML' - field :stages, [Types::Ci::Config::StageType], null: true, + field :stages, Types::Ci::Config::StageType.connection_type, null: true, description: 'Stages of the pipeline' field :status, Types::Ci::Config::StatusEnum, null: true, description: 'Status of linting, can be either valid or invalid' diff --git a/app/graphql/types/ci/config/group_type.rb b/app/graphql/types/ci/config/group_type.rb index 8b0db2934a4..8e133bbcba8 100644 --- a/app/graphql/types/ci/config/group_type.rb +++ b/app/graphql/types/ci/config/group_type.rb @@ -9,7 +9,7 @@ module Types field :name, GraphQL::STRING_TYPE, null: true, description: 'Name of the job group' - field :jobs, [Types::Ci::Config::JobType], null: true, + field :jobs, Types::Ci::Config::JobType.connection_type, null: true, description: 'Jobs in group' field :size, GraphQL::INT_TYPE, null: true, description: 'Size of the job group' diff --git a/app/graphql/types/ci/config/job_restriction_type.rb b/app/graphql/types/ci/config/job_restriction_type.rb new file mode 100644 index 00000000000..294e3c94571 --- /dev/null +++ b/app/graphql/types/ci/config/job_restriction_type.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Types + module Ci + # rubocop: disable Graphql/AuthorizeTypes + module Config + class JobRestrictionType < BaseObject + graphql_name 'CiConfigJobRestriction' + + field :refs, [GraphQL::STRING_TYPE], null: true, + description: 'The Git refs the job restriction applies to.' + end + end + end +end diff --git a/app/graphql/types/ci/config/job_type.rb b/app/graphql/types/ci/config/job_type.rb index 59bcbd9ef49..65fdc4c2615 100644 --- a/app/graphql/types/ci/config/job_type.rb +++ b/app/graphql/types/ci/config/job_type.rb @@ -8,13 +8,36 @@ module Types graphql_name 'CiConfigJob' field :name, GraphQL::STRING_TYPE, null: true, - description: 'Name of the job' + description: 'Name of the job.' field :group_name, GraphQL::STRING_TYPE, null: true, - description: 'Name of the job group' + description: 'Name of the job group.' field :stage, GraphQL::STRING_TYPE, null: true, - description: 'Name of the job stage' - field :needs, [Types::Ci::Config::NeedType], null: true, - description: 'Builds that must complete before the jobs run' + description: 'Name of the job stage.' + field :needs, Types::Ci::Config::NeedType.connection_type, null: true, + description: 'Builds that must complete before the jobs run.' + field :allow_failure, GraphQL::BOOLEAN_TYPE, null: true, + description: 'Allow job to fail.' + field :before_script, [GraphQL::STRING_TYPE], null: true, + description: 'Override a set of commands that are executed before the job.' + field :script, [GraphQL::STRING_TYPE], null: true, + description: 'Shell script that is executed by a runner.' + field :after_script, [GraphQL::STRING_TYPE], null: true, + description: 'Override a set of commands that are executed after the job.' + field :when, GraphQL::STRING_TYPE, null: true, + description: 'When to run the job.', + resolver_method: :restrict_when_to_run_jobs + field :environment, GraphQL::STRING_TYPE, null: true, + description: 'Name of an environment to which the job deploys.' + field :except, Types::Ci::Config::JobRestrictionType, null: true, + description: 'Limit when jobs are not created.' + field :only, Types::Ci::Config::JobRestrictionType, null: true, + description: 'Jobs are created when these conditions do not apply.' + field :tags, [GraphQL::STRING_TYPE], null: true, + description: 'List of tags that are used to select a runner.' + + def restrict_when_to_run_jobs + object[:when] + end end end end diff --git a/app/graphql/types/ci/config/stage_type.rb b/app/graphql/types/ci/config/stage_type.rb index 20618bc41f8..2008c553629 100644 --- a/app/graphql/types/ci/config/stage_type.rb +++ b/app/graphql/types/ci/config/stage_type.rb @@ -9,7 +9,7 @@ module Types field :name, GraphQL::STRING_TYPE, null: true, description: 'Name of the stage' - field :groups, [Types::Ci::Config::GroupType], null: true, + field :groups, Types::Ci::Config::GroupType.connection_type, null: true, description: 'Groups of jobs for the stage' end end diff --git a/app/graphql/types/ci/job_type.rb b/app/graphql/types/ci/job_type.rb index 5b6e8fe8567..f8bf1732e63 100644 --- a/app/graphql/types/ci/job_type.rb +++ b/app/graphql/types/ci/job_type.rb @@ -2,16 +2,16 @@ module Types module Ci - # rubocop: disable Graphql/AuthorizeTypes class JobType < BaseObject graphql_name 'CiJob' + authorize :read_commit_status field :pipeline, Types::Ci::PipelineType, null: true, description: 'Pipeline the job belongs to' field :name, GraphQL::STRING_TYPE, null: true, description: 'Name of the job' - field :needs, JobType.connection_type, null: true, - description: 'Builds that must complete before the jobs run' + 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 :scheduled_at, Types::TimeType, null: true, diff --git a/app/graphql/types/ci/stage_type.rb b/app/graphql/types/ci/stage_type.rb index fd0bde90836..695e7c61bd9 100644 --- a/app/graphql/types/ci/stage_type.rb +++ b/app/graphql/types/ci/stage_type.rb @@ -9,6 +9,7 @@ module Types field :name, GraphQL::STRING_TYPE, null: true, description: 'Name of the stage' field :groups, Ci::GroupType.connection_type, null: true, + extras: [:lookahead], description: 'Group of jobs for the stage' field :detailed_status, Types::Ci::DetailedStatusType, null: true, description: 'Detailed status of the stage' @@ -16,6 +17,38 @@ module Types def detailed_status object.detailed_status(context[:current_user]) end + + # Issues one query per pipeline + def groups(lookahead:) + key = ::Gitlab::Graphql::BatchKey.new(object, lookahead, object_name: :stage) + + BatchLoader::GraphQL.for(key).batch(default_value: []) do |keys, loader| + by_pipeline = keys.group_by(&:pipeline) + include_needs = keys.any? { |k| k.requires?(%i[nodes jobs nodes needs]) } + + by_pipeline.each do |pl, key_group| + project = pl.project + indexed = key_group.index_by(&:id) + + jobs_for_pipeline(pl, indexed.keys, include_needs).each do |stage_id, statuses| + key = indexed[stage_id] + groups = ::Ci::Group.fabricate(project, key.stage, statuses) + loader.call(key, groups) + end + end + end + end + + private + + # rubocop: disable CodeReuse/ActiveRecord + def jobs_for_pipeline(pipeline, stage_ids, include_needs) + results = pipeline.latest_statuses.where(stage_id: stage_ids) + results = results.preload(:needs) if include_needs + + results.group_by(&:stage_id) + end + # rubocop: enable CodeReuse/ActiveRecord end end end |