gist-logs: basic login
Closes Homebrew/homebrew#33839. Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This commit is contained in:
parent
00445c48c7
commit
28d465fab1
@ -6,14 +6,6 @@ require 'stringio'
|
|||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
def gistify_logs f
|
def gistify_logs f
|
||||||
if ARGV.include? '--new-issue'
|
|
||||||
unless HOMEBREW_GITHUB_API_TOKEN
|
|
||||||
puts 'You need to create an API token: https://github.com/settings/applications'
|
|
||||||
puts 'and then set HOMEBREW_GITHUB_API_TOKEN to use --new-issue option.'
|
|
||||||
exit 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
files = load_logs(f.name)
|
files = load_logs(f.name)
|
||||||
|
|
||||||
s = StringIO.new
|
s = StringIO.new
|
||||||
@ -23,11 +15,39 @@ module Homebrew
|
|||||||
|
|
||||||
url = create_gist(files)
|
url = create_gist(files)
|
||||||
|
|
||||||
if ARGV.include? '--new-issue'
|
if ARGV.include?('--new-issue') || ARGV.switch?('n')
|
||||||
url = new_issue(f.tap, "#{f.name} failed to build on #{MACOS_FULL_VERSION}", url)
|
auth = :AUTH_TOKEN
|
||||||
|
|
||||||
|
unless HOMEBREW_GITHUB_API_TOKEN
|
||||||
|
puts 'You can create an API token: https://github.com/settings/applications'
|
||||||
|
puts 'and then set HOMEBREW_GITHUB_API_TOKEN as authentication method.'
|
||||||
|
puts
|
||||||
|
|
||||||
|
auth = :AUTH_BASIC
|
||||||
|
end
|
||||||
|
|
||||||
|
url = new_issue(f.tap, "#{f.name} failed to build on #{MACOS_FULL_VERSION}", url, auth)
|
||||||
end
|
end
|
||||||
|
|
||||||
ensure puts url if url
|
puts url if url
|
||||||
|
end
|
||||||
|
|
||||||
|
#Hack for ruby < 1.9.3
|
||||||
|
def noecho_gets
|
||||||
|
system 'stty -echo'
|
||||||
|
result = $stdin.gets
|
||||||
|
system 'stty echo'
|
||||||
|
puts
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
|
def login request
|
||||||
|
print 'GitHub User: '
|
||||||
|
user = $stdin.gets.chomp
|
||||||
|
print 'Password: '
|
||||||
|
password = noecho_gets.chomp
|
||||||
|
puts
|
||||||
|
request.basic_auth(user, password)
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_logs name
|
def load_logs name
|
||||||
@ -42,11 +62,11 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_gist files
|
def create_gist files
|
||||||
post("/gists", "public" => true, "files" => files)["html_url"]
|
post("/gists", { "public" => true, "files" => files })["html_url"]
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_issue repo, title, body
|
def new_issue repo, title, body, auth
|
||||||
post("/repos/#{repo}/issues", "title" => title, "body" => body)["html_url"]
|
post("/repos/#{repo}/issues", { "title" => title, "body" => body }, auth)["html_url"]
|
||||||
end
|
end
|
||||||
|
|
||||||
def http
|
def http
|
||||||
@ -63,24 +83,27 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_request(path, data)
|
def make_request(path, data, auth)
|
||||||
headers = {
|
headers = {
|
||||||
"User-Agent" => HOMEBREW_USER_AGENT,
|
"User-Agent" => HOMEBREW_USER_AGENT,
|
||||||
"Accept" => "application/vnd.github.v3+json",
|
"Accept" => "application/vnd.github.v3+json",
|
||||||
"Content-Type" => "application/json",
|
"Content-Type" => "application/json",
|
||||||
}
|
}
|
||||||
|
|
||||||
if HOMEBREW_GITHUB_API_TOKEN
|
if auth == :AUTH_TOKEN || (auth == nil && HOMEBREW_GITHUB_API_TOKEN)
|
||||||
headers["Authorization"] = "token #{HOMEBREW_GITHUB_API_TOKEN}"
|
headers["Authorization"] = "token #{HOMEBREW_GITHUB_API_TOKEN}"
|
||||||
end
|
end
|
||||||
|
|
||||||
request = Net::HTTP::Post.new(path, headers)
|
request = Net::HTTP::Post.new(path, headers)
|
||||||
|
|
||||||
|
login(request) if auth == :AUTH_BASIC
|
||||||
|
|
||||||
request.body = Utils::JSON.dump(data)
|
request.body = Utils::JSON.dump(data)
|
||||||
request
|
request
|
||||||
end
|
end
|
||||||
|
|
||||||
def post(path, data)
|
def post(path, data, auth = nil)
|
||||||
request = make_request(path, data)
|
request = make_request(path, data, auth)
|
||||||
|
|
||||||
case response = http.request(request)
|
case response = http.request(request)
|
||||||
when Net::HTTPCreated
|
when Net::HTTPCreated
|
||||||
@ -102,7 +125,7 @@ module Homebrew
|
|||||||
|
|
||||||
def gist_logs
|
def gist_logs
|
||||||
if ARGV.formulae.length != 1
|
if ARGV.formulae.length != 1
|
||||||
puts "usage: brew gist-logs [--new-issue] <formula>"
|
puts "usage: brew gist-logs [--new-issue|-n] <formula>"
|
||||||
Homebrew.failed = true
|
Homebrew.failed = true
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user