diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /app/graphql/resolvers/ci/config_resolver.rb | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'app/graphql/resolvers/ci/config_resolver.rb')
-rw-r--r-- | app/graphql/resolvers/ci/config_resolver.rb | 74 |
1 files changed, 51 insertions, 23 deletions
diff --git a/app/graphql/resolvers/ci/config_resolver.rb b/app/graphql/resolvers/ci/config_resolver.rb index d6e7c206691..72d3ae30d73 100644 --- a/app/graphql/resolvers/ci/config_resolver.rb +++ b/app/graphql/resolvers/ci/config_resolver.rb @@ -3,40 +3,64 @@ module Resolvers module Ci class ConfigResolver < BaseResolver + include Gitlab::Graphql::Authorize::AuthorizeResource + include ResolvesProject + type Types::Ci::Config::ConfigType, null: true + authorize :read_pipeline + + argument :project_path, GraphQL::ID_TYPE, + required: true, + description: 'The project of the CI config.' + 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) + description: "Contents of '.gitlab-ci.yml'." + + argument :dry_run, GraphQL::BOOLEAN_TYPE, + required: false, + description: 'Run pipeline creation simulation, or only do static check.' + + def resolve(project_path:, content:, dry_run: false) + project = authorized_find!(project_path: project_path) + + result = ::Gitlab::Ci::Lint + .new(project: project, current_user: context[:current_user]) + .validate(content, dry_run: dry_run) + + if result.errors.empty? + { + status: :valid, + errors: [], + stages: make_stages(result.jobs) + } + else + { + status: :invalid, + errors: result.errors + } + end end private def make_jobs(config_jobs) - config_jobs.map do |job_name, job| + config_jobs.map do |job| { - name: job_name, + name: job[:name], stage: job[:stage], - group_name: CommitStatus.new(name: job_name).group_name, - needs: job.dig(:needs, :job) || [] + group_name: CommitStatus.new(name: job[:name]).group_name, + needs: job.dig(:needs) || [], + allow_failure: job[:allow_failure], + before_script: job[:before_script], + script: job[:script], + after_script: job[:after_script], + only: job[:only], + except: job[:except], + when: job[:when], + tags: job[:tag_list], + environment: job[:environment] } end end @@ -55,6 +79,10 @@ module Resolvers .group_by { |group| group[:stage] } .map { |name, groups| { name: name, groups: groups } } end + + def find_object(project_path:) + resolve_project(full_path: project_path) + end end end end |