diff options
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/api.rb | 1 | ||||
-rw-r--r-- | lib/api/lint.rb | 38 |
2 files changed, 39 insertions, 0 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb index e14464c1b0d..a08fb056049 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -45,6 +45,7 @@ module API mount ::API::Keys mount ::API::Labels mount ::API::LicenseTemplates + mount ::API::Lint mount ::API::Members mount ::API::MergeRequests mount ::API::Milestones 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 |