diff options
Diffstat (limited to 'app/graphql/resolvers/ci')
-rw-r--r-- | app/graphql/resolvers/ci/config_resolver.rb | 60 | ||||
-rw-r--r-- | app/graphql/resolvers/ci/jobs_resolver.rb | 2 | ||||
-rw-r--r-- | app/graphql/resolvers/ci/pipeline_stages_resolver.rb | 3 | ||||
-rw-r--r-- | app/graphql/resolvers/ci/runner_setup_resolver.rb | 5 |
4 files changed, 69 insertions, 1 deletions
diff --git a/app/graphql/resolvers/ci/config_resolver.rb b/app/graphql/resolvers/ci/config_resolver.rb new file mode 100644 index 00000000000..d6e7c206691 --- /dev/null +++ b/app/graphql/resolvers/ci/config_resolver.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +module Resolvers + module Ci + class ConfigResolver < BaseResolver + type Types::Ci::Config::ConfigType, null: true + + argument :content, GraphQL::STRING_TYPE, + required: true, + description: 'Contents of .gitlab-ci.yml' + + def resolve(content:) + result = ::Gitlab::Ci::YamlProcessor.new(content).execute + + response = if result.errors.empty? + { + status: :valid, + errors: [], + stages: make_stages(result.jobs) + } + else + { + status: :invalid, + errors: result.errors + } + end + + response.merge(merged_yaml: result.merged_yaml) + end + + private + + def make_jobs(config_jobs) + config_jobs.map do |job_name, job| + { + name: job_name, + stage: job[:stage], + group_name: CommitStatus.new(name: job_name).group_name, + needs: job.dig(:needs, :job) || [] + } + end + end + + def make_groups(job_data) + jobs = make_jobs(job_data) + + jobs_by_group = jobs.group_by { |job| job[:group_name] } + jobs_by_group.map do |name, jobs| + { jobs: jobs, name: name, stage: jobs.first[:stage], size: jobs.size } + end + end + + def make_stages(jobs) + make_groups(jobs) + .group_by { |group| group[:stage] } + .map { |name, groups| { name: name, groups: groups } } + end + end + end +end diff --git a/app/graphql/resolvers/ci/jobs_resolver.rb b/app/graphql/resolvers/ci/jobs_resolver.rb index 8a9ae42b375..2c4911748a5 100644 --- a/app/graphql/resolvers/ci/jobs_resolver.rb +++ b/app/graphql/resolvers/ci/jobs_resolver.rb @@ -5,6 +5,8 @@ module Resolvers class JobsResolver < BaseResolver alias_method :pipeline, :object + type ::Types::Ci::JobType.connection_type, null: true + argument :security_report_types, [Types::Security::ReportTypeEnum], required: false, description: 'Filter jobs by the type of security report they produce' diff --git a/app/graphql/resolvers/ci/pipeline_stages_resolver.rb b/app/graphql/resolvers/ci/pipeline_stages_resolver.rb index f9817d8b97b..98170e0cd2e 100644 --- a/app/graphql/resolvers/ci/pipeline_stages_resolver.rb +++ b/app/graphql/resolvers/ci/pipeline_stages_resolver.rb @@ -5,6 +5,9 @@ module Resolvers class PipelineStagesResolver < BaseResolver include LooksAhead + type Types::Ci::StageType.connection_type, null: true + extras [:lookahead] + alias_method :pipeline, :object def resolve_with_lookahead diff --git a/app/graphql/resolvers/ci/runner_setup_resolver.rb b/app/graphql/resolvers/ci/runner_setup_resolver.rb index 241cd57f74b..f68d71174c3 100644 --- a/app/graphql/resolvers/ci/runner_setup_resolver.rb +++ b/app/graphql/resolvers/ci/runner_setup_resolver.rb @@ -23,7 +23,10 @@ module Resolvers def resolve(platform:, architecture:, **args) instructions = Gitlab::Ci::RunnerInstructions.new( - { current_user: current_user, os: platform, arch: architecture }.merge(target_param(args)) + current_user: current_user, + os: platform, + arch: architecture, + **target_param(args) ) { |