add endpoint for linting
This commit is contained in:
parent
27f091d3f3
commit
10fe7e1c39
1
Gemfile
1
Gemfile
|
@ -6,6 +6,7 @@ gemspec
|
|||
gem 'travis-core', github: 'travis-ci/travis-core'
|
||||
gem 'travis-support', github: 'travis-ci/travis-support'
|
||||
gem 'travis-sidekiqs', github: 'travis-ci/travis-sidekiqs', require: nil, ref: 'cde9741'
|
||||
gem 'travis-yaml', github: 'travis-ci/travis-yaml'
|
||||
gem 'sinatra'
|
||||
gem 'sinatra-contrib', require: nil #github: 'sinatra/sinatra-contrib', require: nil
|
||||
|
||||
|
|
|
@ -80,6 +80,12 @@ GIT
|
|||
specs:
|
||||
travis-support (0.0.1)
|
||||
|
||||
GIT
|
||||
remote: git://github.com/travis-ci/travis-yaml.git
|
||||
revision: 7e6e31e82240e170ffc20dfd02c0353b3bd5d33b
|
||||
specs:
|
||||
travis-yaml (0.1.0)
|
||||
|
||||
GIT
|
||||
remote: https://gist.github.com/4269321.git
|
||||
revision: 8e2d21b924a69dd48191df6a18e51769f5a88614
|
||||
|
@ -332,5 +338,6 @@ DEPENDENCIES
|
|||
travis-core!
|
||||
travis-sidekiqs!
|
||||
travis-support!
|
||||
travis-yaml!
|
||||
unicorn
|
||||
yard-sinatra!
|
||||
|
|
19
lib/travis/api/app/endpoint/lint.rb
Normal file
19
lib/travis/api/app/endpoint/lint.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
require 'travis/api/app'
|
||||
require 'travis/yaml'
|
||||
|
||||
class Travis::Api::App
|
||||
class Endpoint
|
||||
class Lint < Endpoint
|
||||
def lint
|
||||
request.body.rewind
|
||||
content = params[:content] || request.body.read
|
||||
parsed = Travis::Yaml.parse(content)
|
||||
warnings = parsed.nested_warnings.map { |k, m| { key: k, message: m } }
|
||||
{ lint: { warnings: warnings } }.to_json
|
||||
end
|
||||
|
||||
post('/', scope: :public) { lint }
|
||||
put('/', scope: :public) { lint }
|
||||
end
|
||||
end
|
||||
end
|
18
spec/unit/endpoint/lint_spec.rb
Normal file
18
spec/unit/endpoint/lint_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Travis::Api::App::Endpoint::Lint do
|
||||
let(:content) { "foo: bar" }
|
||||
let(:body) { "{\"lint\":{\"warnings\":[{\"key\":[],\"message\":\"unexpected key \\\"foo\\\", dropping\"},{\"key\":[],\"message\":\"missing key \\\"language\\\", defaulting to \\\"ruby\\\"\"}]}}" }
|
||||
|
||||
it "accepts content in parameter" do
|
||||
response = post('/lint', content: content)
|
||||
response.should be_ok
|
||||
response.body.should be == body
|
||||
end
|
||||
|
||||
it "accepts content as body" do
|
||||
response = put('/lint', content)
|
||||
response.should be_ok
|
||||
response.body.should be == body
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user