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

Code refactor

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