summaryrefslogtreecommitdiff
path: root/lib/ci/api/lint.rb
blob: fab4f8d5925d4c774aa6e5f0f902bf51fe0c10d0 (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
30
31
32
33
34
35
36
37
38
module Ci
  module API
    class Lint < Grape::API
      before { authenticate! }

      resources :lint do
        post do
          begin
            response = {}
            @content = params[:content]

            if @content
              @config_processor = Ci::GitlabCiYamlProcessor.new(@content)
              @stages = @config_processor.stages
              @builds = @config_processor.builds

              response = {
                content: @content,
                status: "syntax is correct"
              }

              @stages.each do |stage|
                response["#{stage}"] = @builds.select { |build| build[:stage] == stage }
              end
            else
              render_api_error!("Please provide content of .gitlab-ci.yml", 400)
            end

            response

          rescue Ci::GitlabCiYamlProcessor::ValidationError, Psych::SyntaxError => e
            error!({ content: @content, status: "syntax is incorrect", message: e.message })
          end
        end
      end
    end
  end
end