Commit 0d81fd05 authored by Katarzyna Kobierska's avatar Katarzyna Kobierska

Code refactor

parent 1a7a900d
......@@ -8,14 +8,12 @@ module Ci
def create
@content = params[:content]
@error = Ci::GitlabCiYamlProcessor.validation_message(@content)
@status = @error.blank?
unless @error.blank?
@status = @error.blank?
else
if @error.blank?
@config_processor = Ci::GitlabCiYamlProcessor.new(@content)
@stages = @config_processor.stages
@builds = @config_processor.builds
@status = true
end
rescue
@error = 'Undefined error'
......
......@@ -5,7 +5,7 @@ module API
requires :content, type: String, desc: 'Content of .gitlab-ci.yml'
end
namespace 'ci' do
namespace :ci do
post '/lint' do
errors = Ci::GitlabCiYamlProcessor.validation_message(params[:content])
......
......@@ -80,6 +80,7 @@ module Ci
def self.validation_message(content)
return 'Please provide content of .gitlab-ci.yml' if content.blank?
begin
Ci::GitlabCiYamlProcessor.new(content)
nil
......
......@@ -1251,7 +1251,7 @@ EOT
end
end
describe "#errors" do
describe "#validation_message" do
context "when the YAML could not be parsed" do
it "returns an error about invalid configutaion" do
content = YAML.dump("invalid: yaml: test")
......
......@@ -4,11 +4,11 @@ describe API::Lint, api: true do
include ApiHelpers
describe 'POST /ci/lint' do
let(:yaml_content) do
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
end
context 'with valid .gitlab-ci.yaml content' do
let(:yaml_content) do
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
end
it 'passes validation' do
post api('/ci/lint'), { content: yaml_content }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment