class Lintron::API

Makes requests to the lintron local lint API

Public Class Methods

new(base_url) click to toggle source
# File lib/lintron/api.rb, line 8
def initialize(base_url)
  @base_url = base_url
end

Public Instance Methods

post_lint_request(pr) click to toggle source
# File lib/lintron/api.rb, line 26
def post_lint_request(pr)
  HTTParty.post(URI.join(@base_url, 'local_lints'), request_params(pr))
end
request_params(pr) click to toggle source
# File lib/lintron/api.rb, line 30
def request_params(pr)
  {
    body: pr.to_json,
    headers: {
      'Content-Type' => 'application/json',
      'Accept' => 'application/json',
    },
  }
end
violations(pr) click to toggle source
# File lib/lintron/api.rb, line 12
def violations(pr)
  response = post_lint_request(pr)
  violations =
    JSON
    .parse(response.body)
    .map { |json| Lintron::ViolationLine.new(json) }

  violations.sort_by(&:file_and_line)
rescue JSON::ParserError
  puts 'Error occurred while parsing response from Lintron'.colorize(:red)
  puts 'Raw response body: '
  puts response.body
end