more work on lint endpoint
This commit is contained in:
parent
69852d18b3
commit
f940bffe3f
|
@ -1,10 +1,21 @@
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
module Renderer::Lint
|
module Renderer::Lint
|
||||||
|
AVAILABLE_ATTRIBUTES = [ :warnings ]
|
||||||
extend self
|
extend self
|
||||||
|
|
||||||
def render(payload)
|
def available_attributes
|
||||||
# Renderer.render_value(payload)
|
AVAILABLE_ATTRIBUTES
|
||||||
puts payload
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,7 +23,7 @@ module Travis::API::V3
|
||||||
metrics.name_after(factory)
|
metrics.name_after(factory)
|
||||||
|
|
||||||
filtered = factory.filter_params(env_params)
|
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)
|
metrics.tick(:prepare)
|
||||||
result = service.run
|
result = service.run
|
||||||
|
|
|
@ -42,13 +42,14 @@ module Travis::API::V3
|
||||||
Queries[result_type]
|
Queries[result_type]
|
||||||
end
|
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
|
@access_control = access_control
|
||||||
@params = params
|
@params = params
|
||||||
@queries = {}
|
@queries = {}
|
||||||
@github = {}
|
@github = {}
|
||||||
|
@request_body = request_body
|
||||||
end
|
end
|
||||||
|
|
||||||
def query(type = result_type)
|
def query(type = result_type)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
|
require 'travis/yaml'
|
||||||
|
|
||||||
module Travis::API::V3
|
module Travis::API::V3
|
||||||
class Services::Lint::Lint < Service
|
class Services::Lint::Lint < Service
|
||||||
|
params "content"
|
||||||
def run!
|
def run!
|
||||||
# request.body.rewind
|
request_body.rewind
|
||||||
# content = params[:content] || request.body.read
|
content = params[:content] || request_body.read
|
||||||
# parsed = Travis::Yaml.parse(content)
|
parsed = Travis::Yaml.parse(content)
|
||||||
# warnings = parsed.nested_warnings.map { |k, m| { key: k, message: m } }
|
|
||||||
# payload = { lint: { warnings: warnings } }.to_json
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
40
spec/v3/services/lint/lint_spec.rb
Normal file
40
spec/v3/services/lint/lint_spec.rb
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Travis::API::V3::Services::Lint::Lint do
|
||||||
|
let(:content) { "foo: bar" }
|
||||||
|
let(:parsed_body) { JSON.load(last_response.body) }
|
||||||
|
|
||||||
|
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 == {
|
||||||
|
"@warnings" => [{
|
||||||
|
"@type" => "warning",
|
||||||
|
"message" => "query parameter foo: bar not whitelisted, ignored",
|
||||||
|
"warning_type" => "ignored_parameter", "parameter"=>"foo: bar"}],
|
||||||
|
"@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) }
|
||||||
|
example { expect(last_response).to be_ok }
|
||||||
|
example { expect(parsed_body).to be == {
|
||||||
|
"@warnings" => [{
|
||||||
|
"@type" => "warning",
|
||||||
|
"message" => "query parameter foo: bar not whitelisted, ignored",
|
||||||
|
"warning_type" => "ignored_parameter", "parameter"=>"foo: bar"}],
|
||||||
|
"@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