Port Homebrew::Cmd::GistLogs

This commit is contained in:
Douglas Eichelberger 2024-03-29 18:26:19 -07:00
parent 90cd9d2e0a
commit 78b259c8c6
2 changed files with 113 additions and 112 deletions

View File

@ -1,21 +1,18 @@
# typed: true
# frozen_string_literal: true
require "abstract_command"
require "formula"
require "install"
require "system_config"
require "stringio"
require "socket"
require "cli/parser"
module Homebrew
extend Install
module_function
sig { returns(CLI::Parser) }
def gist_logs_args
Homebrew::CLI::Parser.new do
module Cmd
class GistLogs < AbstractCommand
include Install
cmd_args do
description <<~EOS
Upload logs for a failed build of <formula> to a new Gist. Presents an
error message if no logs are found.
@ -31,9 +28,15 @@ module Homebrew
named_args :formula, number: 1
end
sig { override.void }
def run
Install.perform_preinstall_checks(all_fatal: true)
Install.perform_build_from_source_checks(all_fatal: true)
gistify_logs(args.named.to_resolved_formulae.first)
end
def gistify_logs(formula, args:)
def gistify_logs(formula)
files = load_logs(formula.logs)
build_time = formula.logs.ctime
timestamp = build_time.strftime("%Y-%m-%d_%H-%M-%S")
@ -73,7 +76,10 @@ module Homebrew
EOS
end
url = GitHub.create_issue(formula.tap, "#{formula.name} failed to build on #{OS_VERSION}", url) if args.new_issue?
if args.new_issue?
url = GitHub.create_issue(formula.tap, "#{formula.name} failed to build on #{OS_VERSION}",
url)
end
puts url if url
end
@ -119,12 +125,6 @@ module Homebrew
logs
end
def gist_logs
args = gist_logs_args.parse
Install.perform_preinstall_checks(all_fatal: true)
Install.perform_build_from_source_checks(all_fatal: true)
gistify_logs(args.named.to_resolved_formulae.first, args:)
end
end
end

View File

@ -1,7 +1,8 @@
# frozen_string_literal: true
require "cmd/gist-logs"
require "cmd/shared_examples/args_parse"
RSpec.describe "brew gist-logs" do
RSpec.describe Homebrew::Cmd::GistLogs do
it_behaves_like "parseable arguments"
end