module Hoe::Travis

def travis_yml_check path

def travis_yml_check path
  require 'net/http'
  post_body = {
    'content' => File.read(path),
  }
  req = Net::HTTP::Post.new '/lint'
  req.set_form post_body, 'multipart/form-data'
  cert_store = OpenSSL::X509::Store.new
  cert_store.set_default_paths
  http = Net::HTTP.new 'api.travis-ci.org', 443
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  http.cert_store = cert_store
  res = http.request req
  unless Net::HTTPOK === res then
    warn "Unable to lint #{path}: #{res.body}"
    return false
  end
  require 'json'
  response = JSON.parse res.body
  lint     = response.fetch 'lint'
  warnings = lint.fetch 'warnings'
  return true if warnings.empty?
  warnings.each do |warning|
    keys    = warning.fetch 'key'
    message = warning.fetch 'message'
    if keys.empty? then
      warn message
    else
      warn "For #{keys.join ', '}: #{message}"
    end
  end
  return false
rescue Net::HTTPError => e
  warn "Unable to lint #{path}: #{e.message}"
  return false
end