Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix analytics handling when core/cask taps are untapped #14635

Merged
merged 1 commit into from Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion Library/Homebrew/cask/installer.rb
Expand Up @@ -110,7 +110,9 @@ def install

install_artifacts

::Utils::Analytics.report_event("cask_install", @cask.token, on_request: true) unless @cask.tap&.private?
if @cask.tap&.should_report_analytics?
::Utils::Analytics.report_event("cask_install", @cask.token, on_request: true)
end

purge_backed_up_versioned_files

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/formula_installer.rb
Expand Up @@ -414,7 +414,7 @@ def install
options = display_options(formula).join(" ")
oh1 "Installing #{Formatter.identifier(formula.full_name)} #{options}".strip if show_header?

if formula.tap&.installed? && !formula.tap&.private?
if formula.tap&.should_report_analytics?
action = "#{formula.full_name} #{options}".strip
Utils::Analytics.report_event("install", action, on_request: installed_on_request?)
end
Expand Down
7 changes: 7 additions & 0 deletions Library/Homebrew/tap.rb
Expand Up @@ -670,6 +670,13 @@ def pypi_formula_mappings
@pypi_formula_mappings = read_formula_list path/HOMEBREW_TAP_PYPI_FORMULA_MAPPINGS
end

# @private
def should_report_analytics?
return Homebrew::EnvConfig.install_from_api? && official? unless installed?

!private?
end

def ==(other)
other = Tap.fetch(other) if other.is_a?(String)
self.class == other.class && name == other.name
Expand Down
3 changes: 1 addition & 2 deletions Library/Homebrew/utils/analytics.rb
Expand Up @@ -144,8 +144,7 @@ def report_event(category, action, on_request: false)

def report_build_error(exception)
return unless exception.formula.tap
return unless exception.formula.tap.installed?
return if exception.formula.tap.private?
return unless exception.formula.tap.should_report_analytics?

action = exception.formula.full_name
if (options = exception.options.to_a.map(&:to_s).join(" ").presence)
Expand Down