Change class method name
This commit is contained in:
parent
9e313c1294
commit
cc06eab237
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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'
|
||||||
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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…
Reference in New Issue