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

Change class method name

parent 9e313c12
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -92,6 +92,7 @@ v 8.12.0 (unreleased)
- Refactor the triggers page and documentation !6217
- Show values of CI trigger variables only when clicked (Katarzyna Kobierska Ula Budziszewska)
- Use default clone protocol on "check out, review, and merge locally" help page URL
- API for Ci Lint !5953 (Katarzyna Kobierska Urszula Budziszewska)
 
v 8.11.5 (unreleased)
- Optimize branch lookups and force a repository reload for Repository#find_branch
Loading
Loading
Loading
Loading
@@ -11,9 +11,9 @@ module Ci
if @content.blank?
@status = false
@error = "Please provide content of .gitlab-ci.yml"
elsif Ci::GitlabCiYamlProcessor.validate(@content) != "valid"
elsif Ci::GitlabCiYamlProcessor.errors(@content) != nil
@status = false
@error = Ci::GitlabCiYamlProcessor.validate(@content)
@error = Ci::GitlabCiYamlProcessor.errors(@content)
else
@config_processor = Ci::GitlabCiYamlProcessor.new(@content)
@stages = @config_processor.stages
Loading
Loading
Loading
Loading
@@ -2,7 +2,7 @@ module API
class Lint < Grape::API
resource :lint do
params do
requires :content, type: String, desc: 'content of .gitlab-ci.yml'
requires :content, type: String, desc: 'Content of .gitlab-ci.yml'
end
 
desc 'Validation of .gitlab-ci.yml content'
Loading
Loading
@@ -13,9 +13,9 @@ module API
jobs: []
}
 
if Ci::GitlabCiYamlProcessor.validate(@content) != "valid"
if Ci::GitlabCiYamlProcessor.errors(@content) != nil
status 200
response[:errors].push(e.message)
response[:errors].push(Ci::GitlabCiYamlProcessor.errors(@content))
response[:status] = 'invalid'
 
response
Loading
Loading
Loading
Loading
@@ -78,10 +78,10 @@ module Ci
}
end
 
def self.validate(content)
def self.errors(content)
begin
Ci::GitlabCiYamlProcessor.new(content)
"valid"
nil
rescue ValidationError, Psych::SyntaxError => e
e.message
end
Loading
Loading
Loading
Loading
@@ -1251,21 +1251,21 @@ EOT
end
end
 
describe "#validate(config)" do
describe "#errors(content)" do
describe "Error handling" do
it "returns error to parse YAML" do
config = YAML.dump("invalid: yaml: test")
expect(GitlabCiYamlProcessor.validate(config)).to eq "Invalid configuration format"
it "returns error if parse YAML failed" do
content = YAML.dump("invalid: yaml: test")
expect(GitlabCiYamlProcessor.errors(content)).to eq "Invalid configuration format"
end
 
it "returns errors if tags parameter is invalid" do
config = YAML.dump({ rspec: { script: "test", tags: "mysql" } })
expect(GitlabCiYamlProcessor.validate(config)).to eq "jobs:rspec tags should be an array of strings"
content = YAML.dump({ rspec: { script: "test", tags: "mysql" } })
expect(GitlabCiYamlProcessor.errors(content)).to eq "jobs:rspec tags should be an array of strings"
end
 
it "does not return errors" do
config = File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
expect(GitlabCiYamlProcessor.validate(config)).to eq "valid"
content = File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
expect(GitlabCiYamlProcessor.errors(content)).to eq nil
end
end
end
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