diff options
Diffstat (limited to 'lib/api/lint.rb')
-rw-r--r-- | lib/api/lint.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/api/lint.rb b/lib/api/lint.rb new file mode 100644 index 00000000000..68eabb571d6 --- /dev/null +++ b/lib/api/lint.rb @@ -0,0 +1,38 @@ +module API + class Lint < Grape::API + resource :lint do + params do + requires :content, type: String, desc: 'content of .gitlab-ci.yml' + end + + desc 'Validation of .gitlab-ci.yml content' + post do + status 200 + + begin + response = { + status: '', + errors: [], + jobs: [] + } + + config_processor = Ci::GitlabCiYamlProcessor.new(params[:content]) + + config_processor.builds.each do |build| + response[:jobs].push("#{build[:name]}") + response[:status] = 'valid' + end + + response + + rescue Ci::GitlabCiYamlProcessor::ValidationError, Psych::SyntaxError => e + status 200 + response[:errors].push(e.message) + response[:status] = 'invalid' + + response + end + end + end + end +end |