Class: Homebrew::DevCmd::Lgtm Private

Inherits:
AbstractCommand show all
Includes:
SystemCommand::Mixin
Defined in:
dev-cmd/lgtm.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/lgtm.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

Instance Method Summary collapse

Methods included from SystemCommand::Mixin

#system_command, #system_command!

Methods inherited from AbstractCommand

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

Methods included from Utils::Output::Mixin

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

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#argsHomebrew::DevCmd::Lgtm::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/dev_cmd/lgtm.rbi', line 10

def args; end

#runvoid

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.



25
26
27
28
29
30
31
32
33
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'dev-cmd/lgtm.rb', line 25

def run
  Utils::GemSetup.install_bundler_gems!(groups: Utils::GemSetup.valid_gem_groups - ["sorbet"])

  tap = Tap.from_path(Dir.pwd)

  typecheck_args = ["typecheck", tap&.name].compact
  ohai "brew #{typecheck_args.join(" ")}"
  Utils::BrewCommand.run!(*typecheck_args)
  puts

  ohai "brew style --changed --fix"
  Utils::BrewCommand.run! "style", "--changed", "--fix"
  puts

  if tap
    added_files = Utils.popen_read("git", "diff", "--name-only", "--no-relative", "--diff-filter=A", "main")
                       .split("\n")
    changed_formulae = []
    new_formulae = []
    changed_casks = []
    new_casks = []
    changed_audit_args = ["--strict"]
    changed_audit_args << "--online" if args.online?
    new_audit_args = args.online? ? ["--new"] : ["--strict"]

    Utils.popen_read("git", "diff", "--name-only", "--no-relative", "--diff-filter=AMR", "main")
         .split("\n").each do |file|
      next if file.blank?

      tapped_name = "#{tap.name}/#{Pathname(file).basename(".rb")}"

      if tap.formula_file?(file)
        (added_files.include?(file) ? new_formulae : changed_formulae) << tapped_name
      elsif tap.cask_file?(file)
        (added_files.include?(file) ? new_casks : changed_casks) << tapped_name
      end
    end

    if Utils.popen_read("git", "ls-files", "--others", "--exclude-standard", "--full-name")
            .split("\n")
            .any? { |file| tap.formula_file?(file) || tap.cask_file?(file) }
      opoo "Untracked formula or cask files are not checked by `brew lgtm`; stage or commit them first."
    end

    if !args.online? && [*new_formulae, *new_casks].present?
      opoo "New formulae or casks were detected. Run `brew lgtm --online` to include `brew audit --new` checks."
    end

    unless changed_formulae.empty?
      ohai "brew audit #{changed_audit_args.join(" ")} --skip-style --formula #{changed_formulae.join(" ")}"
      Utils::BrewCommand.run! "audit", *changed_audit_args, "--skip-style", "--formula",
                              *changed_formulae
      puts
    end

    unless new_formulae.empty?
      ohai "brew audit #{new_audit_args.join(" ")} --skip-style --formula #{new_formulae.join(" ")}"
      Utils::BrewCommand.run! "audit", *new_audit_args, "--skip-style", "--formula",
                              *new_formulae
      puts
    end

    unless changed_casks.empty?
      ohai "brew audit #{changed_audit_args.join(" ")} --skip-style --cask #{changed_casks.join(" ")}"
      Utils::BrewCommand.run! "audit", *changed_audit_args, "--skip-style", "--cask",
                              *changed_casks
      puts
    end

    unless new_casks.empty?
      ohai "brew audit #{new_audit_args.join(" ")} --skip-style --cask #{new_casks.join(" ")}"
      Utils::BrewCommand.run! "audit", *new_audit_args, "--skip-style", "--cask", *new_casks
      puts
    end

    formulae_to_test = [*changed_formulae, *new_formulae].select do |formula_name|
      next true if Formulary.factory(formula_name).latest_version_installed?

      opoo "Skipping `brew test #{formula_name}`; the latest version is not installed."
      false
    end
    return if formulae_to_test.empty?

    ohai "brew test #{formulae_to_test.join(" ")}"
    Utils::BrewCommand.run! "test", *formulae_to_test
  else
    audit_or_tests_args = ["--changed"]
    audit_or_tests_args << "--online" if args.online?
    ohai "brew tests #{audit_or_tests_args.join(" ")}"
    Utils::BrewCommand.run! "tests", *audit_or_tests_args
  end
end