add endpoint for linting

This commit is contained in:
Konstantin Haase 2014-06-17 12:14:10 +02:00
parent 27f091d3f3
commit 10fe7e1c39
4 changed files with 45 additions and 0 deletions

View File

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

View File

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

View 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

View 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