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