Welcome to mirror list, hosted at ThFree Co, Russian Federation.

lint.rb « api « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 51a87f9433cebf662e77736964b9910e18401b4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

module API
  class Lint < Grape::API::Instance
    namespace :ci do
      desc 'Validation of .gitlab-ci.yml content'
      params do
        requires :content, type: String, desc: 'Content of .gitlab-ci.yml'
        optional :include_merged_yaml, type: Boolean, desc: 'Whether or not to include merged CI config yaml in the response'
      end
      post '/lint' do
        result = Gitlab::Ci::YamlProcessor.new(params[:content], user: current_user).execute
        error = result.errors.first

        status 200

        response = if error.blank?
                     { status: 'valid', errors: [] }
                   else
                     { status: 'invalid', errors: [error] }
                   end

        response.tap do |response|
          response[:merged_yaml] = result.merged_yaml if params[:include_merged_yaml]
        end
      end
    end
  end
end