Skip to content
Snippets Groups Projects
Commit 0d81fd05 authored by Katarzyna Kobierska's avatar Katarzyna Kobierska
Browse files

Code refactor

parent 1a7a900d
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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'
Loading
Loading
Loading
Loading
@@ -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])
 
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
Loading
Loading
@@ -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")
Loading
Loading
Loading
Loading
@@ -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 }
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment