Change class method name

This commit is contained in:
Katarzyna Kobierska 2016-08-25 14:57:57 +02:00
parent 9e313c1294
commit cc06eab237
5 changed files with 16 additions and 15 deletions

View file

@ -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

View file

@ -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

View file

@ -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'
@ -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

View file

@ -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

View file

@ -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