12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/gitlab/lint/client/api.rb', line 12
def lint (url, path, ={ "Content-Type" => "application/json" }, timeout=10)
puts "Making lint request to GitLab with path => #{path} and url => #{url}"
if yamlContent = Gitlab::Lint::Client::YamlFile.new(path).get_json_content()
uri = URI.parse(url)
req = Net::HTTP::Post.new(uri, )
req.body = { content: yamlContent }.to_json
https = Net::HTTP.new(uri.host, uri.port)
https.open_timeout = timeout
https.read_timeout = timeout
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
response = https.request(req)
case response
when Net::HTTPSuccess
return JSON.parse(response.body)
when Net::HTTPUnauthorized
abort("#{response.message}: invalid token in api request?")
when Net::HTTPServerError
abort("#{response.message}: server error, try again later?")
when Net::HTTPBadRequest
puts "Bad request..." + req.body
abort("#{response.message}: bad api request?")
when Net::HTTPNotFound
abort("#{response.message}: api request not found?")
else
abort("#{response.message}: failed api request?")
end
else
abort("\nLint request failed, problem encountered reading yaml file")
end
end
|