diff options
author | Katarzyna Kobierska <kkobierska@gmail.com> | 2016-08-23 12:12:21 +0200 |
---|---|---|
committer | Katarzyna Kobierska <kkobierska@gmail.com> | 2016-09-07 12:10:49 +0200 |
commit | 895ca3a74144d4f858b342d1dd4313faeae79229 (patch) | |
tree | 14b4af76867dc45ed01f7e9e5b626838080a6f16 /lib/ci | |
parent | fb1c7254d5764fb495d73b7e5bb16d60fd09bf03 (diff) | |
download | gitlab-ce-895ca3a74144d4f858b342d1dd4313faeae79229.tar.gz |
Add tests for API CI Lint
Diffstat (limited to 'lib/ci')
-rw-r--r-- | lib/ci/api/entities.rb | 7 | ||||
-rw-r--r-- | lib/ci/api/lint.rb | 33 |
2 files changed, 24 insertions, 16 deletions
diff --git a/lib/ci/api/entities.rb b/lib/ci/api/entities.rb index 8052908e78a..3f5bdaba3f5 100644 --- a/lib/ci/api/entities.rb +++ b/lib/ci/api/entities.rb @@ -59,13 +59,6 @@ module Ci expose :id, :variables expose :pipeline, using: Commit, as: :commit end - - class Lint < Grape::Entity - expose :content - expose :status - expose :builds - expose :stages - end end end end diff --git a/lib/ci/api/lint.rb b/lib/ci/api/lint.rb index d781441d2b7..53a80318195 100644 --- a/lib/ci/api/lint.rb +++ b/lib/ci/api/lint.rb @@ -4,19 +4,34 @@ module Ci before { authenticate! } resources :lint do + post do - content = params[:content] + begin + response = {} + @content = params[:content] - if content - config_processor = Ci::GitlabCiYamlProcessor.new(content) - stages = config_processor.stages - builds = config_processor.builds - status = true + if @content + @config_processor = Ci::GitlabCiYamlProcessor.new(@content) + @stages = @config_processor.stages + @builds = @config_processor.builds - response = { status: status, stages: stages, builds: builds } - end + response = { + content: @content, + status: "syntax is correct" + } + + stage_builds = @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 + response + + rescue Ci::GitlabCiYamlProcessor::ValidationError, Psych::SyntaxError => e + error!({ content: @content, status: "syntax is incorrect", message: e.message }) + end end end end |