From d05c4d24083b11a8f9fff4417b24d094159ac70b Mon Sep 17 00:00:00 2001 From: Andrew Janke Date: Fri, 16 Oct 2015 05:41:50 -0400 Subject: [PATCH] gist-logs: Friendlier titles and display for log gists Adds a summary file and description to get more informative displays on gist.github.com. Closes Homebrew/homebrew#45023. Signed-off-by: Andrew Janke --- Library/Homebrew/cmd/gist-logs.rb | 36 +++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/cmd/gist-logs.rb b/Library/Homebrew/cmd/gist-logs.rb index 495041a712..29deb65513 100644 --- a/Library/Homebrew/cmd/gist-logs.rb +++ b/Library/Homebrew/cmd/gist-logs.rb @@ -3,25 +3,36 @@ require "cmd/config" require "net/http" require "net/https" require "stringio" +require "socket" module Homebrew def gistify_logs(f) files = load_logs(f.logs) + build_time = f.logs.ctime + timestamp = build_time.strftime("%Y-%m-%d_%H-%M-%S") s = StringIO.new Homebrew.dump_verbose_config(s) - files["config.out"] = { :content => s.string } - files["doctor.out"] = { :content => `brew doctor 2>&1` } + # Dummy summary file, asciibetically first, to control display title of gist + files["# #{f.name} - #{timestamp}.txt"] = { :content => brief_build_info(f) } + files["00.config.out"] = { :content => s.string } + files["00.doctor.out"] = { :content => `brew doctor 2>&1` } unless f.core_formula? tap = <<-EOS.undent Formula: #{f.name} Tap: #{f.tap} Path: #{f.path} EOS - files["tap.out"] = { :content => tap } + files["00.tap.out"] = { :content => tap } end - url = create_gist(files) + # Description formatted to work well as page title when viewing gist + if f.core_formula? + descr = "#{f.name} on #{OS_VERSION} - Homebrew build logs" + else + descr = "#{f.name} (#{f.full_name}) on #{OS_VERSION} - Homebrew build logs" + end + url = create_gist(files, descr) if ARGV.include?("--new-issue") || ARGV.switch?("n") auth = :AUTH_TOKEN @@ -40,6 +51,19 @@ module Homebrew puts url if url end + def brief_build_info(f) + build_time_str = f.logs.ctime.strftime("%Y-%m-%d %H:%M:%S") + s = <<-EOS.undent + Homebrew build logs for #{f.full_name} on #{OS_VERSION} + EOS + if ARGV.include?("--with-hostname") + hostname = Socket.gethostname + s << "Host: #{hostname}\n" + end + s << "Build date: #{build_time_str}\n" + s + end + # Hack for ruby < 1.9.3 def noecho_gets system "stty -echo" @@ -68,8 +92,8 @@ module Homebrew logs end - def create_gist(files) - post("/gists", "public" => true, "files" => files)["html_url"] + def create_gist(files, descr) + post("/gists", { "public" => true, "files" => files, "description" => descr })["html_url"] end def new_issue(repo, title, body, auth)