Class: Homebrew::Cmd::GistLogs Private

Inherits:
AbstractCommand show all
Includes:
Install
Defined in:
cmd/gist-logs.rb,
sorbet/rbi/dsl/homebrew/cmd/gist_logs.rbi

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Defined Under Namespace

Classes: Args

Constant Summary

Constants included from Install

Install::DependencySummary

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Install

ask, ask_casks, ask_formulae, ask_prompt_needed?, bottle_download_size, check_cc_argv, check_prefix, combined_fetch_downloads_heading, enqueue_cask_installers, enqueue_formulae, fetch_cask_dependencies, fetch_formulae, finish_installation, formula_installers, formulae_ask_prompt_needed?, global_post_install, install_formula, install_formula?, install_formulae, mark_failed_cask_downloads, perform_build_from_source_checks, perform_preinstall_checks, perform_preinstall_checks_once, prelude_fetch_formulae, print_dry_run_casks, print_dry_run_dependencies, print_dry_run_dependency_summary, reject_failed_downloads, select_formula_installers, source_build_formulae, source_build_heading, unmark_failed_formulae, warn_on_build_from_source

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_once, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_incompatible, #pretty_install_status, #pretty_installed, #pretty_removed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Class Method Details

.truncate_text_to_approximate_size(str, max_bytes, options = {}) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Truncates a text string to fit within a byte size constraint, preserving character encoding validity. The returned string will be not much longer than the specified max_bytes, though the exact shortfall or overrun may vary.

Parameters:

Returns:



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'cmd/gist-logs.rb', line 105

def self.truncate_text_to_approximate_size(str, max_bytes, options = {})
  front_weight = options.fetch(:front_weight, 0.5)
  raise "opts[:front_weight] must be between 0.0 and 1.0" if front_weight < 0.0 || front_weight > 1.0
  return str if str.bytesize <= max_bytes

  glue = "\n[...snip...]\n"
  max_bytes_in = [max_bytes - glue.bytesize, 1].max
  bytes = str.dup.force_encoding("BINARY")
  glue_bytes = glue.encode("BINARY")
  n_front_bytes = (max_bytes_in * front_weight).floor
  n_back_bytes = max_bytes_in - n_front_bytes
  front = bytes.byteslice(0, n_front_bytes).to_s
  back = bytes.byteslice(bytes.bytesize - n_back_bytes, n_back_bytes).to_s
  out = front + glue_bytes + back
  out.force_encoding("UTF-8")
  out.encode!("UTF-16", invalid: :replace)
  out.encode!("UTF-8")
  out
end

Instance Method Details

#args ⇒ Homebrew::Cmd::GistLogs::Args

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



10
# File 'sorbet/rbi/dsl/homebrew/cmd/gist_logs.rbi', line 10

def args; end

#run ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'cmd/gist-logs.rb', line 34

def run
  Install.perform_preinstall_checks_once(all_fatal: true)
  Install.perform_build_from_source_checks(all_fatal: true)
  return unless (name = args.named.downcased_unique_named.first)

  # The installed keg can be HEAD even when the failed build was stable.
  formula = Formulary.resolve(name, spec: (:stable if args.new_issue?), flags: args.flags_only)

  if args.new_issue?
    message = issue_reporting_message(formula:, build_options: formula.logged_build_options)
    odie message if message
  end

  files = load_logs(formula.logs)
  build_time = formula.logs.ctime
  timestamp = build_time.strftime("%Y-%m-%d_%H-%M-%S")

  s = StringIO.new
  SystemConfig.dump_verbose_config s
  # Dummy summary file, asciibetically first, to control display title of gist
  files["# #{formula.name} - #{timestamp}.txt"] = {
    content: <<~EOS,
      Homebrew build logs for #{formula.full_name} on #{OS_VERSION}
      Build date: #{build_time.strftime("%Y-%m-%d %H:%M:%S")}
    EOS
  }
  files["00.config.out"] = { content: s.string }
  files["00.doctor.out"] = { content: Utils.popen_read("#{HOMEBREW_PREFIX}/bin/brew", "doctor", err: :out) }
  unless formula.core_formula?
    tap = <<~EOS
      Formula: #{formula.name}
          Tap: #{formula.tap}
         Path: #{formula.path}
    EOS
    files["00.tap.out"] = { content: tap }
  end

  if GitHub::API.credentials_type == :none
    odie "`brew gist-logs` requires `$HOMEBREW_GITHUB_API_TOKEN` to be set!"
  end

  # Description formatted to work well as page title when viewing gist
  descr = if formula.core_formula?
    "#{formula.name} on #{OS_VERSION} - Homebrew build logs"
  else
    "#{formula.name} (#{formula.full_name}) on #{OS_VERSION} - Homebrew build logs"
  end

  begin
    url = GitHub.create_gist(files, descr, private: args.private?)
  rescue GitHub::API::HTTPNotFoundError
    odie <<~EOS
      Your GitHub API token likely doesn't have the `gist` scope.
      #{GitHub.pat_blurb(GitHub::CREATE_GIST_SCOPES)}
    EOS
  end

  if args.new_issue?
    tap = formula.tap
    odie "Formula #{formula.name} is not associated with a tap!" unless tap
    url = GitHub.create_issue(tap.full_name, "#{formula.name} failed to build on #{OS_VERSION}", url)
  end

  puts url if url
end