Merge branch 'master' into cronjobs
This commit is contained in:
commit
fe76d38230
21
lib/travis/api/v3/renderer/lint.rb
Normal file
21
lib/travis/api/v3/renderer/lint.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
module Travis::API::V3
|
||||
module Renderer::Lint
|
||||
AVAILABLE_ATTRIBUTES = [ :warnings ]
|
||||
extend self
|
||||
|
||||
def available_attributes
|
||||
AVAILABLE_ATTRIBUTES
|
||||
end
|
||||
|
||||
def render(lint, **)
|
||||
{
|
||||
:@type => 'lint'.freeze,
|
||||
:warnings => warnings_for(lint)
|
||||
}
|
||||
end
|
||||
|
||||
def warnings_for(lint)
|
||||
lint.nested_warnings.map { |k, m| { key: k, message: m } }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -23,7 +23,7 @@ module Travis::API::V3
|
|||
metrics.name_after(factory)
|
||||
|
||||
filtered = factory.filter_params(env_params)
|
||||
service = factory.new(access_control, filtered.merge(params))
|
||||
service = factory.new(access_control, filtered.merge(params), env['rack.input'.freeze])
|
||||
|
||||
metrics.tick(:prepare)
|
||||
result = service.run
|
||||
|
|
|
@ -45,6 +45,11 @@ module Travis::API::V3
|
|||
post :debug, '/debug'
|
||||
end
|
||||
|
||||
resource :lint do
|
||||
route '/lint'
|
||||
post :lint
|
||||
end
|
||||
|
||||
resource :organization do
|
||||
capture id: :digit
|
||||
route '/org/{organization.id}'
|
||||
|
|
|
@ -42,13 +42,14 @@ module Travis::API::V3
|
|||
Queries[result_type]
|
||||
end
|
||||
|
||||
attr_accessor :access_control, :params
|
||||
attr_accessor :access_control, :params, :request_body
|
||||
|
||||
def initialize(access_control, params)
|
||||
def initialize(access_control, params, request_body)
|
||||
@access_control = access_control
|
||||
@params = params
|
||||
@queries = {}
|
||||
@github = {}
|
||||
@request_body = request_body
|
||||
end
|
||||
|
||||
def query(type = result_type)
|
||||
|
|
|
@ -13,6 +13,7 @@ module Travis::API::V3
|
|||
Crons = Module.new { extend Services }
|
||||
Job = Module.new { extend Services }
|
||||
Jobs = Module.new { extend Services }
|
||||
Lint = Module.new { extend Services }
|
||||
Organization = Module.new { extend Services }
|
||||
Organizations = Module.new { extend Services }
|
||||
Owner = Module.new { extend Services }
|
||||
|
|
12
lib/travis/api/v3/services/lint/lint.rb
Normal file
12
lib/travis/api/v3/services/lint/lint.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
require 'travis/yaml'
|
||||
|
||||
module Travis::API::V3
|
||||
class Services::Lint::Lint < Service
|
||||
params 'content'
|
||||
def run!
|
||||
request_body.rewind
|
||||
content = params['content'.freeze] || request_body.read
|
||||
Travis::Yaml.parse(content)
|
||||
end
|
||||
end
|
||||
end
|
34
spec/v3/services/lint/lint_spec.rb
Normal file
34
spec/v3/services/lint/lint_spec.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Travis::API::V3::Services::Lint::Lint do
|
||||
let(:content) { "foo: bar" }
|
||||
let(:parsed_body) { JSON.load(last_response.body) }
|
||||
let(:headers) {{ 'CONTENT_TYPE' => 'text/yaml'}}
|
||||
|
||||
|
||||
describe "accepts content in parameter" do
|
||||
before { post("v3/lint", content: content ) }
|
||||
example { expect(last_response).to be_ok }
|
||||
example { expect(parsed_body).to be == {
|
||||
"@type" => "lint",
|
||||
"warnings" => [{
|
||||
"key" => [],
|
||||
"message" => "unexpected key \"foo\", dropping"}, {
|
||||
"key" => [],
|
||||
"message" => "missing key \"language\", defaulting to \"ruby\""}]}
|
||||
}
|
||||
end
|
||||
|
||||
describe "accepts content as body" do
|
||||
before { post("/v3/lint", content, headers) }
|
||||
example { expect(last_response).to be_ok }
|
||||
example { expect(parsed_body).to be == {
|
||||
"@type" => "lint",
|
||||
"warnings" => [{
|
||||
"key" => [],
|
||||
"message" => "unexpected key \"foo\", dropping"}, {
|
||||
"key" => [],
|
||||
"message" => "missing key \"language\", defaulting to \"ruby\""}]}
|
||||
}
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user